Repository navigation
fix(plugin-auth)!: SSO discovery connects only to addresses that are public at connect time - #35781
Conversation
…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>
📓 Docs Drift CheckThis PR changes 2 package(s): 37 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 14 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 50 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 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
|
|
security#2 · os-elon-musk · session_016WV4czt69hUUaG5XcgFNYL Contract-review-claim: session_016WV4czt69hUUaG5XcgFNYL · head 5b98dea · 2026-11-20T07:20Z |
|
security#2 · os-elon-musk · session_016WV4czt69hUUaG5XcgFNYL Contract reviewServed-tier: Inputs: the PR body and file list, the net diff against merge base 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 ( ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgmentM1 (must-fix) — S1 (should-fix) — S2 (should-fix) — N1 (nit) — 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 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 ( Implemented-by: VERDICT: FAIL |
Claude-Session: https://claude.ai/code/session_016WV4czt69hUUaG5XcgFNYL Co-authored-by: Claude <noreply@anthropic.com>
…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>
|
security#2 · os-elon-musk · session_016WV4czt69hUUaG5XcgFNYL Contract-review-claim: session_016WV4czt69hUUaG5XcgFNYL · head 8b4ca8c · 2026-11-20T09:35Z |
|
security#2 · os-elon-musk · session_016WV4czt69hUUaG5XcgFNYL Contract reviewServed-tier: Delta review of the record on The merge touched two of this PR's files, ① Derived judgments
② Semver levelUnchanged and right: both packages ③ Boundary flags
④ Design judgmentM1: 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. S2: closed. The scope store and the wrapper mark are process-wide ( N1: closed for the repeated N2: closed. The wrapper carries the wrapped fetch's own properties. S3 (should-fix) — N3 (nit) — 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: 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>
|
security#2 · os-elon-musk · session_016WV4czt69hUUaG5XcgFNYL Contract-review-claim: session_016WV4czt69hUUaG5XcgFNYL · head 608a01f · 2026-11-20T11:10Z |
|
security#2 · os-elon-musk · session_016WV4czt69hUUaG5XcgFNYL Contract reviewServed-tier: Delta review of the record on ① Derived judgments
② Semver levelUnchanged and right: both packages ③ Boundary flags
④ Design judgmentS3: closed. Three cases, one per door ( N3: closed. The upgrade note is in the module docblock in this commit. N1 (nit) — unchanged: the default guard 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: VERDICT: PASS |
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 flowhttprequests 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_TARGETSdoes 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.sso-discovery-egress.ts, new).@better-auth/sso1.7.12 takes no fetch and no dispatcher: its reads go throughbetterFetch, which readsglobalThis.fetchwhen called, and a barefetchfor the key set. So the request routing opens an SSO discovery scope (AsyncLocalStorage, opened withrunaround 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, everyoidcConfigendpoint, 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 withsso(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 answered503 SERVICE_UNAVAILABLEbefore 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 ownDiscoveryError, 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).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.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, inMETADATA_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.400 VALIDATION_FAILEDonissuer/oidcConfig.discoveryEndpoint, the same answer the early check gives (after-hookexplainSsoDiscoveryConnectRefusal, and the sign-out path on register). An update with the switch on is refused onsignOutOfIdp; a callback ends on the error page withinvalid_provider.@objectstack/core: the guarded fetch's init takes fetch'sredirectmode (it already reached undici; the type now says so). The vendor reads withredirect: '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 insso-discovery-egress.testkit.ts(it judges with the real policy overnode:dns/promises, then hands an admitted read to the stub).Read first (by risk):
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), anddeclareSsoDiscoveryReadsOf(a registration's origins; no read).packages/plugins/plugin-auth/src/auth-manager-request-routing.ts(therunHandlerchoice: which endpoint paths open the scope) andauth-manager.tsrunSsoDiscoveryEgress(answers a context whose adapter is not observed503 SERVICE_UNAVAILABLEbefore the endpoint runs); the observer is mounted inauth-manager-plugin-list.ts.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 realAuthManagerwith the realsso()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 and127.0.0.1/169.254.169.254/10.0.0.5/168.63.129.16when the read connects:400 VALIDATION_FAILEDonissuer, 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);signOutOfIdp, row unchanged (1 case);invalid_provider, nothing connects (4 cases);guarded-fetch.test.tsdoes);OS_TRUSTED_ORIGINSlists is read as before (both reads, nothing judged);/sso/register,/sign-in/ssoand/sso/callback/:providerIdare each answered503 SERVICE_UNAVAILABLEbefore 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
Package suites and typecheck
Derived gate families (local, HEAD 608a01f)
Full dogfood battery (HEAD 608a01f)
Acceptance notes
/sign-in/ssofor 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.502 discovery_unexpected_error.httprequests: 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 inOS_TRUSTED_ORIGINS, whose reads are sent through the global fetch as before.ssoProviderrows 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) printsTests 25 passed (25).Session: https://claude.ai/code/session_016WV4czt69hUUaG5XcgFNYL
🤖 Generated with Claude Code