Skip to content

API Security Basics and Final Project: Access Checks, Safe Output, Rate Limits and Timeouts

NeedMyTools Academy

Sign in free to read the full lesson

Sign in or create a free account

Free forever. No card, no paywall.

Most API breaches do not need clever hacking. Someone changes /orders/1041 to /orders/1042 and sees a stranger’s order, or an endpoint returns a full customer record when the screen only shows a name, or a script sends ten thousand requests a minute because nothing stops it. This last lesson of the course collects the basics that prevent those failures, using the order of the OWASP API Security Top 10 as a guide. You will look at real headers from a production site, watch a real rate limiter answer 429, see an XSS injection run in a live example, and finish with a project: a small API client that applies everything from the course.

Quick answer

Secure an API in layers. On every request, check that the logged-in user may access that exact record, not only that they are logged in. Return only the fields the client needs, and accept only the fields a user may change. Serve everything over HTTPS with headers such as Strict-Transport-Security and X-Content-Type-Options: nosniff. Treat all API data as untrusted when you display it: use textContent, not innerHTML. Limit request rates with 429 and Retry-After, and give every client call a timeout.

45 min read and practice · Content checked on 1 December 2026

In this lesson you will

  • Check access per record and avoid data exposure and mass assignment
  • Read security headers and display API data without XSS
  • Handle rate limits, retries and timeouts in a real API client

Who may see this record, and which fields

The top risk in the OWASP API list is broken object level authorization. An endpoint like GET /orders/:id checks that the caller is logged in, then loads whatever id is in the URL. Ids are easy to guess, so any customer can read every order. The fix is one rule applied everywhere: load the record together with its owner, for example WHERE id = $1 AND user_id = $2, and answer 404 when it does not belong to the caller. Tests should log in as user A and try to read user B’s data.

The recording shows the second problem. A screen that lists customer names called /users/1 and received the email, phone, home address with map coordinates and employer too. On JSONPlaceholder this is fake data, but real APIs leak exactly like this when they return database rows as they are. Choose the output fields on the server for each endpoint. The reverse mistake is mass assignment: saving req.body straight into the database lets a user send "role": "admin" or "balance": 99999. Copy only the fields you allow.

Example: Everything an endpoint sent when the screen needed one name
Real output: curl https://jsonplaceholder.typicode.com/users/1
{
  "id": 1,
  "name": "Leanne Graham",
  "username": "Bret",
  "email": "Sincere@april.biz",
  "address": {
    "street": "Kulas Light",
    "suite": "Apt. 556",
    "city": "Gwenborough",
    "zipcode": "92998-3874",
    "geo": {
      "lat": "-37.3159",
      "lng": "81.1496"
    }
  },
  "phone": "1-770-736-8031 x56442",
  "website": "hildegard.org",
  "company": {
    "name": "Romaguera-Crona",
    "catchPhrase": "Multi-layered client-server neural-net",
    "bs": "harness real-time e-markets"
  }
}

Hiding fields in the front end does not help: anyone can open the Network tab and read the full response. If a field must stay private, the server must never send it.

Sign in free to read the full lesson

You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.

Unlocks after sign-in:

  • 2 more sections with live code examples
  • Common mistakes to avoid
  • Hands-on coding exercise with automatic checks
  • Practice quiz and the graded lesson test
Sign in or create a free account

Free forever. No card, no paywall.

Questions people ask

What is the OWASP API Security Top 10?

A free list, last updated in 2023, of the most common and serious API risks, written by the OWASP Foundation. Broken object level authorization is number one. It is a good checklist to review an API before launch.

Should I use random UUIDs instead of numeric ids?

UUIDs make ids hard to guess, which helps, but they are not access control. An id can still leak through a shared link or a log. Keep the ownership check either way.

How strict should a rate limit be?

Measure normal use first and set the limit well above it. Login, password reset and code verification deserve much tighter limits, such as a handful of tries per minute per account and per IP.

Is HTTPS enough to secure an API?

No. HTTPS protects data on the way, but it does not check who may read which record, validate input or stop abuse. It is the first layer, not the whole wall.

Where can I practise API security legally?

Only on your own projects or on deliberately vulnerable training apps such as OWASP crAPI and Juice Shop, run on your own machine. Testing someone else’s API without written permission can break the law.

Sources

Facts in this lesson were checked against these official pages on 1 December 2026.

Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.