Prompt
I'm building a DevSecOps pipeline and want API security checks in CI
Latest observation
Great idea. For API security checks in CI, you usually want a mix of static, dynamic, and contract-based checks so you catch issues early without slowing the pipeline too much.
Good CI checks for API security
1) OpenAPI / schema validation
If you have an OpenAPI spec, validate it in CI for:
- syntax errors
- invalid references
- insecure defaults
- missing auth definitions
- weak parameter patterns
Tools: swagger-cli, spectral, openapi-generator validate
2) Lint for security rules
Use an API linter with security-focused rules, for example:
- missing authentication on sensitive routes
- unsafe HTTP methods
- overly permissive CORS
- weak error responses revealing internals
- missing rate-limit hints / pagination constraints
Tools: Spectral, custom rules in OpenAPI linting
3) SAST for the API code
Run static analysis on the application code to catch:
- injection issues
- insecure deserialization
- auth bypasses
- SSRF
- hardcoded secrets
- insecure crypto usage
Tools: Semgrep, CodeQL, Bandit (Python), gosec (Go), Brakeman (Rails)
4) Secret scanning
Scan commits and build artifacts for exposed secrets:
- API keys
- JWT secrets
- DB creds
- cloud tokens
Tools: gitleaks, trufflehog, GitHub secret scanning
5) Dependency and container scanning
APIs often depend on vulnerable libraries or insecure base images.
Tools:
- Dependency:
Dependabot,Snyk,OWASP Dependency-Check - Containers:
Trivy,Grype
6) DAST against a deployed test environment
Spin up a staging/test deployment and probe the API for:
- auth issues
- broken access control
- injection
- rate limiting weaknesses
- verbose errors
- misconfigured headers
Tools: OWASP ZAP, Burp Suite Enterprise, StackHawk, Astra, 42Crunch
7) API fuzzing / negative testing
Send malformed or unexpected requests to find parsing and validation bugs:
- oversized payloads
- invalid content-types
- unexpected enum values
- schema violations
- path traversal patterns
Tools: ZAP, Schemathesis, RESTler
8) Contract tests with security assertions
If you use contract testing, add checks like:
- unauthorized requests must return 401/403
- fields not in schema are rejected
- sensitive data is not returned
- only expected methods are allowed
Tools: Pact, Schemathesis, custom test suites
Practical CI pipeline structure
A common order:
-
Pre-commit / PR
- secret scan
- lint OpenAPI
- SAST
- dependency scan
-
Build
- unit tests
- container build
- container scan
-
Deploy to ephemeral/staging
- smoke tests
- DAST
- API fuzzing
- authz/authn checks
-
Release gate
- fail on high/critical findings
- require manual approval for exceptions
Security checks worth prioritizing first
If you want maximum value with minimal complexity, start with:
- secret scanning
- OpenAPI linting
- SAST
- dependency scanning
- DAST on staging
That combination covers many common API risks.
Example GitHub Actions flow
name: api-security-ci
on:
pull_request:
push:
branches: [ main ]
jobs:
lint-and-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Secret scan
run: gitleaks detect --source . --no-banner
- name: OpenAPI lint
run: spectral lint openapi.yaml
- name: SAST
run: semgrep --config p/owasp-top-ten .
- name: Dependency scan
run: npm audit --audit-level=high
deploy-and-dast:
needs: lint-and-scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy test env
run: ./deploy-staging.sh
- name: DAST
run: |
zap-baseline.py -t https://staging.example.com/api
Best practices
- Run fast checks on every PR
- Run DAST only after deploy to a test environment
- Tune thresholds so the pipeline is usable
- Keep a baseline of accepted findings
- Store scan results as build artifacts for auditability
- Don’t rely only on scanners; add security assertions in tests
If you want, I can help you design a CI workflow for a specific stack like GitHub Actions + OpenAPI + ZAP + Semgrep, or give you a sample pipeline for Jenkins/GitLab CI/Azure DevOps.