Back to blog

Logged in, yes. But allowed to open this private album?

Thắng Đoàn
Thắng Đoàn

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

Share:

Recommended for you

Enjoyed this article?

Subscribe for new articles. No spam. Unsubscribe anytime.

No pasting. This is the challenge.0/200

Typed live, never pasted.