Skip to content

feat(security): add security headers middleware #142

feat(security): add security headers middleware

feat(security): add security headers middleware #142

# name: OpenAPI Contract Testing
# on:
# push:
# branches: [main, develop]
# pull_request:
# branches: [main]
# schedule:
# # Run contract tests daily at 2 AM UTC
# - cron: '0 2 * * *'
# env:
# NODE_VERSION: '18'
# OPENAPI_VALIDATION_ENABLED: 'true'
# OPENAPI_VALIDATION_STRICT: 'true'
# OPENAPI_VALIDATE_REQUESTS: 'true'
# OPENAPI_VALIDATE_RESPONSES: 'true'
# OPENAPI_LOG_VIOLATIONS: 'true'
# OPENAPI_REPORT_VIOLATIONS: 'true'
# jobs:
# contract-spec-validation:
# name: Validate OpenAPI Specification
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Setup Node.js
# uses: actions/setup-node@v4
# with:
# node-version: ${{ env.NODE_VERSION }}
# cache: 'npm'
# - name: Install dependencies
# run: npm ci
# - name: Validate OpenAPI specification syntax
# run: |
# npx @apidevtools/swagger-parser validate api-specification.yaml
# - name: Check specification completeness
# run: |
# node scripts/validate-spec-completeness.js
# - name: Generate specification report
# run: |
# npx swagger-codegen generate -i api-specification.yaml -l html2 -o docs/api-spec
# contract-tests:
# name: Run Contract Tests
# runs-on: ubuntu-latest
# needs: contract-spec-validation
# strategy:
# matrix:
# test-suite: [request-validation, response-validation, endpoint-coverage, performance]
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Setup Node.js
# uses: actions/setup-node@v4
# with:
# node-version: ${{ env.NODE_VERSION }}
# cache: 'npm'
# - name: Install dependencies
# run: npm ci
# - name: Setup test database
# run: |
# sudo -u postgres createdb strellerminds_contract_test
# npm run migration:run
# - name: Run specific contract test suite
# run: |
# case "${{ matrix.test-suite }}" in
# "request-validation")
# npm run test:contract:request
# ;;
# "response-validation")
# npm run test:contract:response
# ;;
# "endpoint-coverage")
# npm run test:contract:coverage
# ;;
# "performance")
# npm run test:contract:performance
# ;;
# esac
# - name: Upload test results
# uses: actions/upload-artifact@v4
# if: always()
# with:
# name: contract-test-results-${{ matrix.test-suite }}
# path: |
# test-results/
# coverage/
# retention-days: 30
# contract-compliance-check:
# name: Contract Compliance Check
# runs-on: ubuntu-latest
# needs: contract-tests
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Setup Node.js
# uses: actions/setup-node@v4
# with:
# node-version: ${{ env.NODE_VERSION }}
# cache: 'npm'
# - name: Install dependencies
# run: npm ci
# - name: Build application
# run: npm run build
# - name: Start application for testing
# run: |
# npm run start:prod &
# sleep 30
# - name: Run live contract validation
# run: |
# node scripts/live-contract-validation.js
# - name: Generate compliance report
# run: |
# node scripts/generate-compliance-report.js
# - name: Upload compliance report
# uses: actions/upload-artifact@v4
# with:
# name: contract-compliance-report
# path: contract-compliance-report.json
# retention-days: 90
# contract-diff:
# name: Contract Changes Detection
# runs-on: ubuntu-latest
# if: github.event_name == 'pull_request'
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# with:
# fetch-depth: 0
# - name: Setup Node.js
# uses: actions/setup-node@v4
# with:
# node-version: ${{ env.NODE_VERSION }}
# cache: 'npm'
# - name: Install dependencies
# run: npm ci
# - name: Generate contract diff
# run: |
# # Get base branch specification
# git checkout origin/${{ github.base_ref }} -- api-specification.yaml
# cp api-specification.yaml base-spec.yaml
# # Get current branch specification
# git checkout HEAD -- api-specification.yaml
# cp api-specification.yaml current-spec.yaml
# # Compare specifications
# node scripts/contract-diff.js base-spec.yaml current-spec.yaml
# - name: Comment PR with contract changes
# uses: actions/github-script@v7
# if: steps.diff.outputs.has_changes == 'true'
# with:
# script: |
# const fs = require('fs');
# const diffReport = JSON.parse(fs.readFileSync('contract-diff-report.json', 'utf8'));
# const comment = `## OpenAPI Contract Changes Detected
# ### Breaking Changes: ${diffReport.breakingChanges.length}
# ${diffReport.breakingChanges.map(change => `- ${change}`).join('\n')}
# ### Additions: ${diffReport.additions.length}
# ${diffReport.additions.map(change => `- ${change}`).join('\n')}
# ### Modifications: ${diffReport.modifications.length}
# ${diffReport.modifications.map(change => `- ${change}`).join('\n')}
# ### Deletions: ${diffReport.deletions.length}
# ${diffReport.deletions.map(change => `- ${change}`).join('\n')}
# Please review these changes carefully before merging.`;
# github.rest.issues.createComment({
# issue_number: context.issue.number,
# owner: context.repo.owner,
# repo: context.repo.repo,
# body: comment
# });
# security-validation:
# name: Security Contract Validation
# runs-on: ubuntu-latest
# needs: contract-spec-validation
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Setup Node.js
# uses: actions/setup-node@v4
# with:
# node-version: ${{ env.NODE_VERSION }}
# cache: 'npm'
# - name: Install dependencies
# run: npm ci
# - name: Run security contract validation
# run: |
# node scripts/security-contract-validation.js
# - name: Run API security scan
# run: |
# npx @stoplight/spectral lint api-specification.yaml --ruleset .spectral.yml
# - name: Check for sensitive data exposure
# run: |
# node scripts/check-sensitive-exposure.js
# performance-benchmarks:
# name: Contract Performance Benchmarks
# runs-on: ubuntu-latest
# needs: contract-tests
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Setup Node.js
# uses: actions/setup-node@v4
# with:
# node-version: ${{ env.NODE_VERSION }}
# cache: 'npm'
# - name: Install dependencies
# run: npm ci
# - name: Build application
# run: npm run build
# - name: Start application
# run: |
# npm run start:prod &
# sleep 30
# - name: Run performance benchmarks
# run: |
# node scripts/contract-performance-benchmarks.js
# - name: Compare with baseline
# run: |
# node scripts/compare-performance-baseline.js
# - name: Upload performance results
# uses: actions/upload-artifact@v4
# with:
# name: contract-performance-results
# path: performance-results.json
# retention-days: 90
# notify-results:
# name: Notify Results
# runs-on: ubuntu-latest
# needs: [contract-tests, contract-compliance-check, security-validation]
# if: always()
# steps:
# - name: Download all artifacts
# uses: actions/download-artifact@v4
# - name: Generate summary report
# run: |
# node scripts/generate-test-summary.js
# - name: Send Slack notification
# if: failure()
# uses: 8398a7/action-slack@v3
# with:
# status: failure
# channel: '#api-contracts'
# text: 'OpenAPI contract tests failed! Please check the GitHub Actions logs for details.'
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
# - name: Update contract status badge
# run: |
# node scripts/update-status-badge.js
# deploy-spec:
# name: Deploy Updated Specification
# runs-on: ubuntu-latest
# needs: [contract-tests, contract-compliance-check, security-validation]
# if: github.ref == 'refs/heads/main' && success()
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Deploy to API documentation site
# run: |
# # Deploy to your API documentation platform
# node scripts/deploy-api-spec.js
# - name: Update API gateway
# run: |
# # Update API gateway with new specification
# node scripts/update-api-gateway.js
# - name: Notify teams of specification update
# run: |
# node scripts/notify-spec-update.js