- HTTPS everywhere (TLS 1.2+) -(Transport & Communication)
- Authentication API Keys in Header HTTP Header: Authorization: ApiKey (Authentication)
- Enforce role-based access (RBAC) (Authorization)
- Input Validation Headers,Query params, Body payloads
OAuth 2.0 is an open standard for authorization that allows applications to access resources on behalf of a user without exposing the user's credentials Common OAuth 2.0 Providers:
- Google – Sign in with Google, access Gmail, Google Drive, Calendar.
- Microsoft / Azure AD – Access Microsoft 365 resources, Outlook, OneDrive.
- Facebook – Login via Facebook, access basic profile and friends list.
- GitHub – Login via GitHub, access repos, organizations.
- LinkedIn – Login via LinkedIn, access profile, connections, posts.
- Twitter / X – Login via Twitter, access tweets, followers.
- Rate Limiting: Controls the number of requests a client can make in a given time window. Example: max 100 requests per minute per IP.
- Throttling: Controls how requests are processed once limits are reached. Requests can be delayed, queued, or rejected.
Allow only trusted origins - Avoid: Access-Control-Allow-Origin: *
Idempotency is a concept in APIs (and computing in general) that ensures performing the same operation multiple times has the same effect as doing it once. It prevents unintended consequences when a client retries a request due to network issues, timeouts, or server errors.
Key Idea
- For idempotency keys, the client is usually responsible for generating them, and the server enforces uniqueness and stores the result. string idempotencyKey = Guid.NewGuid().ToString()
- A request is idempotent if repeating it doesn’t change the result.
- Important for critical operations like payments, order creation, or inventory updates.
- Mostly used in post request as calling same order may create duplicate order
POST /orders
Idempotency-Key: 12345
{
"userId": 1,
"itemId": 100,
"quantity": 1
}
- Does this key exist in its database?- Yes: Return the previous response. -No: Process the request, store the key + response.
Log:
- Authentication failures
- Authorization violations
- Rate-limit breaches
- Mask sensitive data (PII, tokens)
- Use short-lived JWTs
- Store secrets in:
- Azure Key Vault
- AWS Secrets Manager
- Rotate secrets automatically
- Both client and server authenticate each other
- Ideal for:
- B2B integrations
- Internal microservices
- Detect:
- Bot attacks
- Scraping
- Credential stuffing
- Use:
- API Gateways
- WAF (Web Application Firewall)
Protect against:
- Broken Object Level Authorization (BOLA)
- Mass Assignment
- Excessive Data Exposure
- Injection attacks
- SSRF
- Enforce OpenAPI schema validation
- Reject non-conforming requests automatically
Examples:
- Azure API Management
- AWS API Gateway
- Kong / Apigee
Capabilities:
- Auth enforcement
- Rate limiting
- IP filtering
- Request validation
- API versioning
- IP allow-listing (where applicable)
- Private endpoints for internal APIs
- Zero Trust networking