Prompt
How do I add API security checks to CI/CD?
Latest observation
Oct 29, 2026
OpenAI APIWeb search: off
To add API security checks to CI/CD, treat security testing like any other automated quality gate: run it on every pull request, on merges to main, and before production deploys.
1) Decide what to check
A good API security pipeline usually includes:
- API schema validation: verify OpenAPI/Swagger specs are valid and changed safely
- Static checks: scan code for auth/authz mistakes, unsafe deserialization, injection risks
- Dependency scanning: vulnerable libraries in the app and API gateway
- Secret scanning: leaked tokens, keys, certs
- DAST/API scanning: active tests against a running API for common issues
- Auth testing: ensure endpoints require the right tokens/roles
- Contract testing: confirm expected request/response shapes and error handling
- Rate-limit / abuse checks: verify throttling and anti-automation controls
- Infrastructure/IaC scanning: insecure cloud, gateway, and container configs
2) Put checks at the right pipeline stages
On pull request
Run fast checks:
- lint + unit tests
- secret scanning
- dependency scanning
- schema validation
- SAST
- contract tests
On merge to main
Run deeper checks:
- build container image
- container image scanning
- IaC scan
- deploy to staging
- DAST/API security scan against staging
Before production release
- repeat critical scans on release candidate
- enforce policy gates
- manual approval for high-risk findings only if needed
3) Add API-specific security tests
These are especially useful for APIs:
Authentication
- missing token should return 401
- invalid token should return 401
- expired token should return 401
Authorization
- user A cannot access user B’s resources
- read-only role cannot write
- admin-only endpoints reject non-admins
Input validation
- invalid JSON should fail cleanly
- oversized payloads should be rejected
- SQL/NoSQL injection attempts should not succeed
- path traversal and SSRF payloads should be blocked
Rate limiting
- repeated requests trigger 429
- brute-force attempts are throttled
Error handling
- no stack traces or secrets in responses
- consistent error schema
- no debug endpoints exposed
4) Use tools that fit your stack
Common options:
- Secret scanning: GitHub secret scanning, Gitleaks, TruffleHog
- Dependency scanning: Snyk, Dependabot, OWASP Dependency-Check
- SAST: Semgrep, SonarQube, CodeQL
- DAST/API testing: OWASP ZAP, Burp Suite Enterprise, StackHawk, 42Crunch
- Container scanning: Trivy, Grype
- IaC scanning: Checkov, tfsec, Terrascan
- Policy as code: OPA/Conftest, Kyverno, HashiCorp Sentinel
5) Example CI flow
A typical GitHub Actions flow:
- Checkout code
- Install dependencies
- Run tests
- Scan secrets
- Scan dependencies
- Run SAST
- Validate OpenAPI spec
- Build image
- Scan image
- Deploy to ephemeral/staging environment
- Run API DAST suite
- Fail pipeline if severity threshold is exceeded
6) Example gating policy
You can define rules like:
- block merge on any critical vulnerability
- block release on high vulnerabilities with public exposure
- warn only for medium findings
- allow exceptions only with expiry dates and approval
7) Make security checks practical
To avoid slowing everyone down:
- keep fast checks on PRs
- run expensive scans only on main/nightly
- use a staging environment for active API scans
- suppress known false positives carefully
- baseline findings and track new issues only
- fail only on exploitable or unapproved issues
8) A simple starter checklist
If you want the minimum useful setup, start with:
- secret scanning
- dependency scanning
- SAST
- OpenAPI validation
- OWASP ZAP against staging
- CI policy that blocks critical/high findings
If you want, I can also give you:
- a GitHub Actions example,
- a GitLab CI example, or
- a full API security pipeline design for your stack.