Skip to content

fix(plugin-auth): a refused enterprise OIDC sign-in names its cause - #31194

Merged
objectstack-fleet[bot] merged 7 commits into
mainfrom
claude/project-thread-bqq14o
Nov 7, 2026
Merged

objectstack-fleet[bot] merged 7 commits into
mainfrom
claude/project-thread-bqq14o

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by 田騏 · project thread

Fixes #30965

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:企业 OIDC 单点登录被拒时,跳转里的 error_description 从一律的 token_not_verified 改成具体原因(过期、未生效、受众不对、签发方不对、签名密钥未知、签名无效),服务器同时写一行 warn 日志(providerId、协议、原因)。
  • 为什么改:Okta / Entra ID 接入时任何配置错误都显示同一句,管理员无法自查(cloud#3666 实测)。按裁定 D + A + V1 只做 OIDC,SAML 等上游。
  • 风险与回滚:better-auth 自己的日志改走 AuthManager 的 logger(级别不变),没配 logger 时仍走控制台;error= 不变。回滚即还原本 PR,无数据迁移。
  • 先看:sso-oidc-refusal-cause.ts(分类与改写,风险在 runSsoOidcCallbackScope)、auth-manager-request-routing.ts(作用域挂载点)、sso-oidc-refusal-cause.test.ts(端到端用例)。
  • 两分钟验证:pnpm --filter @objectstack/plugin-auth exec vitest run src/sso-oidc-refusal-cause.test.ts,预期 15 个用例全过。
  • 需要你做的:无,席位落地。

What changes

@better-auth/sso 1.7.12 answers every refused ID token on the OIDC callback with one redirect, error=invalid_provider&error_description=token_not_verified. The jose error that names the cause reaches only the vendor's logger (ctx.context.logger.error(error) in handleOIDCCallback). Per the ruling (D + A + V1, comment 6709033929), this PR reads it there and does OIDC only:

  • sso-oidc-refusal-cause.ts (new). createBetterAuthLogSink is the logger plugin-auth now hands betterAuth. runSsoOidcCallbackScope wraps one /sso/callback/:providerId request in an AsyncLocalStorage scope. Inside that scope the sink holds back an error line whose message is a jose error with a classified code (and claim), and records the cause. When the vendor answers the opaque redirect, the scope does three things: it replaces the error_description segment with the cause and leaves every other byte and header as they were, it writes one warn line (providerId, protocol: 'oidc', cause), and it drops the held vendor line, which the warn line replaces. Any other answer releases the held lines unchanged.
  • Closed list, exported as SSO_OIDC_REFUSAL_CAUSES: id_token_expired (ERR_JWT_EXPIRED), id_token_not_yet_valid (ERR_JWT_CLAIM_VALIDATION_FAILED + nbf), id_token_audience_mismatch (+ aud), id_token_issuer_mismatch (+ iss), id_token_signing_key_unknown (ERR_JWKS_NO_MATCHING_KEY), id_token_signature_invalid (ERR_JWS_SIGNATURE_VERIFICATION_FAILED). Anything else keeps token_not_verified and still gets the warn line. Classification never reads message text.
  • Wiring: auth-manager-auth-instance.ts passes the sink; auth-manager-request-routing.ts opens the scope for the per-provider callback path through a new AuthManager.runSsoOidcCallback host member. The shared /sso/callback endpoint is not scoped: it is reached only when sso({ redirectURI }) is set, and plugin-auth does not set it.
  • How existing better-auth log lines move: they now reach the AuthManager logger instead of the console, at the level better-auth chose (error stays error, warn stays warn; no regrading under the "Degradation log levels" rule, because the vendor already graded them). info/debug stay unpublished (the vendor's default level warn is unchanged). With no logger configured they go to the console as before. A message that is an error object is rendered as its name and message, as the vendor's console logger rendered it, so a jose claim error's payload (the token's claims) never reaches a line. Further arguments pass through unchanged. driver-fault-auth-log-carriers.test.ts now reads the library's carriers from both the console and the manager logger, and its assertions are otherwise unchanged.
  • Docs: content/docs/permissions/sso.mdx gains "Why an OIDC sign-in was refused", with one row per cause and what to check.
  • Changeset: @objectstack/plugin-auth patch. Metadata-protocol: none takes patch (AGENTS.md Post-Task Checklist step 3). The new export is a runtime constant, not an authorable key.

Not here: SAML (the vendor discards that cause inside a bare catch, and it goes to a follow-up card upstream-first), packages/spec, ADR-0112. The values are lowercase error_description tokens in the vendor's dialect for that slot, not ledger codes (ruling V1).

Tests

sso-oidc-refusal-cause.test.ts drives a real AuthManager with the real sso() plugin through /sign-in/sso → /sso/callback/:providerId. Only the IdP's token and JWKS endpoints are stubbed. The ID tokens are signed in the test with generated RS256 keys, so every refusal comes from the vendor's real verifier.

  • CONTROL: a valid token signs in (302 to callbackURL, session cookie, no refusal line).
  • One case per cause: the redirect carries error=invalid_provider and the cause, there is exactly one warn line { providerId, protocol: 'oidc', cause }, and no vendor error line.
  • Unclassified (azp naming another client): keeps token_not_verified, writes the warn line, and the vendor's diagnosis still reaches the log.
  • No-leak: neither the Location nor any logger channel carries the token, its payload segment, the subject, the email or the name. A known account and an unknown one get identical redirects and lines.
  • Unit: classification by code and claim only, the path scope, a byte-exact rewrite with headers kept, held lines released on other answers, and forwarding outside a scope.
Ablations (each restored, blob == HEAD, `git diff HEAD` empty, via scripts/ablation-replace.mjs)

Run on the 16-case file before the docs-table pin was dropped (heads b73a45f for 1 and 2, 07fe9fc for 3); the per-cause and no-leak cases are unchanged since.

  1. Side channel off (const cause = undefined in the sink): 7 failed / 9 passed (all six per-cause E2E cases and the rewrite unit case).
  2. Sink not handed to betterAuth (the logger: line deleted): 7 failed / 9 passed (six per-cause cases plus the unclassified case). This is the shape a vendor bump that stops passing the error object would take.
  3. Error-message rendering leaks the error's own properties (JSON.stringify({ ...message })): 2 failed / 14 passed, including the held-line no-leak pin.

A first version that also reshaped the vendor's further arguments was measured against driver-fault-auth-log-carriers.test.ts (the error object's cause stopped surviving). The arguments now pass through as written.

Local runs (final head b0a55dc)
  • pnpm --filter @objectstack/plugin-auth test at 07fe9fc (after merging origin/main): Test Files 235 passed (235), Tests 4184 passed, 10 skipped. Since then only a comment move in auth-manager-request-routing.ts and the removal of one test case; the new file reruns 15/15 at b0a55dc.
  • pnpm --filter @objectstack/plugin-auth typecheck: exit 0 (includes check:test-typecheck, debt unchanged).
  • npx eslint --no-inline-config packages/plugins/plugin-auth: exit 0.
  • Derived gates at b0a55dc (node scripts/pm/dispatch-gates.mjs --commands): 95 derived, 95 run, every one :: exit 0; --ran reconciliation: 95 run, 0 NOT-MEASURED, 0 UNRUN. Three gates first answered exit 3 for missing prerequisites (check-plugin-teardown-shape --self-test on a shallow clone, check:skill-examples and check:dual-build-cjs-loads without a full build); fixed by fetching the fixture commit and a full pnpm build (119/119), then rerun green.
  • A first gate pass flagged check:cross-package-test-inputs: a docs-table pin read content/docs/permissions/sso.mdx from the plugin-auth test. That pin was dropped rather than widening the package's declared inputs.

Acceptance notes

  • The cloud#3666 it.todo cases for OIDC (wrong audience, expired token, foreign issuer, retired key) can go live against this behaviour; the cloud repo is not edited here. The SAML todos stay todo until the follow-up card lands.
  • The mechanism depends on the vendor handing its logger the jose error object. Ablation 2 shows the per-cause tests go red if that stops, so a bump cannot silently fall back.
  • The docs table and SSO_OIDC_REFUSAL_CAUSES are kept equal by hand: a pin would read outside the package, which check:cross-package-test-inputs requires declaring in scripts/cross-package-test-inputs.mjs and turbo.json, outside this card's file surface.

Verification

Human Minimum: 1 n/a (no spec), 2 yes, 3 yes, 4 yes, 5 yes, 6 n/a, 7 yes, 8 yes.

🤖 Generated with Claude Code


Generated by Claude Code

@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/plugin-auth, touching 42 documentable anchor(s).

4 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/kernel/contracts/auth-service.mdx (via AuthManager (symbol, a top-level class), handleRequest (symbol, a method of class AuthManager; a top-level function))
  • content/docs/kernel/services-checklist.mdx (via AuthManager (symbol, a top-level class))
  • content/docs/permissions/authentication.mdx (via AuthManager (symbol, a top-level class), handleRequest (symbol, a method of class AuthManager; a top-level function))
  • content/docs/permissions/sso.mdx (via SSO_OIDC_REFUSAL_CAUSES (symbol, a top-level const object), id_token_audience_mismatch (literal, a string literal in SSO_OIDC_REFUSAL_CAUSES; a string literal in classifySsoOidcIdTokenError), id_token_expired (literal, a string literal in SSO_OIDC_REFUSAL_CAUSES; a string literal in classifySsoOidcIdTokenError), id_token_issuer_mismatch (literal, a string literal in SSO_OIDC_REFUSAL_CAUSES; a string literal in classifySsoOidcIdTokenError), id_token_not_yet_valid (literal, a string literal in SSO_OIDC_REFUSAL_CAUSES; a string literal in classifySsoOidcIdTokenError), id_token_signature_invalid (literal, a string literal in SSO_OIDC_REFUSAL_CAUSES; a string literal in classifySsoOidcIdTokenError), id_token_signing_key_unknown (literal, a string literal in SSO_OIDC_REFUSAL_CAUSES; a string literal in classifySsoOidcIdTokenError), invalid_provider (literal, a string literal in OPAQUE_REFUSAL_ERROR), token_not_verified (literal, a string literal in SSO_OIDC_UNCLASSIFIED_REFUSAL))

⛔ 2 release-owned page(s) also name something this change touched. These are read-only:

  • content/docs/releases/v18/18-2.mdx (via AuthManager (symbol, a top-level class))
  • content/docs/releases/v18/18-3.mdx (via AuthManager (symbol, a top-level class))

content/docs/releases/ is RELEASE-OWNED (AGENTS.md "Documentation Guardrails"): release
notes are written centrally at release time, and a code PR that edits them is the exact PR
that guardrail exists to stop. They are still audited — read-only. If one of them is actually
wrong, file an issue or open a dedicated docs-only PR; do not edit it here.

What this run could not see
  • 5 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 63 of 226 client-bound route-ledger rows — the other 163 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 163: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 104 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 22 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 8acbfab9b4d9c0f6df84d4f350b364fe5eb8d4fc → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 4cfdff44e564421d9e06d0113664221f47934be5 — the merge of head b0a55dc3cee8b9b252f0d834b89ba2da585d4608 into base 8acbfab9b4d9c0f6df84d4f350b364fe5eb8d4fc, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 4cfdff44e564421d9e06d0113664221f47934be5 && git checkout 4cfdff44e564421d9e06d0113664221f47934be5
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 8acbfab9b4d9c0f6df84d4f350b364fe5eb8d4fc b0a55dc3cee8b9b252f0d834b89ba2da585d4608 && git checkout -B drift-repro 8acbfab9b4d9c0f6df84d4f350b364fe5eb8d4fc && git merge --no-ff b0a55dc3cee8b9b252f0d834b89ba2da585d4608

node scripts/docs-audit/affected-docs.mjs --json 8acbfab9b4d9c0f6df84d4f350b364fe5eb8d4fc

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs 8acbfab9b4d9c0f6df84d4f350b364fe5eb8d4fc → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#3 · marchtian · session_017ihL2dFb2QdZEHEJ83cR2B

维护者速读

  • 改了什么: 企业 OIDC 单点登录被拒时,跳转里的 error_description 改为具体原因,共六种:过期、尚未生效、受众不对、签发方不对、签名密钥未知、签名无效。服务器同时写一行 warn 日志,内容是供应商 id、协议、原因。error= 不变。
  • 为什么改: 按你选的 D + A + V1。管理员接 Okta / Entra 配错时,可以自己看出错在哪一项。SAML 等上游修复(plugin-auth SSO: SAML refusals name their cause (expiry, issuer, signature, signing key) once @better-auth/sso keeps samlify's error #31168)。
  • 风险与回滚: better-auth 自己的日志从控制台改走平台 logger,级别不变。错误对象只打印名称和消息,令牌的 claims 不会进日志,比原来更安全。回滚即 revert,没有数据迁移。
  • 先看: sso-oidc-refusal-cause.ts 的 runSsoOidcCallbackScope。
  • 两分钟验证: 见 PR 正文同名行。
  • 需要你做的: 无,席位落地(非受管面,不涉及 spec/skills/ADR,按新规无需 Fable 复核)。
  • 席位意见: ACCEPT。

席位核对

ACCEPT · Head-sha: b0a55dc3cee8b9b252f0d834b89ba2da585d4608 · 2026-11-07T17:26Z

  1. Shape: draft → main, Fixes #30965. Clause-②: no / Metadata-protocol: none per the ruling's V1: no ADR-0112 vocabulary change and no packages/spec edit. The claim's provisional yes (widening) was corrected in ruling comment 6709033929. 9 files: plugin-auth src, its tests, content/docs/permissions/sso.mdx, and the changeset. Declared deviations, accepted: the PR attribution line links the card thread instead of the seat thread (cosmetic); a docs-list pin dropped for the cross-package-input gate; driver-fault-auth-log-carriers.test.ts now also reads the [better-auth] lines on the manager logger, with assertions otherwise unchanged. check-governed-merges --pr 31194: NOT governed, +766 / −7.
  2. Premise measured first, as the addendum required: betterAuth({ logger: { log } }) receives the jose error object from handleOIDCCallback's ctx.context.logger.error(error) on the installed @better-auth/core 1.7.12 (report 6710344068). The premise held, so there was no fork.
  3. Gates (check-runs at this head): 50 runs, 38 success, 12 skipped, 0 failure, 0 pending; mergeable clean. Dev's local reading: derived gates 95/95 exit 0; plugin-auth 4184 passed / 10 skipped; three ablation pairs went red and then green again.
  4. Accepted, read in the diff:
    • Classification reads the jose code and claim only, never message text. The six-token list is exported as const.
    • The AsyncLocalStorage scope opens only for /sso/callback/:providerId. The rewrite touches only the error_description=token_not_verified segment, and only when the answer is that exact opaque redirect. Every other answer releases the held vendor lines unchanged, and a throw releases them too.
    • The warn line carries providerId, protocol and cause.
    • Forwarded vendor lines render an Error as name: message, so a claim error's payload (the token's claims) never reaches a log line. That narrows what the vendor's console logger printed before. No level is regraded; info/debug stay unpublished at the vendor's default level.
    • The refusal happens before any user lookup, so the answer is the same for every account.
  5. Out of scope: SAML is plugin-auth SSO: SAML refusals name their cause (expiry, issuer, signature, signing key) once @better-auth/sso keeps samlify's error #31168 (awaiting the maintainer's upstream submission). Skills-docs: n/a (docs page updated here).
  6. Landing: seat lands it (pr_ready + automerge_enable via the relay). On MERGED it checks that plugin-auth SSO: every OIDC and SAML refusal answers one opaque error (token_not_verified / Invalid SAML response), so an admin cannot tell expiry, audience, issuer or key apart #30965 closed, removes pm:dispatched, and releases the serial pair plugin-auth SSO: expose the operator knobs Enterprise SSO needs — IdP-initiated sign-in, IdP group to role / permission set, and refusing unknown users instead of JIT #30967 → plugin-auth SSO: a SAML account_not_linked refusal redirects to the success callbackURL and ignores errorCallbackURL (OIDC honours it) #30966.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 7, 2026 17:26
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 7, 2026 17:26
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 30002df Nov 7, 2026
51 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-bqq14o branch November 7, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

2 participants