Kayavak / The Backend / BE·50 Spring Security and Modern Identity / Deeper
Deeper · The Backend
Spring Security and Modern Identity
The questions the chapter doesn't stop for: why this exists, the model to keep in your head, what changes when an assumption does, how sure we are of each claim, and what's still open. Read it after the chapter; back to the chapter.
Why does this exist?
For years, letting one application use your data on another meant giving it your password. Twitter, Google and others designed OAuth (1.0 in 2007, RFC 5849 in 2010) so you could grant a limited, revocable token instead. OAuth 2.0 (RFC 6749, 2012) simplified it for web and mobile apps, and OpenID Connect (2014) added a standard way to learn who the user is, which OAuth alone never promised. Mobile and browser apps that can't keep secrets got PKCE (RFC 7636, 2015), now recommended for every client.
Passwords themselves improved slowly: storing them hashed with slow, salted algorithms (bcrypt by Niels Provos and David Mazières, 1999; later scrypt and Argon2) limits the damage of a breach. WebAuthn (a W3C Recommendation in 2019) and passkeys replace passwords with public-key credentials that can't be phished. Meanwhile OWASP's 2021 Top 10 put broken access control at number one: most breaches aren't clever cryptography failures but missing checks on who may do what.
The mental model
Try it yourself first: write your own model in the Mental Model Explorer, then compare.
Authentication answers "who are you?"; authorisation answers "may you do this, to this object?". Every request must pass both, and the second must be checked for the specific object, not just the user's role.
| Question | Answer |
|---|---|
| What is it? | Verifying identity and enforcing permissions for every request, with standard protocols for delegated access |
| Problem it solves | Only the right people and programs can read or change each piece of data |
| Parts | Security filter chains, authentication providers, password hashing, sessions or tokens, OAuth 2 and OIDC flows, method and object-level authorisation, CSRF and CORS |
| How it works | Filters authenticate the request into a security context; authorisation rules check it against the route, the method and the object |
| Assumptions | Deny by default; every path through the code reaches a check |
| When they change | An endpoint that checks "is logged in" but not "owns this order" lets any user read any order by changing the id |
| Where it fails | Missing object-level checks, tokens kept too long, misconfigured CORS, secrets in code |
| Related ideas | Frontend security and token storage (The Web Frontend, ch28); cryptography and threat models (Security) |
What if?
What if your API checked roles but not ownership?
Reason it through, then open
Any customer could fetch /orders/1042 belonging to someone else, just by changing the number: an insecure direct
object reference, a form of broken access control. Role checks answer "may customers read orders?"; only an object
check answers "may this customer read this order?". The check belongs in the service or query (where customer_id =
?), so every entry point gets it.
What if passwords were stored with a fast hash like SHA-256?
Reason it through, then open
A stolen database could be attacked offline at billions of guesses per second on GPUs, and most human passwords would fall quickly. Slow, salted, memory-hard functions (bcrypt, scrypt, Argon2) make each guess expensive and stop precomputed tables, which turns a breach from an immediate catastrophe into a slow, partial one.
Where the boundary is
| Aspect | OAuth 2.0 | OpenID Connect |
|---|---|---|
| Answers | What may this client access on the user's behalf? | Who is the user? |
| Main token | Access token (for APIs) | ID token (for the client, about the user) |
| Use for | Calling APIs | Logging users in |
| Common mistake | Using an access token as proof of identity |
How sure are we?
| Claim | How it's known | Where from |
|---|---|---|
| Broken access control is OWASP's top risk (2021) | Measured | OWASP Top 10 2021, from contributed application test data |
| OAuth 2.0 (2012), OIDC (2014), PKCE (2015) | Historical | RFC 6749, OIDC Core 1.0, RFC 7636 |
| Slow password hashes resist offline guessing | Theorem, practically | Cost per guess scales with the work factor |
| Passkeys resist phishing | Model | Credentials are bound to the site's origin; recovery and device sync add new risks |
Still open
Account recovery is the weak point of passkeys and every other strong method; how to recover without reintroducing phishable fallbacks is unsolved in practice.
What would change your mind? If breach reports stopped showing broken access control and started showing mostly cryptographic failures, priorities would flip. They show the opposite.
Recall
What's the difference between authentication and authorisation?
Authentication establishes who you are; authorisation decides what you may do to which object.
Why isn't a role check enough?
It doesn't check that the user may act on this specific object; changing an id would reach other people's data.
What does OpenID Connect add to OAuth 2.0?
A standard ID token telling the client who the user is.
Why hash passwords with bcrypt or Argon2 rather than SHA-256?
They're deliberately slow and salted, so offline guessing is expensive.
Reflect
Be honest with yourself; this stays in your browser. Anything you can't tick yet is what to revisit.