Skip to content

Cybersecurity

Securing a REST API: the 10 OWASP risks to check

Object-level authorization, authentication, data exposure, resource consumption… The ten risks of the OWASP API Security Top 10 explained, with the concrete controls to put in place and automate.

Published 4 min read

Why APIs are a prime target

A REST API directly exposes an application's data and business logic: every route is an entry point that can be called without going through the intended interface. Checks performed only in the browser (a hidden button, a disabled field) therefore offer no protection: an attacker simply calls the API.

OWASP (Open Worldwide Application Security Project) publishes a ranking dedicated to APIs, the OWASP API Security Top 10, whose latest edition dates from 2023. It is a shared reference for designing, building and auditing an API.

The ten risks at a glance

  1. API1 – Broken Object Level Authorization (BOLA): a user accesses someone else's object by changing an identifier in the URL (/invoices/1042 → /invoices/1043).
  2. API2 – Broken Authentication: poorly verified tokens, weak passwords accepted, no limit on login attempts.
  3. API3 – Broken Object Property Level Authorization: the API returns fields that should not be visible, or accepts changes to protected fields (mass assignment, for example role or isAdmin).
  4. API4 – Unrestricted Resource Consumption: no maximum page size, payload limit or rate limit; a single request can overload the server or run up costs.
  5. API5 – Broken Function Level Authorization: a regular user calls an administration route.
  6. API6 – Unrestricted Access to Sensitive Business Flows: a legitimate flow (booking, sign-up, ordering) is automated at scale and abused.
  7. API7 – Server Side Request Forgery (SSRF): the API fetches a user-supplied URL and can be used to reach internal services.
  8. API8 – Security Misconfiguration: overly permissive CORS, detailed error messages, missing security headers, unnecessary methods enabled.
  9. API9 – Improper Inventory Management: forgotten old versions or test environments, still reachable and unpatched.
  10. API10 – Unsafe Consumption of APIs: responses from third-party services are used without validation, as if they were trustworthy.

Risk #1: object-level authorization

Being authenticated does not mean being allowed to access every resource. The rule: every request that handles an object must check, on the server, that the user is entitled to it. The safest way is to build this check into the database query itself, rather than loading the object and checking afterwards.

ts
// GET /api/invoices/:id — users only see their own organisation's invoices
app.get("/api/invoices/:id", requireAuth, async (req, res) => {
  const invoice = await db.invoice.findFirst({
    where: { id: req.params.id, organizationId: req.user.organizationId },
  });
  // 404 rather than 403: do not confirm that someone else's resource exists
  if (!invoice) return res.status(404).end();
  // Only return the intended fields (risk API3)
  res.json(toPublicInvoice(invoice));
});

Unpredictable identifiers (UUIDs) make enumeration harder, but never replace access control. Administration routes must check the user's role on every call (risk API5), ideally through shared middleware rather than case by case.

Authentication and tokens

  • Always verify the token (JWT) signature, the expected algorithm, the issuer (iss), the audience (aud) and the expiry (exp).
  • Use short-lived access tokens and rotate refresh tokens on every use.
  • Rate-limit login and password reset routes.
  • Enable multi-factor authentication for administrator accounts.
  • Never put secrets (API keys, signing keys) in the code or the Git repository: provide them through environment variables or a secrets manager.

Validate inputs and limit resources

Every input should be validated against an explicit schema (Zod, JSON Schema…) that lists the allowed fields: any unknown field is rejected or ignored. It is the simplest protection against mass assignment.

ts
const UpdateProfile = z.object({
  displayName: z.string().trim().min(1).max(80),
  locale: z.enum(["fr", "en"]),
}).strict(); // a "role" field sent by the client is rejected

app.patch("/api/me", requireAuth, async (req, res) => {
  const data = UpdateProfile.parse(req.body);
  await db.user.update({ where: { id: req.user.id }, data });
  res.status(204).end();
});
  • Cap page sizes (maximum limit), request sizes and processing time.
  • Apply rate limits per user and per address, stricter on sensitive flows (API4, API6).
  • If the API must fetch a user-supplied URL, restrict it to an allowlist of domains and block internal addresses (API7).

Configuration, inventory and third-party APIs

  • HTTPS only, with HSTS; CORS restricted to the origins actually in use.
  • Generic error messages for clients, details only in server logs.
  • Up-to-date OpenAPI documentation that doubles as an inventory: every version and every exposed environment is listed, and old versions are retired on a known schedule (API9).
  • Responses from third-party APIs are validated like any other input, with timeouts and error handling (API10).

Automate the checks in CI/CD

A one-off manual review is not enough: the code changes every week. The DevSecOps approach builds the checks into the pipeline, so that a regression blocks the release instead of being discovered later. See our Cybersecurity & DevSecOps expertise.

  • Dependency audits (npm audit, Dependabot) and secret detection in the repository (gitleaks).
  • Static code analysis (Semgrep, CodeQL).
  • Automated authorization tests: “user A can neither read nor modify user B's resource”, for every sensitive route.
  • Dynamic analysis (OWASP ZAP) on a staging environment.
  • Logging of authentication and authorization failures, with alerts.

Pre-release checklist

  • Every route that handles an object checks that the user is entitled to it.
  • Administration routes check the role on every call.
  • Inputs are validated against a schema; responses only contain the intended fields.
  • Page sizes, request sizes and rate limits are capped.
  • Tokens are verified (signature, issuer, audience, expiry); secrets are kept out of the code.
  • CORS, HTTPS, security headers and error messages are configured.
  • The inventory of exposed versions and environments is up to date.
  • Security checks are automated in CI/CD.

Key takeaways

  • Authentication is not enough: authorization is checked on every object, on the server.
  • A strict validation schema protects inputs and prevents mass assignment.
  • Limiting resources (page size, payload size, rate limits) is part of security.
  • Automated checks in CI/CD prevent regressions with every release.

Keywords

  • OWASP
  • REST API
  • Authorization
  • DevSecOps

Contact

A technical question or a project? Let's talk.

Tell us about your need, your context or your technical challenge. We'll get back to you to discuss it, with no commitment.