Prompt
I’m building APIs and want to know where to put security controls
Latest observation
Oct 29, 2026
OpenAI APIWeb search: off
A good rule is: layer security controls at every trust boundary in your API, not just at the edge.
Where to put security controls
1. At the API gateway / edge
Use this for cross-cutting protection:
- TLS termination / HTTPS enforcement
- Authentication enforcement
- Rate limiting / throttling
- IP allow/deny lists
- Basic request size limits
- Bot / abuse protection
- WAF rules
- Request logging and correlation IDs
2. At the application/API layer
This is where you do business-aware security:
- Authorization checks per endpoint and per object
- Input validation and schema validation
- Session/token validation
- CSRF protection if browser-based
- Idempotency checks for sensitive operations
- Business rule enforcement
- Preventing mass assignment / over-posting
3. At the service-to-service layer
For internal APIs and microservices:
- Mutual TLS
- Service identity and auth
- Least-privilege service accounts
- Per-service authorization
- Network segmentation
- Secret rotation
- Signed service tokens / short-lived credentials
4. At the data layer
Protect data even if the app is bypassed:
- Encryption at rest
- Column/field-level encryption for sensitive data
- Database access controls
- Row-level security where supported
- Audit logging for sensitive reads/writes
- Backup protection and key management
5. In CI/CD and deployment
Prevent insecure code from shipping:
- SAST/DAST and dependency scanning
- Secret scanning
- Infrastructure-as-code checks
- Policy checks before deploy
- Environment-specific config controls
- Signed artifacts and provenance
6. In observability and operations
Detect abuse and incidents:
- Security logs
- Anomaly detection
- Alerting on auth failures, spikes, privilege changes
- Tamper-resistant audit trails
- Incident response hooks
Practical pattern
If you’re deciding “where should this control live?”:
- Block obvious abuse early at the edge
- Make all important decisions in the app
- Protect internal calls too
- Assume data may be accessed, and secure it directly
- Continuously verify in the pipeline and monitor in production
Simple example
For a POST /orders API:
- Gateway: TLS, rate limit, auth required
- App: verify user can create for that tenant, validate payload, enforce business rules
- Service-to-service: mTLS to payment service
- Data layer: encrypt card-related fields, restrict DB permissions
- Ops: log order creation and failed auth attempts
If you want, I can also give you a security control checklist by layer or map this to OWASP API Security Top 10.