Track 07 · Lesson 1 of 18Identity and login

Track 07 · Identity and login

Authentication vs authorization

Lesson 1 of 18· 6 min

Two questions sit behind every login. Authentication asks “who are you?”. Authorization asks “what are you allowed to do?”. Many serious bugs are authorization bugs on users who logged in perfectly correctly.

Who may do what?

Switch callers, then turn checks off

Who is calling

What the API checks

  • GET /me200✓ Allowed, correctly
  • GET /brands/123/invoices200✓ Allowed, correctly
  • GET /brands/124/invoices200✕ Shouldn’t be allowed
  • DELETE /users/7200✕ Shouldn’t be allowed

The button is gone from the page, which is nice. But curl -X DELETE https://api.example.com/users/7 skips the page and reaches the API directly. Only the role check above decides.

2 requests served that shouldn’t be. Changing 123 to 124 shows another customer’s invoices: an IDOR. A normal user can delete accounts. Knowing who someone is doesn’t tell you what they may do.

Authentication: who are you?#

Proving identity: a password, a Google account, a passkey, a one-time code. In practice, password login, social sign-in, two-factor and email verification should all end in one place in your code that issues the session or tokens. Several slightly different copies drift apart, and one of them always ends up missing a check.

Authorization: what may you do?#

Checked after identity is known, on every request, by the server. Two kinds come up constantly:

  • Roles: is this person an admin? Hiding the admin page in the browser is only cosmetic. Anyone can call the API directly with curl, skipping the page.
  • Ownership: does this object belong to them? An endpoint that takes brandId=123 and returns it without checking the caller owns brand 123 is an IDOR (insecure direct object reference). Changing 123 to 124 shows someone else’s data.

HTTP forgets you#

Every request a browser makes is independent. The server doesn’t remember that you logged in a second ago. So after login, it gives you something to show on every later request instead of your password: a session ID or a signed token. The rest of this track is about that “something”: what it is, where it lives, how it’s refreshed, and how it ends.

Check yourself

Admin pages are hidden in the UI for normal users. Is that enough?