Skip to content

OAuth for directory clients: confidential clients, refresh policy by client type (L-11) - #130

Merged
ryuzdev merged 2 commits into
mainfrom
oauth-clients
Nov 9, 2026
Merged

ryuzdev merged 2 commits into
mainfrom
oauth-clients

Conversation

@ryuzdev

@ryuzdev ryuzdev commented Nov 9, 2026

Copy link
Copy Markdown
Member

L-11 (owner decision D5: split by standard OAuth client type, not by platform).

Why:

  • ChatGPT and Claude register from shared provider egress, so the 20/h-per-IP DCR cap was effectively global per provider.
  • Gemini requires persistent linking (Google's OAuth guide): "avoid rotating the Refresh Token … return the exact same Refresh Token … and extend its expiration date". Today every refresh rotates and a reuse revokes the grant, which also breaks clients that retry.

Changes:

  • DCR:
    • accepts client_secret_post/client_secret_basic, issuing an outer_cs_ secret; only its sha256 is stored, in oauthClient.clientSecret, and the 201 is no-store;
    • AS metadata advertises ["none","client_secret_post","client_secret_basic"];
    • unknown methods fall back to none; CIMD and existing rows stay public.
  • Limits: DCR 120/h per IP plus 300/h global; /oauth/authorize GET 120/h per IP (429 with retry-after, no request row).
  • Token endpoint: confidential clients authenticate with Basic (rsplit_once plus form decoding) or post, compared in constant time on the hash. This happens before a code is claimed or a refresh row is touched, so a wrong secret burns nothing: 401 invalid_client, plus a Basic challenge when Basic was used.
  • Refresh:
    • Public clients rotate, with a 30 s replay grace (identical pair, from the existing rotationReplay* columns). A concurrent loser replays instead of revoking. Uses BEGIN IMMEDIATE.
    • Confidential clients get non-rotating, sliding tokens: same refresh token, expiresAt extended, scopes narrowed on the row. No reuse detection (accepted D5 tradeoff; controls are the 90-day idle expiry and revoke).
  • Consent copy: names reads, app and account deletion, secrets, keys, sharing and domains, and third-party email. It says the grant cannot change the plan or pay, and "Stay signed in" appears only with offline_access.
  • outer oauth-client add --name … --redirect-uri … [--auth …]: a confidential client for consoles that take a client ID and secret (Gemini's Play Console offers this when DCR isn't used). Rows are verified=1 and exempt from the stale-DCR prune.
  • No migration (reuses Better Auth columns). percent-encoding is a new direct dependency (already in the lock).

Departs from spec §6.1 ("DCR: public clients only", "refresh rotated on every use") per D5; the spec gets updated in the vault.

Tests: 8 new and 8 updated (see the commit). The concurrency tests passed 12 repeated runs.

Smoke on a real outer serve, 13/13 passing:

  • metadata;
  • confidential DCR with the secret and no-store;
  • consent copy;
  • a wrong secret → 401 plus a Basic challenge, after which the same code still exchanges with Basic;
  • the token works on /mcp;
  • two confidential refreshes return the same refresh token, and refresh without the secret → 401;
  • public DCR has no secret; public refresh rotates; a retry inside the grace returns a byte-identical pair; the rotated token works.

@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 34 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7cb16a1c-2b4c-44e0-8dc8-3aed7617bd49
Commits

Reviewing files that changed from the base of the PR and between 69be042 and 88196f7.

Files ignored due to path filters: 1

  • Cargo.lock is excluded by !**/*.lock
Files selected for processing: 9

  • crates/outer/Cargo.toml
  • crates/outer/src/auth/cimd.rs
  • crates/outer/src/auth/oauth.rs
  • crates/outer/src/auth/pages.rs
  • crates/outer/src/auth/tests.rs
  • crates/outer/src/auth/tokens.rs
  • crates/outer/src/main.rs
  • web/docs/(legal)/privacy.mdx
  • web/docs/get-started/sign-in.mdx
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…client type (L-11)

ChatGPT and Claude register from shared provider egress, so the 20/h
per-IP DCR cap was effectively global per provider. Gemini needs
persistent linking (the same refresh token back, expiry extended), and
every refresh rotated with reuse revoking the grant, which also broke
retrying clients. D5: split by standard OAuth client type.

- DCR accepts client_secret_post/basic: an outer_cs_ secret, sha256 in
  oauthClient.clientSecret, returned once with no-store. AS metadata
  advertises the methods. CIMD and NULL-secret rows stay public.
- Limits: DCR 120/h per IP + 300/h global; /oauth/authorize GET 120/h
  per IP (429, no request row).
- /oauth/token authenticates confidential clients (Basic or post,
  constant-time on the hash) before claiming a code or touching a
  refresh row: a wrong secret burns nothing.
- Public refresh rotates with a 30 s replay grace (identical pair, the
  concurrent loser replays instead of revoking; BEGIN IMMEDIATE).
  Confidential refresh is non-rotating and sliding, narrowing scopes.
- Consent names what the grant can do and that it cannot touch billing.
- outer oauth-client add registers a confidential client for consoles
  that take a client ID and secret (e.g. Gemini's Play Console).

No migration: reuses Better Auth's clientSecret, tokenEndpointAuthMethod
and rotationReplay* columns.
@ryuzdev

ryuzdev commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

Security review (independent)

Verdict: mergeable. Client authentication, ordering and the refresh state machine are correct.

Verified:

  • Basic parsing: case-insensitive, rsplit_once, RFC 6749 form decoding; a form/Basic ID mismatch → 401.
  • Client type is decided only by the client row: clientId is UNIQUE, CIMD wins, an empty secret means public; no request parameter can flip it.
  • Secrets: 32 CSPRNG bytes; only the sha256 is stored, compared with ct_eq; the plaintext appears only in the no-store 201 and is never logged.
  • Ordering: authentication happens before a code is claimed or a refresh row is touched; wrong-client_id semantics are unchanged; PKCE, redirect and resource binding are unchanged.
  • Public rotation: one immediate transaction with a consent re-check; the loser replays instead of revoking.
  • Confidential slide: consent_live is checked in the transaction, scopes are narrowed, the same token is returned.
  • verified is written only by the CLI. It drops the "registered itself" note and exempts the row from the stale prune, nothing else.

Fixed in oauth: cancellation-safe immediate transactions; fail closed on client lookup and DCR insert errors:

  • The manual BEGIN IMMEDIATE on a pooled connection wasn't cancellation-safe; it is now pool.begin_with("BEGIN IMMEDIATE"), whose Drop rolls back.
  • A client-lookup DB error classified a confidential client as public; it is now a 500 (client_lookup_error_fails_closed).
  • A failed DCR insert still returned 201 with a secret; it is now a 500 with no secret (dcr_insert_failure_is_500_and_no_secret).
  • The consent copy now also says the app can see and revoke the user's other connections. The "sign-in codes" wording is gone, consistent with L-07 (merged).

Accepted tradeoffs (D5):

  • The 30 s grace is a replay window for a stolen, already-rotated public refresh token. It never replays for revoked consent.
  • Confidential tokens have no reuse detection; revoke and the 90-day idle expiry are the controls.
  • The global DCR bucket (300/h) can be exhausted to deny new registrations for up to an hour. Per-IP buckets can be dodged within an IPv6 /64.
  • /oauth/revoke is still unauthenticated (pre-existing).

@ryuzdev

ryuzdev commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

CodeRabbit skipped this PR (out of free reviews). Reran the 13-check HTTP smoke on the final commit: all pass. Merging on green CI with the independent security review above.

@ryuzdev
ryuzdev merged commit 853a79d into main Nov 9, 2026
5 checks passed
@ryuzdev
ryuzdev deleted the oauth-clients branch November 9, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant