RFC 9700 — OAuth 2.0 Security Best Current Practice

Adopted as baseline (PR 296). See §OneAuth status(#oneauth-status).

RFC 9700 — OAuth 2.0 Security Best Current Practice

Status: Best Current Practice (BCP 240)
Published: 2025-01
L-tier / T-tier: L0 · always-on (cross-cutting)
OneAuth coverage: Adopted as baseline (PR 296). See §OneAuth status.
See also: LANDSCAPE.md · docs/OAUTH21_ALIGNMENT.md

In one sentence

RFC 9700 catalogs the attacks that OAuth 2.0 deployments kept walking into and
prescribes the defenses; OAuth 2.1 is essentially “6749 with 9700 baked in.”

What problem does it solve?

Without 9700 With 9700
Security guidance scattered across RFC errata, OAuth WG blog posts, conference talks, vendor advisories One normative reference; every footgun has a named defense
Deployments quietly diverge on whether PKCE is mandatory, whether iss is on the redirect, whether refresh tokens rotate One normative checklist; OAuth 2.1 promotes most of it from SHOULD to MUST
New attack surfaces (mix-up, code injection, DPoP downgrade) take years to propagate through implementations The BCP is the canonical place where new attacks and mitigations land

If you read OAuth 2.1 first, 9700 is the why doc. Most “wait, why does 2.1
forbid X?” questions are answered here.

Relatable example

Vignette 1 — the mix-up attack. A user clicks “Sign in with their bank” on
a budgeting app that’s authorised to talk to two banks. A compromised reverse
proxy swaps the discovery doc so the user is sent to Bank A’s /authorize,
but the resulting code is delivered to Bank B’s callback. Bank B’s AS now
hands the budgeting app a token for Bank A’s user. Without iss on the
redirect, the client can’t tell. Defense: RFC 9207 — AS appends
iss=<issuer> to the redirect, client checks it. 9700 §4.4 catalogs the
attack; 9207 names the mitigation.

Vignette 2 — the refresh-token reuse leak. A public mobile client stores a
refresh token in the OS keychain. Malware on the device exfiltrates it. Six
months later the attacker uses it. Defense: 9700 §4.14 — rotate refresh
tokens on every exchange, detect reuse, revoke the entire token family on
reuse. The original user’s next refresh fails, they log back in, and the
attacker’s stolen token is now dead. OneAuth ships this; see grep evidence
below.

Key concepts

  1. Defense-in-depth — Assume any single layer can fail. Bearer + short
    expiry + sender binding + revocation + rotation is the stack, not a menu.
  2. Exact matching everywhere — Redirect URIs (no wildcards, no substring),
    iss comparison (full string), aud on JWTs. Substring/prefix matching is
    the attack surface.
  3. PKCE for all clients, public AND confidential — The 2.0 BCP said “for
    public clients”; 9700 / 2.1 say “everyone.” Closes the authorization-code
    injection attack against confidential clients.
  4. Sender constraint — Bearer tokens are whoever holds them are them.
    Either bind tokens to a sender (mTLS / DPoP) or accept that interception
    == takeover.
  5. Mix-up defense — iss on redirect (RFC 9207) lets the client verify
    which AS issued the code before exchanging it. Required in 2.1.
  6. Don’t put tokens in URLs — Browser history, server logs, Referer
    headers, caches and CDNs all persist URL contents. Use the Authorization
    header, period.
  7. Removed grants are removed for reasons — Implicit (token in URL),
    ROPC (encourages credential-passing through clients). 9700 §2.1.1 and
    §2.4 catalog why each goes.

Wire example

Refresh token rotation with reuse detection — the workhorse defense from
§4.14:

POST /api/token HTTP/1.1
Host: as.example.com
Content-Type: application/x-www-form-urlencoded
Authorization: Basic czZCaGRSa3F0Mzo3RmpmcDBaQnIxS3REUmJuZlZkbUl3

grant_type=refresh_token&refresh_token=RT-abc-old
HTTP/1.1 200 OK
Content-Type: application/json

{
  "access_token": "AT-new",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "RT-new",          ← old RT-abc-old is now single-use-spent
  "scope": "read write"
}

If a second exchange uses RT-abc-old again, the AS detects reuse and revokes
the entire family descended from the original login (every refresh and
access token derived from it). The legitimate user’s next refresh fails →
they log back in fresh → the leaked token line is dead.

Mix-up defense via iss on redirect — the §4.4 mitigation:

HTTP/1.1 302 Found
Location: https://client.example.com/cb?code=Spl...&state=xyz&iss=https://as.example.com
                                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
                                                                  client verifies before
                                                                  POSTing the code

Where it lands on the OAuth abstraction

  • L0 spine. 9700 doesn’t add new endpoints or grants; it constrains the
    ones in 6749. Everything in L1–L8 inherits 9700’s defaults.
  • T-tier: always-on. Not one moment in the flow — every step has a 9700
    paragraph against it. T0 (discovery integrity), T1 (PKCE challenge prep),
    T4 (iss on redirect), T5 (PKCE verify), T6 (no tokens in URLs), T8
    (refresh rotation) all trace back here.
  • 9700 is the document that legitimizes everything in OAuth 2.1 §1. If you
    ever wonder “is this restriction load-bearing?” — chase the cite chain
    through 2.1 → 9700.

OAuth 2.0 status

9700 is a Best Current Practice — Standards-Track-adjacent but distinct.
It applies to OAuth 2.0 deployments and serves as the source-of-truth for
“things you should do beyond what 6749 strictly mandates.” Most defenses are
SHOULD or RECOMMENDED rather than MUST under 9700 itself.

For 2.0 deployments, treating 9700 as “the closest thing to a normative
security checklist” is the right framing. Major IdPs (Google, GitHub, Auth0,
etc.) ship most of 9700’s recommendations by default.

OAuth 2.1 status

OAuth 2.1 promotes most of 9700’s SHOULDs to MUSTs and bakes the defenses
into the core spec. Where 9700 says “you should do PKCE for public clients,”
2.1 says “you must do PKCE for everyone.” Where 9700 says “consider rotating
refresh tokens,” 2.1 says “rotate or use sender constraint.”

If you’re shipping to 2.1 strictness, 9700 is implicitly your minimum. If
you’re shipping to 2.0, 9700 is your discretionary security profile.

Migration path

Not applicable — 9700 is the migration path for 2.0 deployments looking to
adopt 2.1-grade defenses without committing to the 2.1 draft. Read 9700,
implement what it recommends, and you’ll be most of the way to 2.1.

When NOT to use it

Never; it’s a BCP and applies to every OAuth 2.0/2.1 deployment. But:

  • Some defenses have context-specific knobs. Distributed refresh-token
    rotation needs a shared store with atomic CAS (a single in-process map is
    fine for tests, not production). The BCP describes what must happen, not
    how.
  • Sender constraint (DPoP / mTLS) is “SHOULD” in 9700, not MUST. For
    internal service-to-service traffic on a controlled network you may
    reasonably skip it. FAPI 2.0 (L8) promotes it to MUST.
  • Some §4 items only apply to specific deployment shapes (e.g., §4.12 on
    307 redirects matters only if you reverse-proxy /token). Read for what
    your topology actually does.

OneAuth status

OneAuth adopted 9700 as the alignment baseline under PR 296 (issue #140).
The OAuth 2.1 audit table in
docs/OAUTH21_ALIGNMENT.md is the row-by-row
verdict; the table below summarises against the BCP defenses themselves.

9700 defense OneAuth status Where (grep-verified) Notes
PKCE for all auth-code flows (§2.1.1) Compliant AuthorizationHandler.ValidateValues (apiauth/authorize.go) requires code_challenge; authorizationCodeGranter.AuthorizationCodeGrant (apiauth/authorize_granter.go) checks the verifier with core.VerifyPKCE Server-side enforcement landed in PR 297 (/authorize)
PKCE shape (RFC 7636 §4.1, §4.2) Compliant AuthorizationHandler.ValidateValues An S256 code_challenge must be 43 base64url characters, and a code_verifier or plain challenge 43 to 128 unreserved characters (0.1.49)
PKCE method MUST be S256 (§2.1.1) Compliant AuthorizationHandler.ValidateValues rejects anything other than S256 unless AllowPlainPKCE is set plain rejected by default; default omitted is rejected too
Exact redirect URI matching (§2.1.3, §4.1) Compliant AuthorizationHandler.validateRedirectURI (apiauth/authorize.go) against AppStore/RedirectURIValidator, compared with RedirectURIMatches; admin/registrar.go validateRedirectURI at DCR Two-layer check: registration + authorization. An http loopback redirect matches on any port, as RFC 8252 §7.3 requires; scheme, host, path and query still match exactly (0.1.38). With neither an AppStore nor a RedirectURIValidator, /authorize refuses every request unless AllowAnyRedirectURI is set (0.1.49).
HTTPS redirect URIs, RFC 8252 loopback exempt (§2.1.2) Compliant admin/registrar.go validateRedirectURIs, called from Register/UpdateRegistration Loopback (127.0.0.1, ::1, localhost) carved out per RFC 8252 §7.3. Since 0.1.50 DCR also refuses userinfo and a missing https host, and every redirect problem answers invalid_redirect_uri (admin.ErrInvalidRedirectURI).
Implicit grant removed (§2.1.2) Compliant AuthorizationHandler.ValidateValues answers any response_type but code with unsupported_response_type Preserved post PR 297; only code is accepted. The reference server advertises response_types_supported: ["code"] only with code_flow on (0.1.51).
ROPC removed (§2.4) Compliant by default; opt-in retained TokenEndpointHandler.handlePassword (apiauth/token_endpoint.go) answers unsupported_grant_type while OneAuthConfig.PasswordGranter is nil, and always under FAPI2 The library leaves ROPC off unless a deployment wires NewPasswordGranter (issue 294). The reference server wires it, except under fapi2: true, where the grant is refused and left out of metadata.
Bearer tokens NOT in query string (§4.3.2) Compliant by default; opt-in OAuth 2.0 path retained apiauth/middleware.go LegacyQueryParamBearer fallback (default nil) Per capability-gating umbrella #344. See docs/DEMOS.md for the three header-clean WebSocket alternatives.
Refresh-token rotation + reuse detection (§4.14) Compliant RotateRefreshToken in the refresh path of apiauth/token_validator.go → core.ErrTokenReused → RevokeTokenFamily Backend-agnostic; FS, GORM, GAE all implement; exercised by apiauth/auth_test.go reuse subtest. The grant checks the presenting client: the token must belong to the client_id sent, and a confidential owner must authenticate (0.1.41). OneAuthConfig.DisableRefreshTokenRotation turns rotation off, as FAPI 2.0 asks; FAPI2 sets it (0.1.43). GORM rotation is a compare-and-set, and rotation keeps the family’s expiry in every store (0.1.45). On reuse the family’s unexpired access tokens are blacklisted too, with OneAuthConfig.Blacklist (issue 436).
Authorization code reuse (RFC 6749 §4.1.2) Compliant authorizationCodeGranter.refuseReuse / revoke (apiauth/authorize_granter.go); AuthorizationCodeStore.ConsumeAuthorizationCode A redeemed code is kept, marked used, until its access token expires. Presenting it again blacklists that token’s jti (with OneAuthConfig.Blacklist) and revokes the refresh family (0.1.57, issue 429).
iss on authorization-response redirect (§4.4 / RFC 9207) Compliant AuthorizationHandler.SuccessRedirect / ErrorRedirect (apiauth/authorize.go) emit it when EmitIssParameter is true Opt-in in the library (AuthorizeMountConfig.EmitIssParameter). The reference server always sets it with code_flow on and advertises authorization_response_iss_parameter_supported (0.1.51).
Sender-constrained tokens, DPoP (§4.10) Compliant DPoPProofValidator (apiauth/dpop.go) via OneAuthConfig.DPoP; APIMiddleware.DPoP / RequireDPoP RFC 9449 is implemented end to end: token binding (0.1.37), dpop_jkt on /authorize, nonces and client SDK proofs (0.1.38), OneAuthConfig.RequireDPoP (0.1.41), EdDSA proofs and DisableRefreshTokenRotation (0.1.43). See RFC_9449.md.
Sender-constrained tokens, mTLS (§4.10) Gap — RFC 8705 is #335. See RFC_8705.md.
Client authentication, assertion-based (§2.3) Compliant clientAuthenticator.authenticateAssertion (apiauth/client_authenticator.go) client_secret_jwt (issue 159) and private_key_jwt are both supported. Audiences come from r.TLS and r.Host or OneAuthConfig.AcceptedAudiences, never forwarded headers, and the issuer is accepted (0.1.52). Under FAPI2 only PS256 / ES256 / EdDSA assertions pass, with the issuer as a string aud; oneauth can register only ES256 client keys today (0.1.54). See RFC_7523.md.
Authorization request integrity, PAR Compliant PARHandler (apiauth/par.go), mounted by MountAuthorize when AuthorizeMountConfig.PushedStore is set RFC 9126 since 0.1.38. A pushed request issues one code and survives the consent screen (0.1.49); require_pushed_authorization_requests is per client through DCR (0.1.50); the reference server serves PAR with code_flow.par.enabled (0.1.54). See RFC_9126.md.
Authorization request integrity, JAR Gap — RFC 9101 is #338. See RFC_9101.md.
Open redirectors (§4.11) Compliant httpauth.LocalRedirect (httpauth/pagesafety.go) Logout and post-login redirects go only to local paths, and logout is POST (0.1.44).
CSRF on browser forms (§4.7) Compliant httpauth.CSRFMiddleware (httpauth/csrf.go) Unsafe methods are checked against Sec-Fetch-Site and Origin (with TrustedOrigins) before the token, and with SessionID set a token is bound to the session. The reference server binds tokens to the login session (0.1.55).
Credential responses not cached (RFC 6749 §5.1) Compliant noStore (apiauth/no_store.go) and the handlers that set Cache-Control: no-store Every response carrying a secret is no-store: token responses and errors, device responses, DCR, admin read / list / rotate, API-key creation, the authorize redirect and the reset form (0.1.44).

The FAPI 2.0 Security Profile (OneAuthConfig.FAPI2, 0.1.52 and 0.1.54)
turns on the strict end of several rows above at once: DPoP required,
rotation off, private_key_jwt only, no password grant, no public clients,
and PAR-only /authorize. docs/SECURITY_AUDIT.md
walks it requirement by requirement and lists its caveats.

The audit table in docs/OAUTH21_ALIGNMENT.md is the single source of truth
for ROPC and query-param-bearer status; this doc is the BCP-level mapping.
When a row in either updates, update both.

  • RFC 6749 — the spec 9700 patches; you must read 6749 first
  • OAuth 2.1 draft — promotes most of 9700 from SHOULD to MUST
  • RFC 7636 — PKCE; 9700 §2.1.1 says use it
  • RFC 9207 — iss on redirect; 9700 §4.4 names this as the mix-up defense
  • RFC 8252 — Native Apps; the loopback redirect exemption
  • RFC 9449 — DPoP; the 9700 §4.10 sender-constraint path for public clients
  • RFC 8705 — mTLS; the 9700 §4.10 sender-constraint path for confidential clients

Maintenance note. When OAuth 2.1 graduates from draft to RFC, update the
“In one sentence” line and the OAuth 2.1 cross-link. When mTLS (#335) or JAR
(#338) ships, update its row here in the same change as LANDSCAPE.md §6.