Logged in, yes. But allowed to open this private album?
A FotoFlow user opens their private album at /albums/1042, changes one digit to 1043, and a stranger's private photos load. The login check passed; the ownership check never ran. This is the most common serious bug in APIs, and it has a name: broken object-level authorization.
Check ownership on every request
Every handler that touches an object must answer: does this user own it, or was it shared with them? Logged in is not the same as allowed. Hiding the button in the UI is not a control; the attacker does not use your UI. The check belongs on every request, not in the UI that hides the button. Centralize it in the data layer or middleware so a new endpoint cannot forget it.
When the answer is no, return 404, not 403. A 403 confirms the object exists, which is itself a leak to someone probing ids. Answer 404, not 403: the existence of an object is already information.
Stop trusting the request body
The client sends { "title": "Rome 2026", "role": "admin" } and the server writes both fields. That is mass assignment: one extra field just made the user an admin. Accept known fields explicitly, an allow-list, never Object.assign of the raw body. Validation belongs at the trust boundary where outside data enters.
Roles, rows and relationships
Not everything is ownership. RBAC gives a few meaningful roles, admin, moderator, member, and a matrix of what each may do. Row-level security moves the rule into the database: every query is scoped by owner_id or org_id, so even a bug in the app code cannot fetch another tenant's rows. Shared albums and follower graphs need ReBAC, relationship-based rules of the kind Google's Zanzibar powers: "Alice can view photo P because Ana shared its album with her." Tools like SpiceDB and OpenFGA answer exactly that shape.
The rules themselves can live in one policy engine, OPA or Cedar, evaluated on every request, so policy is code that is versioned, tested and audited instead of scattered through if statements.
What this does not solve
Authorization assumes the caller is who they claim to be, so a stolen session token walks straight past every rule above; that is why the previous part made tokens short-lived. And a confused deputy attack tricks a privileged service into acting for someone else: services calling each other must forward "act as this user" tokens and re-check permissions themselves, never trust the caller's word. One more quiet obligation: append-only audit logs of who saw what, the evidence trail that SOC 2, HIPAA and GDPR auditors will ask for.
The last endpoint you wrote that takes an id from the URL: where exactly is the ownership check?
A moderator service asks for a user's private album on their behalf. Who checks permission, and against which rule?
Access rules decide who may see the photos. Next: what protects all of it when nobody is looking. Next in the series: Photos, tokens, secrets: what protects them when you are not looking?
Sources
OWASP Authorization Cheat Sheet
OAuth 2.0 and OpenID Connect
OWASP Authentication Cheat Sheet
Recommended for you
- Craft & Skills
One server, 10 million users: how does a photo app survive that?
A 40-post series that follows FotoFlow, a photo app, from one server and 100 users to 10 million users with direct messages. One problem, one fix, one honest cost at a time.
- Craft & Skills
Ten million users want direct messages: could you design the chat system?
The final design: 20 million open sockets and a promise that every message arrives, in order, exactly once. Dumb gateways, a connection registry, store-first durability and sync by cursor.
- Craft & Skills
Five million home feeds: how do you build the page everyone opens?
The home feed must load in 200 ms from two hundred followed accounts. Fan-out on read melts at 4.6 million lookups a second; fan-out on write melts on celebrities; the hybrid survives both.
- Craft & Skills
FotoFlow wants short share links: could you design one today?
The first full design walkthrough: turn a one-line brief into numbers, the simplest system, then fix codes, caching, storage and abuse one bottleneck at a time. The method is the point.
Enjoyed this article?
Subscribe for new articles. No spam. Unsubscribe anytime.
Typed live, never pasted.