Skip to content

fix(plugin-auth)!: SSO discovery connects only to addresses that are public at connect time - #35781

Merged
os-zhuang merged 4 commits into
mainfrom
claude/sso-discovery-connect-time-guard
Nov 20, 2026
Merged

os-zhuang merged 4 commits into
mainfrom
claude/sso-discovery-connect-time-guard

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Elon · project thread

Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — no published skill teaches SSO provider registration or sign-in; the rule is written into the hand-written SSO guide in this diff

维护者速读

  • 平台管理员登记或更新企业单点登录身份提供方、员工经单点登录登录时,服务器每次读取身份提供方配置,都只连接到连接那一刻判定为公网的地址;部署受信来源未列出的内网地址一律不连、什么都不发送,其余照旧。
  • 延续上一轮“登记前先检查发现文档主机”的同一条规则:把判定放到连接发生的那一刻,并补上登出开关与登录回调的读取,替部署运维把这条规则收成一处实现。
  • 碰到的是身份提供方放在内网、又没列入受信来源的部署:登记、打开“同时登出公司登录”或单点登录会被拒并说明怎么办;运维把它的来源加入受信来源即可恢复;不改任何已存数据,可直接回滚。
  • 无。

What changes

The rule: SSO discovery connects only to addresses that are public at connect time. Every read plugin-auth has the server make of an identity provider's OpenID Connect configuration is sent through the core outbound-request guard (@objectstack/core/egress, the same guard webhook and flow http requests use): the connection resolves the host, judges every address with the platform's address classes (classifyAddress), and connects to an address it judged, never resolving again. So the address judged is the address connected. A host that is not public is refused and nothing is sent to it; so is a name that does not resolve when the read connects. OS_TRUSTED_ORIGINS (the deployment's configured trusted origins) stays the one way to an identity provider on an internal network; OS_EGRESS_ALLOWED_TARGETS does not open SSO discovery.

The reads it covers: the registration's discovery document (/sso/register, and the Register SSO Provider bridge that re-dispatches there), the sign-out switch's read of that document on register and on update-provider, a sign-in's discovery (/sign-in/sso), and the callback's token, key-set and userinfo reads (/sso/callback/*). The vendor's own update-provider endpoint reads nothing.

  • How the reads reach the guard (sso-discovery-egress.ts, new). @better-auth/sso 1.7.12 takes no fetch and no dispatcher: its reads go through betterFetch, which reads globalThis.fetch when called, and a bare fetch for the key set. So the request routing opens an SSO discovery scope (AsyncLocalStorage, opened with run around the whole vendor request, as the SCIM scope is) for the three endpoint paths that read, and a wrapper over the global fetch sends a read inside that scope through the guard. The wrapper is inert outside a scope, and inside one it judges only a read at an origin the request's provider configuration names; a scope starts naming none. The origins are named where the configuration is read, before anything reads from them: a registration's from its body (issuer, every oidcConfig endpoint, the discovery document, companion origins) by the global before-hook, which reads nothing; a stored provider's as the vendor reads its row, through the auth context's adapter, which a plugin mounted with sso (ssoProviderReadsObserverPlugin) hands the context as an observed view; the sign-out read's by its caller. Every other request in the same request (a datastore or a rate-limit store reached over HTTP, a host's own call), before or after the origins are named, is sent as it was. A context whose adapter is not observed (a later view that does not hand its reads on through the observed one) is answered 503 SERVICE_UNAVAILABLE before the endpoint runs, so nothing is read or sent. The scope store and the wrapper are keyed process-wide (Symbol.for), so a second copy of the module finds both and never wraps the global fetch again; the wrapper keeps the wrapped fetch's own properties. A refused read rejects with the vendor's own DiscoveryError, so every vendor path answers it as its own refusal of a non-public host; the refusal names the host and the rule, never the resolved address (that goes to the server log through the guard's logger).
  • The sign-out read (AuthManager.assertSsoSignOutOfIdpSupported) runs in its own scope, which names the origins of the body's and the stored provider configuration (the one document it reads) and judges a read at them unless the configured trust lists it.
  • The registration's early check (refuseSsoDiscoveryHostNotPublic) now asks the guard's own judgement (judgeUrl, same resolver, same policy) instead of resolving and classifying on its own, so the early check and the connection apply one rule with one implementation. That brings the platform's address classes to it, an address literal included: 168.63.129.16 (the Azure host-platform endpoint, in METADATA_ADDRESSES) is refused there, where the vendor's own predicate admits it. A name that does not resolve at that check is left to the read, as before; the connection then refuses it and sends nothing.
  • One answer for a registration. A registration whose discovery read is refused when it connects is answered 400 VALIDATION_FAILED on issuer / oidcConfig.discoveryEndpoint, the same answer the early check gives (after-hook explainSsoDiscoveryConnectRefusal, and the sign-out path on register). An update with the switch on is refused on signOutOfIdp; a callback ends on the error page with invalid_provider.
  • @objectstack/core: the guarded fetch's init takes fetch's redirect mode (it already reached undici; the type now says so). The vendor reads with redirect: 'manual' and refuses redirects itself.
  • AuthManagerOptions.ssoDiscoveryEgress (optional): the guard to send through; absent, the real one is built once per manager with the manager's logger. A suite that fakes the identity provider over a stubbed global fetch hands the stand-in in sso-discovery-egress.testkit.ts (it judges with the real policy over node:dns/promises, then hands an admitted read to the stub).
  • Docs: the SSO guide's paragraph on discovery hosts now states the connect-time rule.

Read first (by risk):

  1. packages/plugins/plugin-auth/src/sso-discovery-egress.ts: installFetchWrapper / sendThroughGuard / judges (only named origins are judged), observingSsoProviderReads + ssoProviderReadsObserverPlugin (a stored provider's origins, named from the row the vendor reads), and declareSsoDiscoveryReadsOf (a registration's origins; no read).
  2. packages/plugins/plugin-auth/src/auth-manager-request-routing.ts (the runHandler choice: which endpoint paths open the scope) and auth-manager.ts runSsoDiscoveryEgress (answers a context whose adapter is not observed 503 SERVICE_UNAVAILABLE before the endpoint runs); the observer is mounted in auth-manager-plugin-list.ts.
  3. packages/plugins/plugin-auth/src/auth-manager.ts: assertSsoSignOutOfIdpSupported (the sign-out read's own scope and its register answer).

Tests

  • sso-discovery-connect-time.test.ts (new, 25 cases): a real AuthManager with the real sso() plugin and the real guard (its policy and transport), name resolution as a double, and the ordinary transport (the global fetch) as a double that resolves again at connect and records the address it connects to. The host answers a public address to every check before a read and 127.0.0.1 / 169.254.169.254 / 10.0.0.5 / 168.63.129.16 when the read connects:
    • register: refused 400 VALIDATION_FAILED on issuer, the answer never names the address, nothing connects (the ordinary transport records nothing, the loopback receiver gets nothing), the guard logs one refusal with its class (4 cases);
    • register with the sign-out switch on: the same, on its first read (4 cases);
    • update-provider turning the switch on: refused on signOutOfIdp, row unchanged (1 case);
    • sign-in callback: the token read is refused, the callback redirects with invalid_provider, nothing connects (4 cases);
    • CONTROL: a host whose address is public at connect registers, its document read over the guard's own connection (127.0.0.1 standing in for the public host, as guarded-fetch.test.ts does);
    • CONTROL: an origin OS_TRUSTED_ORIGINS lists is read as before (both reads, nothing judged);
    • CONTROL: a registration whose datastore and rate-limit counter store are reached over the global fetch, both on internal addresses the guard would refuse: their requests are sent through the ordinary transport before the guard's first judgement (the counter store, ahead of the global before-hook), between, and after its discovery read (the provider row's insert); the guard is never asked for either host;
    • CONTROL: the same for a sign-in by email and its callback: the provider lookup's datastore read and the counter store are sent as they were, while the callback's token read is the one read judged, and it is refused;
    • the scope: CONTROL: a read at an origin no provider configuration names is sent as it was, before and after naming, while a named one is judged unless configured-trusted; a provider row the observed adapter answers names its origins (another model's row names none; the view is idempotent and writes nothing onto the adapter); outside a scope the global fetch is the fetch it was, keeping its own properties; a second copy of the module (registry reset) shares the wrapper and the scope: the global fetch is wrapped once across 3 alternating rounds.
    • a context whose adapter is not the observed view (a later plugin rebuilt it as a plain object): /sso/register, /sign-in/sso and /sso/callback/:providerId are each answered 503 SERVICE_UNAVAILABLE before the endpoint runs: no rate-limit consume, no datastore read, no judgement, no connection, the stored row unchanged (3 cases); CONTROL: a later view that hands its reads on through the observed adapter keeps it: the sign-in runs and its callback's token read is judged and refused (1 case);
  • sso-discovery-companion-origins.test.ts: the early-check unit cases take the shared judgement; new case: an address literal the vendor admits (168.63.129.16) is refused by the platform's classes. Its relying party hands the stubbed-fetch stand-in.
  • guarded-fetch.test.ts (core): a manual redirect mode answers the redirect and follows nothing.
Before (base wiring) / after / ablation
BEFORE  plugin-auth wiring at merge base 92ab0564ede (after-hook, before-hook, routing, AuthManager, plugin list, early check), new module + test in place
        sso-discovery-connect-time.test.ts: Tests 16 failed | 5 passed (21)
        failures: registrations answered 200 and stored the provider; the ordinary transport recorded the internal
        address (register, register + switch, update, callback); the public CONTROL and the registration datastore CONTROL
        answered 502 (no guarded transport); the sign-in datastore CONTROL saw no judgement of the token read
        passing: the configured-trust CONTROL and the four scope cases; restored: 6 blobs == HEAD, git diff HEAD empty
AFTER   HEAD 608a01fb65a: Tests 25 passed (25)
ABLATION 1  (HEAD 8b4ca8cf0ad, 21 cases) wrapper hands every read on (installFetchWrapper; anchor 1 -> 0, blob 0e5c2dda20aa -> cc78b532de98)
        Tests 19 failed | 2 passed (21); restored: blob == HEAD (0e5c2dda20aa), git diff HEAD empty
ABLATION 2  (HEAD 8b4ca8cf0ad, 21 cases) the scope judges every read, no origin filter (judges(); anchor 1 -> 0, blob 0e5c2dda20aa -> 48bdf224a512)
        Tests 4 failed | 17 passed (21): both datastore CONTROLs, the scope CONTROL, the adapter-observation case;
        restored: blob == HEAD, git diff HEAD empty
ABLATION 3  HEAD 608a01fb65a: runSsoDiscoveryEgress hands an unobserved context on (auth-manager.ts; anchor 1 -> 0; blob 5d28c23737c7 -> 4796447f4aab)
        Tests 3 failed | 1 passed | 21 skipped (25): the three doors answered 409 / 200 / 302 where 503 is pinned;
        the CONTROL held; restored: blob == HEAD (5d28c23737c7), git diff HEAD empty
Package suites and typecheck
pnpm --filter @objectstack/plugin-auth exec vitest run   VERDICT command-exit 0   Test Files 289 passed (289) · Tests 6110 passed | 10 skipped (6120)   HEAD 608a01fb65a
pnpm --filter @objectstack/plugin-auth typecheck          VERDICT command-exit 0   (tsc, examples, check:test-typecheck OK, debt held)
pnpm --filter @objectstack/core test && typecheck         VERDICT command-exit 0   Test Files 154 passed (154) · Tests 3671 passed (3671)   HEAD 8b4ca8cf0ad; packages/core unchanged since
Derived gate families (local, HEAD 608a01f)
node scripts/pm/dispatch-gates.mjs --commands   109 commands derived from the change set (14 paths vs merge base 92ab0564e)
109 exit 0 (3 of them re-run on the same head after a first-pass exit 3: check:type-check-debt under the verify lock,
    then spec check:skill-examples and check:dual-build-cjs-loads once the re-measure build produced the dists they read)
dispatch-gates --ran (with exit codes): 109 derived, 109 run, 0 NOT-MEASURED, 0 UNRUN
node scripts/check-platform-checklist.mjs --changed-from origin/main   exit 0 (1 anchored file, 18 anchors judged, 0 lost)
Full dogfood battery (HEAD 608a01f)
pnpm --filter '@objectstack/dogfood^...' build   VERDICT command-exit 0 (7m26s)
pnpm --filter @objectstack/dogfood test          VERDICT command-exit 0 · held the lock 38m11s
Test Files 482 passed | 3 skipped (485) · Tests 4094 passed | 68 skipped (4162)

Acceptance notes

  • The sign-in's discovery (/sign-in/sso for a provider stored without endpoints) reads only origins the deployment trusts: the vendor validates that discovery URL and every endpoint it names against the configured trusted origins at sign-in. Those reads stay exempt, as the rule says; the scope still sits under them.
  • The registration's early check stays open on a lookup error (a name that does not resolve there is left to the read); the read's connection is where an unresolved name is refused, and nothing is sent. The register answer for that case is the vendor's 502 discovery_unexpected_error.
  • The guard connects with its own transport, as it does for webhook deliveries and flow http requests: a deployment that sends outbound HTTP through a global dispatcher or an outbound proxy no longer has these reads go through it. An identity provider reachable only that way is listed in OS_TRUSTED_ORIGINS, whose reads are sent through the global fetch as before.
  • The wrapper over the global fetch is installed on the first SSO request, once per process (a process-wide mark every copy of the module reads), and again over a fetch someone set after it; a runtime whose global fetch cannot be replaced refuses the read rather than sending it unjudged.
  • Every adapter read of the auth context passes through the observed view (one extra await and a model check per findOne / findMany); it names origins only for ssoProvider rows inside an SSO scope. The before-hook no longer reads the provider table: the rows that matter are the ones the vendor reads anyway.

Verification

Two minutes: pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2 src/sso-discovery-connect-time.test.ts (after building @objectstack/plugin-auth's dependencies) prints Tests 25 passed (25).

Session: https://claude.ai/code/session_016WV4czt69hUUaG5XcgFNYL

🤖 Generated with Claude Code

…public at connect time

Every read plugin-auth has the server make of an identity provider's
OpenID Connect configuration (a registration's discovery document, the
sign-out switch's read of it on register and update, a sign-in's
discovery, and the callback's token, key-set and userinfo reads) is sent
through the core outbound-request guard, whose connection resolves the
host, judges every address and connects to an address it judged. The
registration's early check of its discovery host now applies the same
judgement and the same address classes. OS_TRUSTED_ORIGINS stays the
one way to an identity provider on an internal network.

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

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 2 package(s): @objectstack/core, @objectstack/plugin-auth, touching 75 documentable anchor(s).

37 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: node scripts/docs-audit/affected-docs.mjs --json 811858c6595421c8b7ca1d05f546b0e11e947eec.

⛔ 14 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails.

What this run could not see
  • 1 anchor(s) matched too much of the corpus to be a work list: VALIDATION_FAILED (literal, 50 pages)
  • 11 name(s) were too generic to anchor anything (single lowercase words)
  • 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 — 50 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 811858c6595421c8b7ca1d05f546b0e11e947eec → packageMentionDocs.

Which tree this was computed on

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

node scripts/docs-audit/affected-docs.mjs --json 811858c6595421c8b7ca1d05f546b0e11e947eec

⚠️ 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 811858c6595421c8b7ca1d05f546b0e11e947eec → 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

security#2 · os-elon-musk · session_016WV4czt69hUUaG5XcgFNYL

Contract-review-claim: session_016WV4czt69hUUaG5XcgFNYL · head 5b98dea · 2026-11-20T07:20Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

security#2 · os-elon-musk · session_016WV4czt69hUUaG5XcgFNYL

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 5b98dea6f390568b34ae979ad61338f5d8365c0e
Local-runs: none
Scope: .changeset/sso-discovery-connect-time.md (declaration lines), packages/core/src/egress/guarded-fetch.ts, packages/core/src/egress/guarded-fetch.test.ts, packages/plugins/plugin-auth/src/sso-discovery-egress.ts, packages/plugins/plugin-auth/src/sso-discovery-egress.testkit.ts, packages/plugins/plugin-auth/src/sso-discovery-connect-time.test.ts, packages/plugins/plugin-auth/src/sso-discovery-companion-origins.ts, packages/plugins/plugin-auth/src/sso-discovery-companion-origins.test.ts, packages/plugins/plugin-auth/src/auth-manager.ts, packages/plugins/plugin-auth/src/auth-manager-request-routing.ts, packages/plugins/plugin-auth/src/auth-manager-before-hook.ts, packages/plugins/plugin-auth/src/auth-manager-after-hook.ts + read, not reviewed: @better-auth/sso 1.7.12 dist/index.mjs, better-call 1.4.4 dist/router.mjs, @better-auth/core 1.7.12 adapter factory, packages/plugins/plugin-auth/src/objectql-adapter.ts, packages/plugins/plugin-auth/src/sso-sign-out-of-idp.ts, packages/drivers/driver-turso/src/turso-driver.ts, packages/drivers/driver-odata/src/transport.ts
Security-touching: yes

Inputs: the PR body and file list, the net diff against merge base ca4ec2a2f1b, the check-runs on this head, the dev evidence quoted in the brief. No card (a security-seat no-card order). Nothing was built or run; the vendor packages were read from their published tarballs at the locked versions. content/docs/permissions/sso.mdx is prose and is the seat's at ACCEPT.

The rule under review: every read plugin-auth has the server make of an identity provider connects only to an address judged public at connect time, by the one judgment (classifyAddress) the early register check also uses; a configured trusted origin is the one way out; reads at other origins and outside the request scope are untouched.

① Derived judgments

  • Register discovery read (/sso/register, and the bridge, which re-dispatches by URL through handleVendorRequest): in scope, origin named from the body, sent through the guard. Right.
  • Early register check (refuseSsoDiscoveryHostNotPublic): now guard.judgeUrl, the same resolver and policy as the connection, an address literal included. One judgment. Right. It newly refuses a literal the vendor predicate admits (168.63.129.16); the changeset says so. Right.
  • Sign-out switch read on register and update-provider: its own scope with targets: 'every' around judgeSignOutOfIdpCapability, which makes the discovery read and nothing else (the stored row is read before the scope opens). Right.
  • Callback token, key-set and userinfo reads: the vendor reads the stored tokenEndpoint / jwksEndpoint / userInfoEndpoint; oidcConfigReadUrls names exactly those members plus the issuer and discovery URL. The key-set read is a bare fetch resolved at call time, so the wrapper sees it. Right.
  • Runtime discovery on sign-in and callback: the vendor admits that discovery URL and every endpoint the document names only on a configured trusted origin (validateDiscoveryUrl, normalizeAndValidateUrl), so those reads fall under the rule's one way out. Right.
  • The configured-trust predicate the scope keeps is bound to the hook's own ctx.context; the body-named origins join a merged copy the vendor endpoint receives, never that object. A body-named origin does not exempt a read. Right.
  • Provider lookup when the request names no provider reads the whole table: the adapter's unbounded ssoProvider read is count-then-read (readEverySsoProviderRowWhenUnbounded), so no provider is left unnamed past row 100. plugin-auth sets neither defaultSSO nor redirectURI. Right.
  • Route match: isSsoDiscoveryEgressPath reads the path betterAuthEndpointPath answers (trailing slashes stripped); the vendor router answers 404 on a trailing-slash or doubled-slash spelling, so no spelling reaches the three endpoints outside the scope. Right.
  • Redirects: the vendor reads with redirect: 'manual', which the guarded fetch now hands to undici; a followed redirect would be judged hop by hop. Right.
  • Refusal shape: the vendor's own DiscoveryError class (one ESM instance), discovery_private_host or discovery_unexpected_error; the text names the host and the origin, never the address. Register answers 400 VALIDATION_FAILED on the naming member from both the before-hook and the after-hook. Right.
  • "Every other request (a database driver over HTTP, a host's own call) passes through untouched" (module docblock, PR body): wrong before the request's origins are named. See M1.

② Semver level

@objectstack/plugin-auth patch, @objectstack/core patch. The diff publishes: one optional AuthManagerOptions member, one optional EgressFetchInit member, and narrowed runtime answers of the SSO doors. Metadata-protocol: none, so the repo rule (AGENTS.md Post-Task Checklist step 3) ships it patch with its BREAKING banner; the banner, the ADR-0087 marker and both declaration lines are present in the changeset and the PR body. The removed SsoHostResolver type and the resolve input are not exported from the package index. Clause-②: no (narrowing) is the right declaration. Level: right. The BREAKING paragraph is incomplete: it names only an identity provider on a non-public address, and M1 moves a second population.

③ Boundary flags

  • The dev's four acceptance notes are answered in ① (runtime discovery; early check open on a lookup error; the guard's own transport; the wrapper's install).
  • SQL push-down: S1.
  • Gates: at this read Check Changeset, Lint · PM dispatch-gates, Spec property liveness, PR-body guards, Governed Surface Queue Guard, Dogfood Regression Gate concluded success; Test Core 1–10, Build Core, Type Check · workspace, Type Check · consumer gates, Test UI, Live E2E UI were still in progress with no conclusion. No gate has concluded failure. The verdict below does not rest on the open ones.
  • Private residuals held by the security seat: R1–R5 — graded in the seat's private notes. R5 is finding M1 below; R1–R4 do not block this PR.

④ Design judgment

M1 (must-fix) — sso-discovery-egress.ts, runInSsoDiscoveryEgressScope + judges + declareSsoDiscoveryReadsOf: the rule says reads at other origins are untouched, and inside the scope they are not until the origins are named. A vendor-endpoint scope starts targets: 'every' with no trust predicate, so every http(s) request made through the global fetch in that request is sent through the guard's public-only policy, whatever its origin. That window covers the vendor router's pre-hook work (rate-limit storage, plugin onRequest) and, on /sign-in/sso and /sso/callback/*, the hook's own adapter.findMany of ssoProvider, which runs before declareSsoDiscoveryReads. Two in-tree callers read the global fetch at call time: driver-turso fetchBoundedBy (turso-driver.ts:1237, every remote request when timeout is set) and driver-odata (transport.ts:124). For a datastore reached that way on an address that is not public (a self-hosted libSQL server on the deployment's network), the provider read is refused with a DiscoveryError, the catch then declares 'every', and every later datastore read of that sign-in or callback is refused too: SSO sign-in stops for that deployment, and its datastore is not an identity provider. On a public address the datastore's requests are re-sent over the guard's transport with the body re-read as text. A request that matches the three paths but never reaches the hook keeps the judge-everything scope for whatever it started. The test until the request names its origins, every read is judged pins a db.internal.example read going through the guard, so this is the design, not a slip; the docblock, the PR body and the changeset's BREAKING paragraph state the opposite. Owed: no read at an origin the request's provider configuration does not name is judged (the hook's own provider read included), a case that drives a real request with a non-provider read made through the global fetch before and after the hook and shows it sent as it was, or the changeset names the second population as a break.

S1 (should-fix) — declareSsoDiscoveryReadsOf: when the request names no providerId (the ordinary /sign-in/sso by email, domain or organization) or names one with no row (/sso/callback/ with an unknown id, an unauthenticated door), the hook reads every ssoProvider row (a count, then the whole table) and parses each oidcConfig in the application, on every such request. /sign-in/sso makes no read the rule covers outside a configured trusted origin, so the materialisation serves nothing there; where it is needed the lookup pushes down (domain, organizationId, or the one row the vendor resolves). No reason is given in the diff (AGENTS.md, Prime Directive 5).

S2 (should-fix) — installFetchWrapper: the install is idempotent against a module-local variable (installedFetch), not against the global. Two copies of the module in one process (the dual build, a module-registry reset) each see the other's wrapper as a foreign fetch and wrap it again, alternately, one layer per request with no bound. A mark on the wrapper itself that every copy can read closes it.

N1 (nit) — judgeSsoDiscoveryUrl attaches a new catch to defaultGuard on every call, and its default guard has no logger.

N2 (nit) — the wrapper is never removed and replaces the global fetch's identity for the life of the process; a runtime that reads own properties of fetch loses them. Inert outside a scope, as stated.

Tried and held, and so not findings: isolation between concurrent requests (the scope is the AsyncLocalStorage store of one request; the wrapper holds no request state); the guard's own send leaving the scope (scopeStore.exit), so a stand-in that hands on to the global fetch is not judged twice; nested scopes on register (the sign-out read records its refusal on its own scope and answers it there); getOrCreateAuth running before the scope opens; an unresolved name (allowed at the early check, refused at the connection, nothing sent); the guard refusing every send where it cannot prove its connector is consulted.

Implemented-by: claude/sso-discovery-connect-time-guard
Reviewed-by: isolated sub-agent of session_016WV4czt69hUUaG5XcgFNYL

VERDICT: FAIL

…ider configuration names

A vendor endpoint's SSO discovery scope now starts naming no origin, so a
request's other reads over the global fetch (a datastore or a rate-limit
store reached over HTTP), before and after its provider configuration is
read, are sent as they were. The origins are named where the configuration
is read: a registration's body by the global before-hook, a stored
provider's row as the vendor reads it through the auth context's adapter
(a view mounted with the sso plugin, so the before-hook makes no provider
read of its own), and the sign-out check's reads by its caller. A context
whose adapter is not observed refuses the request.

The scope store and the wrapper over the global fetch are keyed
process-wide, so a second copy of the module finds both and never wraps the
global fetch again. The wrapper keeps the wrapped fetch's own properties,
and the default guard's failure handler is attached once.

Claude-Session: https://claude.ai/code/session_016WV4czt69hUUaG5XcgFNYL
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

security#2 · os-elon-musk · session_016WV4czt69hUUaG5XcgFNYL

Contract-review-claim: session_016WV4czt69hUUaG5XcgFNYL · head 8b4ca8c · 2026-11-20T09:35Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

security#2 · os-elon-musk · session_016WV4czt69hUUaG5XcgFNYL

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 8b4ca8cf0ad6c68ed11afe1dc73f5b0cc38fa97d
Local-runs: none
Scope: .changeset/sso-discovery-connect-time.md (declaration lines), packages/core/src/egress/guarded-fetch.ts, packages/core/src/egress/guarded-fetch.test.ts, packages/plugins/plugin-auth/src/sso-discovery-egress.ts, packages/plugins/plugin-auth/src/sso-discovery-egress.testkit.ts, packages/plugins/plugin-auth/src/sso-discovery-connect-time.test.ts, packages/plugins/plugin-auth/src/sso-discovery-companion-origins.ts, packages/plugins/plugin-auth/src/sso-discovery-companion-origins.test.ts, packages/plugins/plugin-auth/src/auth-manager.ts, packages/plugins/plugin-auth/src/auth-manager-request-routing.ts, packages/plugins/plugin-auth/src/auth-manager-before-hook.ts, packages/plugins/plugin-auth/src/auth-manager-after-hook.ts, packages/plugins/plugin-auth/src/auth-manager-plugin-list.ts + read, not reviewed: @better-auth/sso 1.7.12 dist/index.mjs, better-auth 1.7.12 dist/context/helpers.mjs and create-context.mjs, @better-auth/core 1.7.12 dist/context/transaction.mjs, packages/plugins/plugin-auth/src/agent-forward-identity-view.ts, packages/plugins/plugin-auth/src/sso-sign-out-of-idp.ts
Security-touching: yes

Delta review of the record on 5b98dea6f39 (FAIL: M1, S1, S2, N1, N2). Read: the fix commit against its first parent, the merge of origin/main for what it did to this PR's own files, and the whole diff against the new merge base 92ab0564ede. No card (a security-seat no-card order). Nothing was built or run; vendor packages were read from their published tarballs at the locked versions. content/docs/permissions/sso.mdx is prose and is the seat's at ACCEPT.

The merge touched two of this PR's files, auth-manager-before-hook.ts and auth-manager-after-hook.ts, with main-side additions only (#35664). declareSsoDiscoveryReadsOf is still the third statement of the before-hook, ahead of every added branch, and the after-hook's two discovery explanations keep their order.

① Derived judgments

  • A scope names no origin when it opens, and only a read at a named origin is judged (judges). So a read at any other origin, before or after naming, is sent as it was. Right, and it is now what the docblock, the PR body and the changeset say.
  • A registration's origins: named from the body by the before-hook, which reads nothing now, ahead of the vendor endpoint. The vendor's register makes one read, the discovery document, at an origin in that set. Right.
  • A stored provider's origins: named as its row is answered. The vendor reads its provider for sign-in and callback through ctx.context.adapter.findOne / findMany on model ssoProvider and through nothing else (resolveOIDCProvider, the /sign-in/sso lookups by provider, organization and domain; the callback's state carries an id, never a URL). The observed view names the row's issuer, discovery URL and four endpoints after the read resolves and before it returns the row, so no read of that provider can precede its naming. Right.
  • The view is the adapter the endpoints hold: plugin init results are assigned onto the auth context in plugin order (runPluginInit), the agent-forward view is mounted earlier and is itself a delegating Proxy, so the context adapter is observer over agent view over the factory adapter. In either order the provider read passes through the observer. Right.
  • The callback's second provider read runs on the transaction adapter (getCurrentAdapter), which the view does not cover. It is made after the token, key-set and userinfo reads, its row is only compared against the accepted reference, and nothing is read from it. Right.
  • Runtime discovery on sign-in and callback still admits its URL and every endpoint the document names only on a configured trusted origin, the rule's one way out. Right.
  • The sign-out read: its scope names the body's and the stored configuration's URLs, which cover the three places judgeSignOutOfIdpCapability takes its discovery URL from (body, stored, the issuer's well-known URL). Right.
  • runSsoDiscoveryEgress refuses the request when the auth context's adapter does not carry the observed mark. Right as far as it goes: it proves the view is mounted, not that the vendor reads through it; what proves that is the callback cases on the real stack. See S3.
  • The configured-trust predicate is still bound to the hook's own context; a body-named origin does not exempt a read. Right.

② Semver level

Unchanged and right: both packages patch, Metadata-protocol: none, the BREAKING banner, the ADR-0087 marker and Clause-②: no (narrowing) in the changeset and the PR body. The fix adds no published surface (sso-discovery-egress.ts is not exported from the package index; the new plugin is mounted internally). The changeset now states that only reads at the origins the provider's configuration names are judged, which is what the tree does; the BREAKING paragraph is complete.

③ Boundary flags

  • SQL push-down: the hook's provider read is gone; the diff adds no read, no id materialisation and no in-app join. The observer reads the rows the vendor already asked for.
  • Gates on this head at this read: 61 check-runs concluded success, 12 skipped, none failed. One Check Changeset run started 09:23Z was still in progress; an earlier run of the same check on this head concluded success. The seat reads its conclusion before it acts.
  • Private residuals held by the security seat: R1–R6 — graded in the seat's private notes; none blocks this PR.

④ Design judgment

M1: closed. The scope starts empty and judges by origin alone; the before-hook reads nothing; the two real-stack CONTROL cases send datastore and counter-store reads on internal addresses through the global fetch before and after the provider read and show them sent as they were, while the token read in the same request is refused.

S1: closed. declareSsoDiscoveryReadsOf no longer reads the provider table.

S2: closed. The scope store and the wrapper mark are process-wide (Symbol.for); a second module copy finds both and does not wrap again, and a case pins it.

N1: closed for the repeated catch; the default guard outside a scope still has no logger (nit, unchanged).

N2: closed. The wrapper carries the wrapped fetch's own properties.

S3 (should-fix) — AuthManager.runSsoDiscoveryEgress: the refusal of a context whose adapter is not observed has no case. Removing the check, or the plugin's mount, leaves a suite that fails only through the callback cases, and nothing pins that the request is refused rather than sent on unjudged. One case that builds a manager whose context adapter lacks the mark and shows the three paths refused would pin it.

N3 (nit) — isSsoProviderModel and oidcConfigReadUrls hold the vendor's model name and member names as literals beside the comment naming @better-auth/sso 1.7.12; the dependency is pinned exactly, and the real-stack callback cases go red if a later version stops reading through this view. A line in the upgrade notes for that dependency would say so where the next upgrader looks.

Tried and held: a provider read that bypasses the view (none in the vendor's sign-in or callback); a read racing its row's naming (the naming is awaited inside the read); a foreign fetch wrapper installed after this one (wrapped once more, the older layer sees an unjudged read and hands it on); concurrent requests (one store per request, no shared request state); nested scopes on register; the merge's added before-hook branches (all after the declaration).

Implemented-by: claude/sso-discovery-connect-time-guard
Reviewed-by: isolated sub-agent of session_016WV4czt69hUUaG5XcgFNYL

VERDICT: PASS

…he observed view is refused

`runSsoDiscoveryEgress` answers a context whose adapter does not hand its
provider reads on through the SSO discovery observer with
`503 SERVICE_UNAVAILABLE` (the standard envelope) before the endpoint runs,
instead of rejecting with a bare error, and logs the reason. A case per
door (register, sign-in, callback) pins that nothing is read, judged or
sent; a CONTROL pins that a later view handing its reads on through the
observed adapter keeps it. The module docblock carries the upgrade note:
the observer keys on the vendor's provider model and member names.

Claude-Session: https://claude.ai/code/session_016WV4czt69hUUaG5XcgFNYL
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

security#2 · os-elon-musk · session_016WV4czt69hUUaG5XcgFNYL

Contract-review-claim: session_016WV4czt69hUUaG5XcgFNYL · head 608a01f · 2026-11-20T11:10Z

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

security#2 · os-elon-musk · session_016WV4czt69hUUaG5XcgFNYL

Contract review

Served-tier: CONTRACT_REVIEW_TIER
Head-sha: 608a01fb65a47542a4570e3f733b1349c6f50391
Local-runs: none
Scope: .changeset/sso-discovery-connect-time.md (declaration lines), packages/core/src/egress/guarded-fetch.ts, packages/core/src/egress/guarded-fetch.test.ts, packages/plugins/plugin-auth/src/sso-discovery-egress.ts, packages/plugins/plugin-auth/src/sso-discovery-egress.testkit.ts, packages/plugins/plugin-auth/src/sso-discovery-connect-time.test.ts, packages/plugins/plugin-auth/src/sso-discovery-companion-origins.ts, packages/plugins/plugin-auth/src/sso-discovery-companion-origins.test.ts, packages/plugins/plugin-auth/src/auth-manager.ts, packages/plugins/plugin-auth/src/auth-manager-request-routing.ts, packages/plugins/plugin-auth/src/auth-manager-before-hook.ts, packages/plugins/plugin-auth/src/auth-manager-after-hook.ts, packages/plugins/plugin-auth/src/auth-manager-plugin-list.ts + none new (the cited code of the earlier records on this PR stands unchanged)
Security-touching: yes

Delta review of the record on 8b4ca8cf0ad (PASS, S3 and N3 open). Read: git diff 8b4ca8cf0ad 608a01fb65a (one commit, three files: auth-manager.ts, sso-discovery-egress.ts, sso-discovery-connect-time.test.ts), the PR body as it stands, the check-runs on this head. The merge base is unchanged (92ab0564ede); no file outside those three moved. No card (a security-seat no-card order). Nothing was built or run.

① Derived judgments

  • runSsoDiscoveryEgress, a context whose adapter does not carry the observed mark: was a thrown bare Error, is now a returned 503 with the envelope success: false, error.code: SERVICE_UNAVAILABLE, and one error line to the server log. Right: the return precedes run, so the vendor handler, its rate limiter, its hooks and its endpoint never start; nothing is read, judged or connected. It refuses, as the thrown error did, and answers in the package's envelope where the throw left the answer to the host.
  • The answer's text names no host, address, adapter or plugin: it says the server cannot judge its reads of an identity provider and that nothing was read or sent. The detail goes to the server log only. Right.
  • The branch is reached only when the shipped mount is broken (the observer is mounted with sso, and the only other adapter view in the package delegates), so no deployment's answers move and the changeset owes it no line. Right. The PR body names the 503 in its read-first list and its test list.
  • The callback door answers the same JSON 503 to a browser, where its ordinary refusals redirect to the error page. Right for a server that cannot serve the door at all; noted, not a finding.
  • The docblock of sso-discovery-egress.ts now carries the upgrade note for the vendor dependency (model and member names the observer keys on). Right.

② Semver level

Unchanged and right: both packages patch, Metadata-protocol: none, BREAKING banner, ADR-0087 marker, Clause-②: no (narrowing) in the changeset and the PR body. The delta publishes nothing new: a private method's refusal changed shape on a branch the shipped configuration does not reach.

③ Boundary flags

  • SQL push-down: the delta adds no read, no id materialisation, no in-app join.
  • Gates on this head at this read: every check-run is completed; 62 concluded success, 12 skipped, none failed (Check Changeset ran twice, both success).
  • Private residuals held by the security seat: R1–R6 — graded in the seat's private notes; none blocks this PR.

④ Design judgment

S3: closed. Three cases, one per door (/sso/register, /sign-in/sso, /sso/callback/:providerId), on a real manager whose context adapter was rebuilt without the mark: each pins status 503, the envelope code, an empty judgement and transport timeline, no refusal logged by the guard, and the stored rows unchanged. Each fails when the check is removed, since the door then runs its endpoint and answers its own status. The CONTROL shows a later view that delegates keeps the mark and the callback's token read is still judged and refused, so the check does not refuse a sound stack.

N3: closed. The upgrade note is in the module docblock in this commit.

N1 (nit) — unchanged: the default guard judgeSsoDiscoveryUrl builds outside a scope has no logger.

No must-fix, no should-fix.

Tried and held on this delta: the 503 path consuming a rate-limit slot or reading the datastore (it returns before the vendor handler); the answer carrying internals (it carries none); the rebuilt-adapter stand-in passing for the wrong reason (a spread of the view drops the mark, which is what the check reads); the CONTROL passing without observation (its refusal is logged by the real guard with the address class).

Implemented-by: claude/sso-discovery-connect-time-guard
Reviewed-by: isolated sub-agent of session_016WV4czt69hUUaG5XcgFNYL

VERDICT: PASS

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 20, 2026 11:40
@objectstack-fleet objectstack-fleet Bot added the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 20, 2026
@os-zhuang
os-zhuang added this pull request to the merge queue Nov 20, 2026
@objectstack-fleet objectstack-fleet Bot removed the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 20, 2026
Merged via the queue into main with commit ecd4b2b Nov 20, 2026
83 checks passed
@os-zhuang
os-zhuang deleted the claude/sso-discovery-connect-time-guard branch November 20, 2026 12:23
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/xl 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.

3 participants