Prompt
I'm building a DevSecOps pipeline and need API security tests
Latest observation
Absolutely — for a DevSecOps pipeline, API security tests should cover both automated functional checks and security-focused abuse cases. A good approach is to layer them by pipeline stage so you catch issues early and keep tests fast enough for CI.
Core API security test areas
1) Authentication tests
Validate that only legitimate clients can access the API.
- Missing token is rejected
- Expired token is rejected
- Invalid signature / malformed JWT is rejected
- Revoked token is rejected
- Token audience / issuer mismatch is rejected
- MFA-required flows cannot be bypassed
- Anonymous access is blocked where required
2) Authorization tests
Ensure users can only access what they’re allowed to.
- Horizontal privilege escalation:
- User A cannot access User B’s resources by changing IDs
- Vertical privilege escalation:
- Regular user cannot access admin endpoints
- Role-based access control enforced consistently
- Scope/claim enforcement for OAuth2 tokens
- Method-level authorization:
GETmay be allowed, butPUT/DELETEdenied
3) Input validation / injection tests
Check that unsafe input doesn’t reach downstream systems.
- SQL injection payloads
- NoSQL injection payloads
- Command injection payloads
- LDAP injection if applicable
- Path traversal in file/resource parameters
- Header injection / CRLF injection
- SSRF attempts through URL-fetching endpoints
- JSON/XML parsing edge cases
- Oversized payloads / malformed content types
4) Rate limiting / abuse control
Confirm the API resists automated abuse.
- Burst requests trigger throttling
- Repeated auth failures trigger lockout or step-up
- Enumeration attempts are rate-limited
- Pagination scraping is constrained
- Brute-force protection on login/reset endpoints
- Distributed requests still trigger protection if applicable
5) Sensitive data exposure
Prevent leakage of secrets and personal data.
- No secrets in responses
- No stack traces or debug info in production
- Tokens not returned in logs or headers unnecessarily
- PII masked/redacted where required
- Error messages do not reveal internal structure
- Cache headers correct for sensitive responses
- TLS enforced; no plaintext endpoints
6) Error handling and security headers
Verify secure defaults and non-revealing failures.
- Generic 4xx/5xx errors
- No detailed exception leakage
- Security headers present where relevant:
Strict-Transport-SecurityContent-Security-Policyfor browser-facing APIsX-Content-Type-OptionsCache-Control: no-storefor sensitive data
7) Business logic abuse
APIs are often vulnerable even when “secure” technically.
- Replaying requests should not create duplicate transactions
- Tampering with price/quantity/discount fields is rejected
- State transitions are enforced:
- cannot cancel completed order, etc.
- One-time tokens cannot be reused
- Approval workflows cannot be skipped
- Multi-step flows can’t be shortcut
8) CORS and browser-facing protections
If the API is accessed from browsers:
- CORS does not allow arbitrary origins
- Credentials not allowed with wildcard origins
- Preflight responses are correct
- Cross-origin sensitive endpoints are protected
9) File upload/download tests
If applicable, these are high-risk.
- File type validation
- Extension/content mismatch rejected
- Malware scanning hooks work
- Upload size limits enforced
- Stored file names sanitized
- Download endpoints prevent path traversal
- Direct object access to uploads is controlled
10) Dependency and version exposure
Ensure the API and stack don’t reveal too much.
- Server/version banners removed
- Deprecated endpoints return safe deprecation notices
- OpenAPI/Swagger exposed only as intended
- No internal hostnames or build metadata leaked
Recommended automated tools in CI/CD
You can combine these by stage:
In unit/integration tests
- Authorization unit tests
- Input validation tests
- Business logic tests
- Contract tests for expected security behavior
In QA/staging
- DAST tools:
- OWASP ZAP
- Burp Suite Enterprise
- StackHawk
- 42Crunch
- API fuzzing:
- Schemathesis
- RESTler
- Auth testing:
- Negative JWT/OAuth test cases
- Runtime validation:
- Check logs, headers, and error responses
In pre-deploy / runtime
- WAF policy validation
- Rate-limit verification
- Secret scanning
- Container/image scanning
- IaC scanning
- SAST + dependency scanning
Minimal API security test checklist
Use this as a baseline for every endpoint:
- Requires authentication where expected
- Enforces authorization on every object/action
- Rejects invalid, expired, and tampered tokens
- Validates all inputs and content types
- Prevents injection and traversal attempts
- Handles errors without leaking internals
- Applies rate limiting and abuse controls
- Protects sensitive data in transit and at rest
- Logs securely without secrets/PII leakage
- Enforces correct state and business rules
Example test cases
Here are a few concrete examples:
GET /users/123as user456→ 403 ForbiddenPOST /loginwith 20 failed attempts → 429 Too Many RequestsGET /orderswith expired JWT → 401 UnauthorizedDELETE /admin/configas regular user → 403 ForbiddenPOST /itemswithprice=-1→ 400 Bad RequestGET /search?q=' OR 1=1 --→ rejected / sanitizedPOST /uploadwith.exedisguised as.jpg→ blockedGET /export?url=http://169.254.169.254/→ blocked SSRF
Good pipeline pattern
A practical DevSecOps flow looks like this:
-
Pre-commit
- secrets scanning
- linting
- basic unit tests
-
PR/CI
- SAST
- dependency scan
- authz/authn unit tests
- input validation tests
-
Staging
- DAST against OpenAPI spec
- fuzzing
- rate-limit and abuse tests
- security regression tests
-
Pre-prod
- scan exposed endpoints
- confirm headers/TLS/CORS
- verify logging/monitoring alerts
-
Runtime
- anomaly detection
- WAF rules
- auth failure alerts
- secret exposure monitoring
If you want, I can also provide:
- a ready-to-use API security test suite template,
- Postman/Newman tests,
- OWASP ZAP automation, or
- a CI pipeline example for GitHub Actions/GitLab/Jenkins.