Authorization Code + PKCE flow, JWT signature verification, Strict-Dynamic CSP nonces, and CSRF/XSS mitigation.
\text{code\_challenge} = \text{BASE64URL}\bigl(\text{SHA256}(\text{code\_verifier})\bigr)
Binds the authorization code to the initiating client to prevent authorization code interception.
Prefer `HttpOnly; Secure; SameSite=Lax` session cookies paired with short-lived in-memory bearer tokens to defend against both XSS token exfiltration and cross-site request forgery.
| Storage Mechanism | XSS Token Theft Risk | CSRF Risk | Recommended Mitigation |
|---|---|---|---|
| localStorage / sessionStorage | High (readable by any JS) | None | Never store long-lived refresh tokens here |
| HttpOnly + Secure Cookie | Low (invisible to document.cookie) | Medium | Pair with SameSite=Lax/Strict + Origin check |
| In-Memory JS Closure + HttpOnly Refresh | Minimal | Low | Gold-standard SPA + SSR hybrid pattern |
OAuth 2.0 is a delegated authorization framework (granting an Access Token for APIs), whereas OIDC is an identity layer built on top of OAuth 2.0 that issues a signed JWT ID Token proving who the user is.