Skip to main content

API Security

Tooling

PracticeDescription
Auto Detect IssuesUsing SonarQ to detect issues.
Using AI ToolUsing Windsuf to automate unit testing, documentation

Authentication

PracticeDescription
Avoid Basic AuthUse standards like JWT instead of Basic Authentication.
Use Existing MechanismsDon’t reinvent authentication, rely on proven methods.
Max Retry & JailImplement brute force protection on login.
Encrypt Sensitive DataAlways encrypt sensitive information.

JWT (JSON Web Token)

PracticeDescription
Strong SecretUse a good JWT Secret to prevent brute force attacks.
Verify AlgorithmDo not extract algorithm from header; validate in backend.
Token ExpiryKeep TTL/RTTL as short as possible.
No Sensitive PayloadDon’t store sensitive data inside JWT.
Small PayloadKeep payloads small to reduce token size.

Access Control

PracticeDescription
ThrottlingLimit requests to prevent DDoS and brute force attacks.
HTTPS & CiphersUse secure protocols and ciphers.
HSTSUse HSTS headers to prevent SSL stripping.
Disable Directory ListingTurn off directory browsing.
IP WhitelistingRestrict private APIs to safe-listed IPs.
Validate Redirect URIAlways validate on server side.
Avoid response_type=tokenPrefer code exchange for security.
Use state ParameterPrevent CSRF attacks.
Scope ValidationSet and validate scopes per app.

Input Validation

PracticeDescription
Proper HTTP MethodsUse appropriate methods (GET, POST, etc.).
Validate Content-TypeCheck headers for correct content type.
Validate InputPrevent common vulnerabilities.
Authorization HeaderUse it for sensitive data.
Server-Side EncryptionDo not rely on client-side only.
API GatewayUse for caching, rate limiting, and more.

Processing

PracticeDescription
Auth on All EndpointsProtect every endpoint.
Avoid Personal IDsDon't expose user IDs in URLs.
Use UUIDsPrefer UUIDs to auto-incremented IDs.
Disable XML Entity ParsingPrevent XXE attacks.
Disable Entity ExpansionApplies to XML, YAML, etc.
Use CDNOffload file uploads.
Avoid HTTP BlockingEspecially with large data.
Disable Debug in ProdEnsure debug mode is off.
Non-Executable StacksUse when available.

Output

PracticeDescription
X-Content-Type-OptionsUse nosniff.
X-Frame-OptionsUse deny.
Content-Security-PolicySet default-src 'none'.
Remove Fingerprinting Headerse.g., x-powered-by.
Force Content-TypeExplicitly set response type.
No Sensitive DataDon’t expose credentials/tokens.
Proper Status CodesReturn correct HTTP status codes.

|

Monitoring

PracticeDescription
Centralized LoggingTrack across all services.
Full Request MonitoringWatch requests, responses, errors.
AlertsUse SMS, Slack, Email, Kibana, CloudWatch, etc.
No Sensitive LogsEnsure logs don’t contain sensitive info.
IDS/IPSImplement intrusion detection/prevention systems.