API security breaches cost companies an average of $4.45M per incident. 83% of organisations experienced an API security incident in 2024. Most breaches exploit the same set of well-known vulnerabilities that are entirely preventable.
Why API Security is Your Most Urgent Priority
APIs are now the primary attack surface for modern applications. Unlike web UI vulnerabilities (which require a user to click something), API vulnerabilities can be exploited programmatically — meaning attackers can run thousands of attacks per second with automated tools.
Your API is exposed to the internet 24/7. Every endpoint is a potential entry point.
1. Rate Limiting
Without rate limiting: Attackers can brute-force credentials, scrape your data, or overwhelm your server in minutes.
Implementation (Node.js with express-rate-limit):
Node.js example with express-rate-limit:
const rateLimit = require('express-rate-limit');
const limiter = rateLimit({
windowMs: 60 * 1000,
max: 100,
message: 'Too many requests, please try again later.'
});
app.use('/api/', limiter);
Rate limiting should be applied at three levels:
- Per IP address (prevents mass attacks)
- Per user account (prevents targeted brute force)
- Per API key (prevents key abuse)
API Attacks by Type — 2024 Breakdown
Source: Salt Security State of API Security Report 2024. BOLA is the #1 API-specific vulnerability.
Is your business actually secure?
Most businesses discover vulnerabilities only after a breach. A professional penetration test finds them first.
2. JWT Authentication
Never use API keys for user authentication. Use JSON Web Tokens (JWT) with proper configuration.
| Setting | Wrong | Right |
|---|---|---|
| Algorithm | HS256 (symmetric) for public APIs | RS256 (asymmetric) |
| Expiry | None or 30 days | 15 minutes (access) + refresh token |
| Secret storage | In code | Environment variable + secret manager |
| Validation | Trust the token | Validate signature + expiry + issuer |
Common JWT mistake: Not validating the token on every request. Every protected endpoint must verify the signature.
3. Input Validation and Sanitisation
All user input is untrusted. Validate everything:
- Type validation: Is this field a string when you expect an integer?
- Range validation: Is this quantity between 1 and 1000?
- Format validation: Is this actually an email address?
- SQL injection: Use parameterised queries, never string concatenation
- NoSQL injection: Sanitise MongoDB operators ($where, $regex)
Use a validation library (Zod for TypeScript, Pydantic for Python, Joi for Node.js).
4. HTTPS and Certificate Management
- Enforce HTTPS everywhere. Redirect HTTP to HTTPS. Return HSTS headers.
- Use TLS 1.2 minimum, TLS 1.3 preferred
- Implement certificate pinning for mobile apps
- Auto-renew certificates (Let's Encrypt + certbot)
- Scan for expired certs weekly (use Qualys SSL Labs)
5. Monitoring and Alerting
You cannot protect what you cannot see. Implement:
- Access logging: Every API call with: user, endpoint, status, response time, IP
- Anomaly detection: Alert on: unusual request volume, 4xx spike, off-hours admin access
- Security scanning: Weekly automated scans with OWASP ZAP or Burp Suite
- Incident response: Documented procedure for when a breach is detected
Security Audit Your API
Our security team performs comprehensive API security audits covering all OWASP API Security Top 10 vulnerabilities. Book an API security audit — we deliver a prioritised fix list within 5 business days.
Tags
- API Security
- JWT
- Rate Limiting
- Authentication
Written by
Editorial team
An independent engineering practice building platforms, automation and security.
Field notes
Engineering notes, security advisories and case files. Monthly, no noise.