Home/Security/OWASP API Security Top 10: Practical Vulnerability Analysis and Defensive Code
SecurityOWASPDevSecOps

OWASP API Security Top 10: Practical Vulnerability Analysis and Defensive Code

APIs sit at the core of modern applications, and OWASP updated its API Security Top 10 in 2023. This post walks through the critical risks with vulnerable vs. fixed code and practical mitigations.

OWASP API Security Top 10: Practical Vulnerability Analysis and Defensive Code
Contents
  1. Why API Security Matters
  2. API1:2023 — Broken Object Level Authorization (BOLA)
  3. API2:2023 — Broken Authentication
  4. API3:2023 — Broken Object Property Level Authorization
  5. API4:2023 — Unrestricted Resource Consumption
  6. API5–10: Key Takeaways
  7. References: Official Documentation

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

JavaScript
// 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

JavaScript
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

JavaScript
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

JavaScript
// :
res.json(user); // password_hash, internal_id

// :
const { id, name, email } = user;
res.json({ id, name, email });

API4:2023 — Unrestricted Resource Consumption

JavaScript
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

RankVulnerabilityKey mitigation
API5Function Level AuthorizationRole-based access control (RBAC)
API6Unrestricted Business FlowsRate limiting on business logic
API7Server Side Request ForgeryValidate against a URL allowlist
API8Security MisconfigurationDisable unused HTTP methods
API9Improper Inventory ManagementAPI version management
API10Unsafe Consumption of APIsValidate 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 verification

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.

Published ·
Topic-related official docs (auto-linked · not per-claim sources)OWASP documentation ↗

Comments

Be the first to comment.