Why API Security Matters
APIs are the core of modern applications. OWASP updated the API Security Top 10 in 2023.
API1:2023 — Broken Object Level Authorization (BOLA)
This is the most common and most critical vulnerability.
Vulnerable code
// GET /api/orders/{orderId}
app.get('/api/orders/:orderId', async (req, res) => {
// : User check
const order = await Order.findById(req.params.orderId);
res.json(order);
});Fixed code
app.get('/api/orders/:orderId', authenticate, async (req, res) => {
const order = await Order.findOne({
_id: req.params.orderId,
userId: req.user.id // required
});
if (!order) return res.status(403).json({ error: 'Forbidden' });
res.json(order);
});API2:2023 — Broken Authentication
Secure JWT configuration
import jwt from 'jsonwebtoken';
const token = jwt.sign(
{ userId: user.id },
process.env.JWT_SECRET,
{ algorithm: 'HS256', expiresIn: '1h' }
);
// when when required
const decoded = jwt.verify(token, process.env.JWT_SECRET, {
algorithms: ['HS256']
});API3:2023 — Broken Object Property Level Authorization
// :
res.json(user); // password_hash, internal_id
// :
const { id, name, email } = user;
res.json({ id, name, email });API4:2023 — Unrestricted Resource Consumption
import rateLimit from 'express-rate-limit';
const limiter = rateLimit({
windowMs: 15 * 60 * 1000,
max: 100,
message: { error: 'Too many requests' }
});
app.use('/api/', limiter);API5–10: Key Takeaways
| Rank | Vulnerability | Key mitigation |
|---|---|---|
| API5 | Function Level Authorization | Role-based access control (RBAC) |
| API6 | Unrestricted Business Flows | Rate limiting on business logic |
| API7 | Server Side Request Forgery | Validate against a URL allowlist |
| API8 | Security Misconfiguration | Disable unused HTTP methods |
| API9 | Improper Inventory Management | API version management |
| API10 | Unsafe Consumption of APIs | Validate third-party API responses |
API security must start in the development phase. Fixing issues after deployment costs 10–100× more.
References: Official Documentation
The primary sources for the behavior, configuration, and errors covered in this article are the official documents below. Check them for version-specific options and exact behavior.
Sources and checks vary by article. Only articles with a recorded check date, scope and sources below were checked, and only within that scope. For other articles, verify against the current docs for your version before applying anything, and email us about errors. Editorial policy · email us
This article has no recorded human check (date and scope) yet.
Comments
Be the first to comment.