Skip to content

fix(plugin-auth): a kernel without SSO answers 404 again on the SSO discovery endpoints, with no error log - #36072

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-35939-sso-unmounted-404
Nov 21, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-35939-sso-unmounted-404

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Fixes #35939

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:SSO 发现出口作用域现在只在 better-auth 实例真正挂载了 SSO 插件时才打开;没开 SSO 的部署对 /sso/register、/sign-in/sso、/sso/callback/* 重新回 404。
  • 为什么改:上一轮 SSO 出口加固后,作用域只看路径就打开,而它依赖的观察器只随 SSO 挂载,导致所有未开 SSO 的部署(默认形态)在这三个入口回 503 并每次打一行 error 日志;cloud 的 pin 轮因此 3/9 用例红。
  • 风险与回滚:开了 SSO 的部署行为不变(未被观察的适配器仍 503、发现读取仍走连接时守卫);判据读的是实际构建出的插件清单,读不到时按“已挂载”处理,只会多拦不会放行。回滚即还原本 PR 一行条件。
  • 先看:packages/plugins/plugin-auth/src/auth-manager-request-routing.ts(runHandler 那一行条件);packages/plugins/plugin-auth/src/sso-discovery-egress.ts(新判据 mountsSsoEndpoints);packages/plugins/plugin-auth/src/sso-discovery-connect-time.test.ts(新 describe)。
  • 两分钟验证:pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2 src/sso-discovery-connect-time.test.ts,预期 32 个用例全绿,其中新增 6 个“answers 404, and nothing is logged at error level”。
  • 需要你做的:无,席位落地。

What changes

On a kernel that does not mount SSO (the default without OS_SSO_ENABLED or plugins.sso), POST /sso/register, /sign-in/sso and /sso/callback/* answered 503 SERVICE_UNAVAILABLE and logged one error line per request. The discovery-egress scope opened on isSsoDiscoveryEgressPath(path) alone, while ssoProviderReadsObserverPlugin is pushed only inside if (enabled.sso), so runSsoDiscoveryEgress found no observed adapter and refused.

  • sso-discovery-egress.ts: new mountsSsoEndpoints(auth). It reads the built instance's plugin list (auth.options.plugins, the same read implicit-account-linking.ts uses for the composed sso plugin) and answers whether the vendor's sso plugin is mounted. A list it cannot read answers true, so the scope opens.
  • auth-manager-request-routing.ts: the scope opens when the path names a discovery endpoint AND mountsSsoEndpoints(auth) holds. Unmounted: the vendor answers its own 404 and no provider read can happen. Mounted: unchanged. An unobserved adapter is still refused 503 before the endpoint runs.
  • auth-manager.ts: a docblock line on runSsoDiscoveryEgress saying it is reached only when SSO is mounted.

Why the composition and not isSsoWired(): isSsoWired() re-reads OS_SSO_ENABLED at request time, and better-auth is built lazily, so the two can disagree. If they disagree in the "off" direction, a kernel that mounted SSO would serve discovery with its reads unjudged. That fails open. The built plugin list is the composition that answers the request, so it cannot disagree with itself. The new CONTROL case pins this.

Tests

New top-level describe in sso-discovery-connect-time.test.ts (this file already holds the discovery-scope tests):

  • For plugins.sso: false, and for plugins.sso unset with OS_SSO_ENABLED unset: each of POST /sso/register, POST /sign-in/sso and GET /sso/callback/:providerId answers 404. logger.error is never called, and no warn or info line says "SSO request refused" (6 cases).
  • CONTROL: a kernel built with OS_SSO_ENABLED=true, with the env unset after the build and the context adapter rebuilt as a plain object, still answers 503 SERVICE_UNAVAILABLE with one error line.
  • The SSO-on refusal is already pinned by the existing describe "a request whose auth context adapter is not the observed view is refused", which runs all three doors on plugins.sso: true. Those cases stay green, unchanged.

Ablation (one-off, no test file kept): node scripts/ablation-replace.mjs deleted the anchor && mountsSsoEndpoints(auth) (anchor 1 to 0, blob b04539afe0af to 739194970b07). The file then had 6 failed and 26 passed: the 6 new 404 cases went red with expected 503 to be 404, and the existing 503 pins and the CONTROL stayed green. The restore matched the HEAD blob and git diff HEAD was empty. A first attempt used --replacement with a substring of the anchor. The tool refused it (replacement count could not rise), so it was a no-op and the test never ran.

Acceptance notes

  • Before the fix, at commit a776f67 (test only), the new file section had 6 failed and 1 passed (the CONTROL). The response body was the card's exact 503 message.
  • check:dual-build-cjs-loads exited 3 (PREREQUISITE NOT MET: it needs every package's dist/, and this container has no room for a full build). NOT MEASURED locally; the PR's Lint & Repo Gates run carries it.
  • test:repo was not run locally. The diff touches no file in that project; Test Core carries it.

Verification

All readings were taken at head 1f505ba unless noted.

plugin-auth tests and typecheck
  • pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2 (at 3f7ec3b; the later commit adds only the changeset): Test Files 291 passed (291), Tests 6184 passed and 10 skipped (6194), exit 0.
  • pnpm --filter @objectstack/plugin-auth build && pnpm --filter @objectstack/plugin-auth typecheck: exit 0. check:test-typecheck: OK, 10 files / 71 errors / 23 pinned signatures held in the ledger, unchanged.
Derived gate families (dispatch-gates --commands, 76)
  • 75 exit 0. pnpm check:dual-build-cjs-loads exit 3 (PREREQUISITE NOT MET).
  • dispatch-gates --ran with exit codes recorded: 76 derived families accounted for, 75 run, 1 NOT-MEASURED (derived from the recorded exit 3), 0 UNRUN.

Generated by Claude Code

…scovery endpoints

Claude-Session: https://claude.ai/code/session_01Q4EjjPP1zuWBNq3nBXVei9
Co-authored-by: Claude <noreply@anthropic.com>
…nstance mounts SSO

A kernel without SSO answered 503 SERVICE_UNAVAILABLE and logged an error on
/sso/register, /sign-in/sso and /sso/callback/* because the scope opened on
the path alone while its adapter observer mounts only with SSO. The scope now
opens when the path names a discovery endpoint AND the built auth instance
mounts the vendor's sso plugin, so an unmounted kernel answers the vendor's
404 again and a mounted one is judged exactly as before.

Claude-Session: https://claude.ai/code/session_01Q4EjjPP1zuWBNq3nBXVei9
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/m 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 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

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

3 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 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 top-level function))

⛔ 3 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/v18/18-4.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
  • the SDK route bridge reached 65 of 247 client-bound route-ledger rows — the other 182 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 182: 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; 123 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 — 21 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 615d99542a404ba2fd5e8f3d9840d07550a16254 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 25384849e56fda82b4d239c7fbfd4d6b13c7cd05 — the merge of head 1f505ba720c776fa93ebf1a57a35e53bba3372cc into base 615d99542a404ba2fd5e8f3d9840d07550a16254, 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 25384849e56fda82b4d239c7fbfd4d6b13c7cd05 && git checkout 25384849e56fda82b4d239c7fbfd4d6b13c7cd05
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 615d99542a404ba2fd5e8f3d9840d07550a16254 1f505ba720c776fa93ebf1a57a35e53bba3372cc && git checkout -B drift-repro 615d99542a404ba2fd5e8f3d9840d07550a16254 && git merge --no-ff 1f505ba720c776fa93ebf1a57a35e53bba3372cc

node scripts/docs-audit/affected-docs.mjs --json 615d99542a404ba2fd5e8f3d9840d07550a16254

⚠️ 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 615d99542a404ba2fd5e8f3d9840d07550a16254 → 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

repo:cloud#5 · hotlong · session_01Q4EjjPP1zuWBNq3nBXVei9

ACCEPT 2026-11-21T12:45Z · head 1f505ba720c7 · Fixes #35939

The seat read the diff: 5 files, +106 −4, all in packages/plugins/plugin-auth/src plus a changeset.

  • Shape. handleRequest opens the SSO discovery-egress scope only when the path matches AND mountsSsoEndpoints(auth) holds. That function reads the built instance's own plugin list for the vendor sso plugin, not the request-time env re-read, which can disagree with the lazy build. An unreadable list answers true, so the scope opens and it fails closed. With SSO mounted, nothing changes: an unobserved adapter is still answered 503. This keeps PR fix(plugin-auth)!: SSO discovery connects only to addresses that are public at connect time #35781's protection whole.
  • Premise measured. At the test-only commit, the 6 new cases (2 compositions × 3 doors) were red with expected 503 to be 404. After the fix all 6 answer 404, with no error log and no refusal line. The CONTROL is built with SSO, has its env unset afterwards and its adapter unobserved: it still answers 503. The existing SSO-on 503 pins stay green, and that also proves the plugin id sso matches the mounted vendor plugin. Ablation: deleting && mountsSsoEndpoints(auth) turns exactly the 6 cases red, and the restore was byte-equal.
  • Gates. The package ran 6184 tests and all passed. dispatch-gates derived 76 commands: 75 exited 0, and check:dual-build-cjs-loads is NOT MEASURED locally because the disk is short. CI covers it: every check-run on 1f505ba720c7 is green or a skip by design.
  • Accepted deviations. None beyond the NOT MEASURED gate above, which CI covers.
  • Out of scope. None.
  • Landing. The surface is not governed, the PR is +106/−4, and there is no ! and no narrowing arm. The seat lands it: ready, then auto-merge.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 21, 2026 12:45
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 21, 2026
Merged via the queue into main with commit 0e91213 Nov 21, 2026
54 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-35939-sso-unmounted-404 branch November 21, 2026 13:15
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/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugin-auth: a kernel without SSO answers 503 and logs an error on /sso/register, /sign-in/sso and /sso/callback/* (was 404) since #35781

2 participants