Course map

Topic 167 / Advanced

Web and API security

Chapter 10.4 · Application and API Security

What and why

The Top 10 (→ 166) names the risk categories; this topic is the practical hardening that stops the most common instances of them from reaching production — chiefly around broken access control, injection, and insecure design. None of these controls are exotic; they're details that are easy to skip under deadline pressure and expensive to add back after a breach. Builds on: → 166 (OWASP Top 10, 2025 edition).

Diagram

Attack Hardening control Where it's taught in full
Mass assignment Explicit allow-list of writable fields, never bind the whole request body New here
Credential stuffing / brute force Rate limiting as a security control, not only a capacity control → 96
Information leakage via errors Generic error messages — no stack traces, no "user not found" vs "wrong password" distinction → 1 (deliberate error handling)
Missing per-object checks Resource-level authorization re-verified per object, every request → 39, 163

How it works

  1. Validate all input server-side, regardless of what the client already validated — a client-side check is a UX convenience, never a security control.
  2. Prevent mass assignment: explicitly allow-list which fields a request may set on an internal model; never bind an entire request body onto it and trust the result.
  3. Apply rate limiting (→ 96) as a security control — against credential stuffing, brute-force login attempts, and scraping — not only as a capacity-protection measure.
  4. Design error responses deliberately: no stack traces, library versions, or internal paths in a response body; the same message for "wrong password" and "no such account" on login, so a caller can't enumerate valid accounts by trying many and watching which message comes back.
  5. Re-verify resource-level checks (→ 39, 163) per object, on every endpoint — the check that matters is per object, never merely per route.
  6. Stack these controls — defense in depth (→ 158) means losing any single one of them shouldn't mean total compromise.

Practical example

(illustrative). A PATCH /users/{id} endpoint binds the entire request body directly onto the internal user model. A caller updating their own profile adds "role": "admin" to the request body; with no allow-list, the field binds and the caller becomes an admin. The fix is an explicit allow-list — only {name, email} may be set by this endpoint — regardless of what the request body contains.

When to use it

  • Use on every API handling untrusted input, public or internal — this is Advanced because it compounds several earlier topics, not because it's optional.
  • Avoid skipping hardening on "internal-only" APIs: internal callers and services are frequently the first thing compromised in a real breach (→ 169, zero trust).
  • Failure scenarios: mass assignment granting unintended privilege; an unthrottled login endpoint enabling credential stuffing at scale; a "user not found" vs. "wrong password" message difference letting an attacker enumerate valid accounts one guess at a time.
  • Simpler alternative: for a low-stakes internal tool, a strict field allow-list plus basic rate limiting covers most of the realistic risk, without the full network-layer controls of → 168.

Practice

(Pattern kind — spot the misuse, implement minimal; 20–30 min, lab: Redis for rate limiting). Given a handler that binds a whole request body onto an internal model, identify the mass-assignment risk and rewrite it with an explicit field allow-list. Then add rate limiting to a login endpoint using the lab's Redis, and confirm that repeated failed attempts from one source are throttled while a legitimate single login still succeeds. Done when the mass-assignment fix is demonstrated (the rewritten endpoint rejects an unexpected field) and the throttle is demonstrated (a burst of attempts is measurably slowed).

Shared lab setup

Key takeaway

Most real-world API breaches come from a handful of specific, fixable gaps — unrestricted field binding, unthrottled auth endpoints, and chatty error messages — not exotic attacks. Done when you can: given an API handler, name its mass-assignment, rate-limiting, and error-leakage exposure and fix all three. Used next in → 172 (these findings become what a SAST/DAST pipeline should catch), → 168 (network-layer controls on top of these).

References

None — this topic makes no external claims.

Source directory

Search the guide