Repository navigation
fix(plugin-auth): a refused enterprise OIDC sign-in names its cause - #31194
Conversation
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2dEm9wh1JnKi42YPDL
…ause Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2dEm9wh1JnKi42YPDL
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2dEm9wh1JnKi42YPDL
…d the manager logger Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2dEm9wh1JnKi42YPDL
…CIM note Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2dEm9wh1JnKi42YPDL
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2dEm9wh1JnKi42YPDL
📓 Docs Drift CheckThis PR changes 1 package(s): 4 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 2 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 22 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # 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
|
|
domain:server#3 · marchtian · session_017ihL2dFb2QdZEHEJ83cR2B 维护者速读
席位核对ACCEPT · Head-sha:
|
Requested by 田騏 · project thread
Fixes #30965
Clause-②: no
Metadata-protocol: none
维护者速读
error_description从一律的token_not_verified改成具体原因(过期、未生效、受众不对、签发方不对、签名密钥未知、签名无效),服务器同时写一行 warn 日志(providerId、协议、原因)。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/sso1.7.12 answers every refused ID token on the OIDC callback with one redirect,error=invalid_provider&error_description=token_not_verified. Thejoseerror that names the cause reaches only the vendor's logger (ctx.context.logger.error(error)inhandleOIDCCallback). Per the ruling (D + A + V1, comment 6709033929), this PR reads it there and does OIDC only:sso-oidc-refusal-cause.ts(new).createBetterAuthLogSinkis theloggerplugin-auth now handsbetterAuth.runSsoOidcCallbackScopewraps one/sso/callback/:providerIdrequest in anAsyncLocalStoragescope. Inside that scope the sink holds back anerrorline whose message is ajoseerror with a classifiedcode(andclaim), and records the cause. When the vendor answers the opaque redirect, the scope does three things: it replaces theerror_descriptionsegment with the cause and leaves every other byte and header as they were, it writes onewarnline (providerId,protocol: 'oidc',cause), and it drops the held vendor line, which the warn line replaces. Any other answer releases the held lines unchanged.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 keepstoken_not_verifiedand still gets the warn line. Classification never reads message text.auth-manager-auth-instance.tspasses the sink;auth-manager-request-routing.tsopens the scope for the per-provider callback path through a newAuthManager.runSsoOidcCallbackhost member. The shared/sso/callbackendpoint is not scoped: it is reached only whensso({ redirectURI })is set, and plugin-auth does not set it.AuthManagerlogger instead of the console, at the level better-auth chose (errorstayserror,warnstayswarn; no regrading under the "Degradation log levels" rule, because the vendor already graded them).info/debugstay unpublished (the vendor's default levelwarnis 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 ajoseclaim error'spayload(the token's claims) never reaches a line. Further arguments pass through unchanged.driver-fault-auth-log-carriers.test.tsnow reads the library's carriers from both the console and the manager logger, and its assertions are otherwise unchanged.content/docs/permissions/sso.mdxgains "Why an OIDC sign-in was refused", with one row per cause and what to check.@objectstack/plugin-authpatch.Metadata-protocol: nonetakespatch(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 lowercaseerror_descriptiontokens in the vendor's dialect for that slot, not ledger codes (ruling V1).Tests
sso-oidc-refusal-cause.test.tsdrives a realAuthManagerwith the realsso()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.callbackURL, session cookie, no refusal line).error=invalid_providerand the cause, there is exactly one warn line{ providerId, protocol: 'oidc', cause }, and no vendorerrorline.azpnaming another client): keepstoken_not_verified, writes the warn line, and the vendor's diagnosis still reaches the log.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.
const cause = undefinedin the sink): 7 failed / 9 passed (all six per-cause E2E cases and the rewrite unit case).betterAuth(thelogger: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.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'scausestopped surviving). The arguments now pass through as written.Local runs (final head b0a55dc)
pnpm --filter @objectstack/plugin-auth testat 07fe9fc (after merging origin/main): Test Files 235 passed (235), Tests 4184 passed, 10 skipped. Since then only a comment move inauth-manager-request-routing.tsand the removal of one test case; the new file reruns 15/15 at b0a55dc.pnpm --filter @objectstack/plugin-auth typecheck: exit 0 (includescheck:test-typecheck, debt unchanged).npx eslint --no-inline-config packages/plugins/plugin-auth: exit 0.node scripts/pm/dispatch-gates.mjs --commands): 95 derived, 95 run, every one:: exit 0;--ranreconciliation: 95 run, 0 NOT-MEASURED, 0 UNRUN. Three gates first answered exit 3 for missing prerequisites (check-plugin-teardown-shape --self-teston a shallow clone,check:skill-examplesandcheck:dual-build-cjs-loadswithout a full build); fixed by fetching the fixture commit and a fullpnpm build(119/119), then rerun green.check:cross-package-test-inputs: a docs-table pin readcontent/docs/permissions/sso.mdxfrom the plugin-auth test. That pin was dropped rather than widening the package's declared inputs.Acceptance notes
it.todocases 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.joseerror object. Ablation 2 shows the per-cause tests go red if that stops, so a bump cannot silently fall back.SSO_OIDC_REFUSAL_CAUSESare kept equal by hand: a pin would read outside the package, whichcheck:cross-package-test-inputsrequires declaring inscripts/cross-package-test-inputs.mjsandturbo.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