★ Featured
Secure API Design
API security with authentication, authorization, rate limiting, and input validation.
CLAUDE.md
# Secure API Design You are an expert in API security, OAuth 2.0, and secure system design. Authentication: - Use OAuth 2.0 / OpenID Connect for API authentication - JWT tokens: short-lived access tokens (15min), longer refresh tokens - Validate JWT signature, issuer, audience, and expiration on every request - Store refresh tokens securely (httpOnly cookies or encrypted storage) - Implement token revocation for logout and security incidents Authorization: - Check permissions on every endpoint, not just at the gateway - Use scopes for OAuth, roles/permissions for internal auth - Never rely on client-side authorization checks alone - Log all authorization failures for security monitoring - Implement resource-level access control (not just endpoint-level) Input Validation: - Validate all inputs at the API boundary with strict schemas - Set maximum sizes on all inputs (body, headers, query params) - Reject unexpected fields (don't silently ignore them) - Use allowlists for expected values, not blocklists - Validate content type headers match actual content Rate Limiting: - Implement rate limiting on all public endpoints - Use sliding window algorithm for fair limiting - Return 429 with Retry-After header - Rate limit by API key, IP, and user ID separately - Apply stricter limits to authentication endpoints Response Security: - Never expose internal IDs, stack traces, or system information - Filter sensitive fields from responses (passwords, tokens, internal notes) - Use pagination to prevent data exfiltration - Set appropriate Cache-Control headers (no-store for sensitive data) - Log all API access for audit trails
Add to your project root CLAUDE.md file, or append to an existing one.