Prompt
API security testing in CI/CD
Latest observation
Oct 29, 2026
OpenAI APIWeb search: off
API security testing in CI/CD means automatically checking your APIs for security issues as part of the build/release pipeline, so vulnerabilities are caught before production.
What to test
Common API security checks include:
- Authentication
- Missing auth
- Weak token handling
- Broken login flows
- Authorization
- IDOR/BOLA
- Privilege escalation
- Broken role checks
- Input validation
- SQL/NoSQL injection
- Command injection
- Schema violations
- Sensitive data exposure
- Secrets in responses/logs
- Overly verbose errors
- Rate limiting / abuse
- Brute force
- DoS-style request flooding
- Misconfiguration
- CORS issues
- Debug endpoints
- Open admin routes
- Transport/security headers
- TLS only
- Security headers where relevant
- API schema and contract
- Unexpected fields
- Deprecated endpoints
- Excessive data exposure
Where it fits in CI/CD
Typical pipeline stages:
- Pre-commit / PR
- Linting
- Secret scanning
- Dependency scanning
- Schema checks
- Build
- SAST
- Container/image scan
- Unit tests with security cases
- Test / staging
- DAST against a deployed test environment
- API fuzzing
- AuthZ tests
- OpenAPI-based validation
- Release gate
- Fail on critical/high findings
- Manual review for exceptions
- Post-deploy
- Monitoring
- Runtime alerts
- Continuous scanning
Recommended tools
Examples by category:
- SAST: Semgrep, SonarQube, CodeQL
- Secret scanning: Gitleaks, TruffleHog
- Dependency scanning: Snyk, Dependabot, OWASP Dependency-Check
- Container scanning: Trivy, Grype
- DAST/API testing: OWASP ZAP, Burp Suite Enterprise, StackHawk, 42Crunch
- Contract/schema testing: OpenAPI validators, Dredd, Schemathesis
- Fuzzing/property testing: Schemathesis, RESTler
- Cloud/IaC: Checkov, tfsec, Terrascan
Good CI/CD pattern
A practical approach:
- Shift-left: run fast static checks on every PR
- Gate merges on critical issues
- Run dynamic API tests in a staging environment with test accounts
- Use the OpenAPI spec to generate test cases automatically
- Include auth scenarios for multiple roles
- Track findings over time and fail builds only on new/high-severity issues to reduce noise
Example GitHub Actions flow
name: api-security
on: [pull_request, push]
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Secret scan
run: gitleaks detect --source . --no-banner
- name: SAST
run: semgrep scan --config auto
- name: Dependency scan
run: snyk test
- name: OpenAPI validation
run: ./scripts/validate-openapi.sh
dast:
needs: scan
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Run API DAST
run: |
docker run --rm -t \
-e API_BASE_URL=$API_BASE_URL \
zaproxy/zap-stable zap-api-scan.py \
-t openapi.yaml \
-f openapi
Best practices
- Test against a dedicated staging environment
- Use test data only
- Keep secrets in a vault, never in pipeline logs
- Run scans with authenticated and unauthenticated contexts
- Maintain a known-bad test suite for regressions
- Tune rules to reduce false positives
- Make security results visible in PRs
- Automate remediation where possible
Common pitfalls
- Relying only on DAST and ignoring authz logic
- Scanning production directly
- Missing authenticated API coverage
- No OpenAPI/spec drift checks
- Treating all findings as equally blocking
- Ignoring third-party dependencies and containers
If you want, I can also give you:
- a complete CI/CD pipeline template for GitHub Actions, GitLab CI, or Jenkins, or
- a tooling matrix for API security testing by pipeline stage.