Reliability and security · L1Authentication and authorization

Authentication and authorization

Prove who the user is, then check what they may do, on every request and for every object.

L1 Must-knowReliability and security20 min read
Fact-checked by AI against cited sources · Human review pendingLast reviewed 21 Oct 2026 · How we check content
Section 1 of 8

What broke

First American is a large US title insurance company. In 2013 it launched EaglePro, an app that sent document images to customers through unique links. 1

From 2014, the app had a defect. A user could take the URL of their own document and change some digits in it. The server then showed other people's documents. The user should not have had access to those images. 1

The company's own security team found this in a manual test. Their report was finished on 11 January 2019. It said that replacing a number in the URL with another sequential number gave access to other documents. A clerical error gave the flaw a lower severity, so its deadline became 90 days instead of 45. That deadline was 8 May 2019, and the flaw was still not fixed after it. 1

On 24 May 2019, a cybersecurity journalist told the company about it. The flaw exposed over 800 million title and escrow document images, going back to 2003. Some held social security numbers and financial information. 2

The executives who answered the press did not know about the January report. 1 In 2021, the SEC charged the company with failing to keep proper disclosure controls. It agreed to pay a $487,616 penalty, without admitting or denying the findings. 2

The bug was one missing check: "Does this document belong to the person asking?" The same mistake is number one on the OWASP API Security Top 10 today. 3

Section 2 of 8

The idea in simple words

Two questions protect every request.

  • Authentication: who are you? The user proves it with a password, a second factor or a login at another provider.
  • Authorization: what may you do? The server checks if this user may do this action on this object.

Authentication happens once at login, and then a session or token carries the answer on each request. Authorization must happen on every request, for the exact object asked for. OWASP says to check permissions on every request, on the server, and to deny by default. 4

The key idea. Logging in proves who you are. It never proves you may touch this order. Check ownership or permission on the server, every time, for every object.

Section 3 of 8

How it works

Step through one login and one request for an order. Use Next and Back, or the ← and → keys.

Log in, then every request is checked: who are you, and may you see this order? Browser Orders API Database POST /loginemail + passwordcheck hash✓ Asha Set-Cookie: sidHttpOnly · Securecookie saved GET /orders/123cookie sentsid → Asha order 123?owner: Ravi404 Not FoundAsha is not Ravi ✓ owner checked every time SeniorPath
  1. Asha logs in. The API finds her account and compares a hash of the password she typed with the stored hash. It never stores or decrypts her real password.
  2. Authentication worked. The API creates a session and sends its random ID in a cookie. HttpOnly hides it from JavaScript, and Secure sends it only over HTTPS.
  3. Asha's browser asks for order 123 and sends the cookie on its own. The API looks up the session ID and learns who is asking: Asha. This is authentication, again, on every request.
  4. Now authorization. The API loads order 123 and sees that it belongs to Ravi, not Asha. It refuses. A 404 also hides that order 123 exists.
  5. The check runs on every request, for the exact object asked for. Changing 123 to 124 in the URL gets Asha nothing she does not own.
Step 1 of 5

Passwords done right

Never store a password as it is. Hash it. A hash is one-way, so even you cannot get the password back. 5 Encryption is two-way, so anyone with the key can. OWASP says to encrypt passwords only in rare edge cases. 5

Use a slow password hashing function, not a fast one like plain SHA-256. OWASP's first choice is Argon2id with at least 19 MiB of memory, 2 iterations and a parallelism of 1. If Argon2id is not available, use scrypt. 5 Use bcrypt only for older systems where neither is available, with a work factor of at least 10. Most bcrypt libraries read at most 72 bytes of a password. 5 Each password gets its own random salt, so two users with the same password get different hashes. Good libraries handle the salt for you. 5

At the login form, OWASP says to:

  • Treat passwords shorter than 8 characters as weak when multi-factor authentication (MFA) is on, and shorter than 15 when it is off. 6
  • Allow at least 64 characters, so people can use passphrases. 6
  • Block common and already breached passwords. 6
  • Show one generic error, like "Invalid user ID or password", so attackers cannot learn which accounts exist. 6

Then add MFA. OWASP calls it "by far the best defense against the majority of password-related attacks". It cites a Microsoft analysis that MFA would have stopped 99.9% of account compromises. 6

Sessions and cookies

After login, the server must remember the user. The classic way is a session. The server stores the session and sends the browser a random session ID in a cookie. The browser sends the cookie back with each request on its own. 8

Set three cookie attributes:

  • HttpOnly: JavaScript cannot read the cookie. This limits the damage of cross-site scripting (XSS). 8
  • Secure: the browser sends it only over HTTPS. 8
  • SameSite: controls whether the cookie goes with requests from other sites. OWASP says to set Strict (preferred) or Lax on session cookies. 7

The session ID needs at least 64 bits of entropy, so nobody can guess it. Give the user a new session ID after login. On logout, delete the session on the server, not only the cookie. 7

Tokens and JWTs

A JWT (JSON Web Token) is a compact, URL-safe string that carries claims, such as a user ID. It can be signed, as a JWS, or encrypted, as a JWE. 9 This lesson is about signed JWTs.

Signed is not secret. The payload is only base64url encoded, so anyone with the token can read every claim. 10 Never put private data in it. The signature only proves that nobody changed it. 10

Give each JWT an exp claim. The exp claim is optional in the standard, but once it is set, the token must not be accepted on or after that time. 9 Your parser must reject tokens with "alg":"none", which have no signature. 10

The big catch is revocation. The server checks a JWT by its signature, with no lookup. So a stolen token works until it expires. Fixes: keep lifetimes short, and if you must revoke early, keep a denylist keyed on the token's jti and issuer. 10 Once you add that lookup, you have a session store again.

OAuth 2.0 and OpenID Connect

OAuth 2.0 is about delegation. It lets an app get limited access to an API for a user, without the user's password. 11 Example: a printing app wants to read your photos from a cloud drive.

It has four roles: the user (resource owner), the app (client), the authorization server that issues tokens, and the API (resource server). 11

OpenID Connect (OIDC) is about login. It is an identity layer on top of OAuth 2.0. It adds an ID token, a signed JWT with claims about how the user logged in. 15 The app must check that iss is the expected provider, that aud holds its own client ID, and that exp has not passed. 15

The app must also check the signature. One exception: if the app got the ID token straight from the token endpoint over TLS, the spec allows it to trust TLS instead. 15

The normal flow today is the authorization code flow with PKCE:

  1. The app makes a random secret, the code verifier. It sends its SHA-256 hash, the code challenge, with the S256 method. 13
  2. The user logs in at the authorization server. The server redirects back to the app with a short-lived code. 11
  3. The app swaps the code for tokens and sends the original verifier. The server hashes the verifier and compares it with the challenge. 13

PKCE stops an attacker who steals the code on its way back, because they do not have the verifier. 13 RFC 9700 says public clients, such as mobile and browser apps, must use PKCE. It also says the implicit grant should not be used, and the password grant must not be used. 14

Check every object, with the least privilege

Broken object level authorization (BOLA) happens when an API takes an object ID from the client and does not check that the caller may use that object. OWASP calls it "extremely common". 3 The fix is the check in the diagram, in every function that reads a record using an ID from the client. Random IDs make guessing harder, and authorization tests stop regressions. 3 Random IDs alone are not enough. 4

Give each user, service and token only the access it needs. OWASP asks for least privilege. 4 RFC 9700 says OAuth access tokens should get the minimum privileges for the use case. 14

Roles, like "admin" and "viewer", are a good start. Larger products need richer rules. Google's Zanzibar, for example, serves hundreds of services from one shared permission model. 12 See Authorization models: RBAC, ABAC and ReBAC.

Section 4 of 8

Trade-offs

OptionRevoke at once?Server lookup per request?Main riskUse it when
Session ID in a cookieYes Delete the session on the server. 7Yes One read from the session store.Cross-site requests. Set SameSite. 7A web app with its own backend. A good default.
Long-lived signed JWTNo It works until exp. 10No Only a signature check.Stolen tokens stay valid.Rarely. Prefer the next row.
Short-lived JWT plus a refresh tokenMostly. The access token dies soon, and you revoke the refresh token.Only when refreshing.More moving parts. Public clients must rotate or bind refresh tokens. 14Mobile apps and APIs used by many services.
Login with OIDC (Google, Okta and others)Depends on the provider and your session.Only at login.Skipping ID token checks. 15Users already have an account elsewhere, or a company wants single sign-on.

Simple rule: for your own web app, use a server session in an HttpOnly, Secure cookie. Use tokens when you truly need them, and keep them short-lived.

Section 5 of 8

At work: how a senior uses this

  • In every review of an endpoint that takes an ID, ask: "Where do we check that this user may access this object?"
  • Put the authorization check in one place, like a policy function or middleware. Do not copy it into each handler.
  • Write a test for each endpoint where user A asks for user B's object. It must fail with 403 or 404.
  • Never write your own password hashing or JWT code. Use a well-known library, and read its defaults.
  • Ask: "If this token leaks, how long does it work, and how do we kill it?"
  • Give services and tokens the smallest scopes that work. Review admin roles every quarter.
Section 6 of 8

With AI

What to ask the agent

"List every API endpoint in this repo that takes an object ID. For each one, show where it checks that the current user may access that object, or say that it does not."

"Write tests where user A tries to read, update and delete user B's orders. Every test must expect 403 or 404."

"Review this login code against the OWASP Password Storage and Session Management cheat sheets. List each gap with the line number."

What to check yourself

  • Passwords use Argon2id, scrypt or bcrypt from a known library. Never MD5, SHA-256 alone or encryption.
  • Every query by ID also filters by the current user or tenant, or calls a permission check first.
  • JWT code checks the signature, exp, iss and aud, and rejects "alg":"none".
  • Session cookies have HttpOnly, Secure and SameSite. A new session ID is created at login.
  • OAuth code uses the authorization code flow with PKCE, not the implicit flow.
  • No secrets, tokens or passwords appear in logs, URLs or test fixtures.
  • AI agents often copy a handler and forget the ownership check. Read each new handler for that line.
Section 7 of 8

Check yourself

1. A user changes /orders/123 to /orders/124 in the URL and sees someone else's order. What is missing?

Show answer

An object-level authorization check that order 124 belongs to this user. The user was logged in. The server never checked that the user may see that exact object. OWASP calls this broken object level authorization.

2. How should a server store user passwords?

Show answer

Hashed with a slow password hashing function, such as Argon2id, with a salt. OWASP says to hash passwords, because hashing is one-way. Encryption can be reversed. Argon2id is OWASP's first choice.

3. Your API issues signed JWTs that are valid for 7 days. A user's laptop is stolen. What is the problem?

Show answer

The token keeps working until it expires, unless you build a denylist or other revocation. The server checks the signature and expiry, not a session store. Short lifetimes and a denylist keyed on the jti and issuer limit the damage.

4. What is the main difference between OAuth 2.0 and OpenID Connect?

Show answer

OAuth gives an app limited access to an API. OpenID Connect adds an ID token that tells the app who the user is. OpenID Connect is an identity layer on top of OAuth 2.0. Its ID token is a JWT about the user's login.

5. Which session cookie attribute stops JavaScript on the page from reading the cookie?

Show answer

HttpOnly MDN says an HttpOnly cookie cannot be read through document.cookie. This limits damage from cross-site scripting.

Your progress is saved only in this browser. Export it to keep it safe.

Was this clear?
Report a mistake (opens GitHub in a new tab)
Section 8 of 8

Go deeper

Show 15 sources and related lessons
  1. U.S. Securities and Exchange Commission, Order in the Matter of First American Financial Corporation, Release No. 92176, 14 June 2021 (opens in a new tab)
    The official findings on the EaglePro flaw, the January 2019 test that found it, and why it stayed unfixed.
  2. U.S. Securities and Exchange Commission, press release 2021-102: SEC charges issuer with cybersecurity disclosure controls failures (opens in a new tab)
    A short summary of the case, the 800 million images and the penalty.
  3. OWASP API Security Top 10 (2023), API1:2023 Broken Object Level Authorization (opens in a new tab)
    The most common API flaw, with attack examples and how to prevent it.
  4. OWASP Cheat Sheet Series, Authorization Cheat Sheet (opens in a new tab)
    Least privilege, deny by default, and checks on every request, on the server.
  5. OWASP Cheat Sheet Series, Password Storage Cheat Sheet (opens in a new tab)
    Hashing versus encryption, salts, and the settings for Argon2id, scrypt, bcrypt and PBKDF2.
  6. OWASP Cheat Sheet Series, Authentication Cheat Sheet (opens in a new tab)
    Password length, breached passwords, generic login errors and multi-factor authentication.
  7. OWASP Cheat Sheet Series, Session Management Cheat Sheet (opens in a new tab)
    Session ID strength, cookie attributes, new IDs after login, timeouts and logout.
  8. MDN Web Docs, Using HTTP cookies (opens in a new tab)
    How browsers send cookies, and what HttpOnly, Secure and SameSite do.
  9. Jones, Bradley and Sakimura, RFC 7519: JSON Web Token (JWT) (IETF, 2015) (opens in a new tab)
    The JWT format, signed versus encrypted tokens, and the exp and jti claims.
  10. OWASP Cheat Sheet Series, JSON Web Token Cheat Sheet (opens in a new tab)
    Common JWT mistakes, such as accepting "none", secrets in the payload and no way to revoke.
  11. Hardt, RFC 6749: The OAuth 2.0 Authorization Framework (IETF, 2012) (opens in a new tab)
    The four OAuth roles and the authorization code grant.
  12. Pang et al., Zanzibar: Google's Consistent, Global Authorization System, USENIX ATC 2019 (opens in a new tab)
    How Google runs one authorization system, with one data model, for hundreds of services.
  13. Sakimura, Bradley and Agarwal, RFC 7636: Proof Key for Code Exchange (PKCE) (IETF, 2015) (opens in a new tab)
    The code interception attack and how a code verifier and challenge stop it.
  14. Lodderstedt, Bradley, Labunets and Fett, RFC 9700: Best Current Practice for OAuth 2.0 Security (IETF, 2025) (opens in a new tab)
    Today's OAuth rules, such as PKCE, exact redirect URIs and no implicit or password grants.
  15. OpenID Foundation, OpenID Connect Core 1.0 (opens in a new tab)
    The ID token, its required claims, and how a client must validate it.

Case studies: Google: Zanzibar: one consistent permission system for all of Google

Related: TLS and secure connections · OWASP Top 10 and secure coding · Authorization models: RBAC, ABAC and ReBAC · Secrets and key management · Enterprise SSO and SCIM · REST API design

Term

See full entry

Jump to a section

  1. 1What broke
  2. 2The idea in simple words
  3. 3How it works
  4. 4Trade-offs
  5. 5At work
  6. 6With AI
  7. 7Check yourself
  8. 8Go deeper