Skip to content

fix(plugin-auth): a refused SAML sign-in lands on the error URL, as OIDC does - #31231

Merged
objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/project-thread-f4lk8u
Nov 7, 2026
Merged

objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/project-thread-f4lk8u

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Leehom · project thread
Fixes #30966

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:SAML 登录被拒时(典型是邮箱属于一个尚未关联该 IdP 的已有账号,account_not_linked),不再跳回「登录成功」页,而是跳到登录时给的 errorCallbackURL;没给就跳到平台登录页,与 OIDC 以及 SAML 其它拒绝一致。响应过大被拒时原来跳到站点根,也一并改为错误页。error=、error_description 原样保留。
  • 为什么改:用户会看到一个看似登录了、其实没登录的页面(cloud#3666 用 Okta / Entra 实测)。原因在上游 @better-auth/sso:账号类拒绝被发往成功地址。
  • 风险与回滚:只改 SAML ACS 拒绝时的跳转目标,不放行任何登录;成功登录、IdP 发起的登录(无 relay state)不受影响。回滚即还原本 PR,无数据迁移。
  • 先看:sso-oidc-refusal-cause.ts 末尾的 SAML 一节(风险在 readSamlAcsLanding 的安全规则与 landSamlRefusal 的成功判定);auth-manager-request-routing.ts(同一作用域挂载点);sso-saml-refusal-landing.test.ts(真实 ACS 端到端)。
  • 两分钟验证:pnpm --filter @objectstack/plugin-auth exec vitest run src/sso-saml-refusal-landing.test.ts,预期 15 个用例全绿(含成功对照与 takeover 落到错误页)。
  • 需要你做的:无,席位落地。

What changes

@better-auth/sso 1.7.12 processSAMLResponse sends nearly every SAML refusal to the flow's error URL (samlErrorRedirectUrl: the sign-in's errorCallbackURL, else onAPIError.errorURL, which plugin-auth points at the Console login page). Two refusals do not:

  1. An account refusal from better-auth's handleOAuthUserInfo comes back as result.error, and the vendor answers ctx.redirect(buildSAMLRedirectUrl(callbackUrl, { error })): the SUCCESS callbackURL with only ?error=. Values: account_not_linked (the takeover case on the card), signup_disabled, unable_to_link_account, unable_to_create_user, email_not_verified, unable_to_create_session.
  2. A response over maxResponseSize is refused before the vendor reads the relay state, so it lands on the provider's fallback candidates. For a provider stored by the Register SAML Provider bridge (whose callbackUrl is the ACS itself) that is the app origin /.

The cause is upstream, so the fix wraps the ACS in plugin-auth at the seam PR #31194 uses for the OIDC callback, as the seat ruled. There is no vendored patch.

  • One scope for both callbacks. auth-manager-request-routing.ts now asks ssoCallbackOf(endpointPath, request), which answers the OIDC callback (unchanged) or a POST to /sso/saml2/sp/acs/:providerId. Both run through the one host member AuthManager.runSsoCallback (renamed from runSsoOidcCallback) and runSsoCallbackScope in sso-oidc-refusal-cause.ts. The OIDC branch calls the existing runSsoOidcCallbackScope unchanged. The file keeps its name and gains a "SAML: where a refusal lands" header section.
  • Where the error URL comes from. The vendor computes samlErrorRedirectUrl from the relay state and offers no hook on it, and it deletes the relay-state row once read. So before the vendor runs, readSamlAcsLanding reads the same row (auth-state:RELAY_STATE) through the vendor's own internalAdapter.findVerificationValue, which does not consume it. It applies the vendor's default (onAPIError.errorURL, else ${baseURL}/error) and the vendor's redirect safety rule (getSafeRedirectCandidate: a same-origin path not starting // or /\, or an absolute URL on the app origin or a trusted origin, never the ACS itself). No relay state, no row, an unreadable row, an unsafe target, or a throw while reading means no landing, and the vendor's answer stands.
  • The rewrite. landSamlRefusal re-bases a redirect whose Location carries error= and is not the success URL onto the error URL, keeping error and error_description as the vendor wrote them. It builds the URL as the vendor's buildSAMLRedirectUrl does: values set on the target, and a relative target kept relative. A refusal already on the error URL comes out byte-identical; status and every other header are kept. error= is never changed (seat ruling).
  • Not here: the SAML refusal causes in error_description (plugin-auth SSO: SAML refusals name their cause (expiry, issuer, signature, signing key) once @better-auth/sso keeps samlify's error #31168, waiting on upstream). Neither field's value changes, so this PR and plugin-auth SSO: SAML refusals name their cause (expiry, issuer, signature, signing key) once @better-auth/sso keeps samlify's error #31168 stay separable. No packages/spec, ADR-0112, or package export change (index.ts still exports only the OIDC cause constants).
  • Docs: content/docs/permissions/sso.mdx "SAML sign-in flow" gains step 5 (where a refusal lands) and names the optional errorCallbackURL.
  • Changeset: @objectstack/plugin-auth patch, .changeset/30966-saml-refusal-lands-on-error-url.md.

Every SAML ACS refusal, and where it lands

Measured with this PR's rig on origin/main 66bf5b4a (before) and on the head (after), sign-in with errorCallbackURL given:

Refusal Before After
account_not_linked (takeover) callbackURL?error=account_not_linked errorCallbackURL?error=account_not_linked
same, no errorCallbackURL callbackURL?error=account_not_linked Console login page ?error=account_not_linked
other handleOAuthUserInfo results (signup_disabled, unable_to_link_account, unable_to_create_user, email_not_verified, unable_to_create_session) callbackURL (same vendor line, read in source) errorCallbackURL (same rule; not driven end to end)
response over maxResponseSize app origin /?error=saml_error&… errorCallbackURL?error=saml_error&…
signature / parse failure (saml_error) errorCallbackURL unchanged
no assertion (saml_no_assertion) errorCallbackURL unchanged
unknown or expired request ID, audience, recipient, replay, invalid_state variants, resolveUser / validateUserInfo refusals (APIError with a code, e.g. plugin-auth's own implicit-link gate) error URL (vendor source; the request-ID case measured) unchanged
relay state the vendor cannot read vendor fallback (no error URL known) unchanged
provider not found (404), unverified domain (401), POST without SAMLResponse (400) JSON answers, not redirects unchanged
IdP-initiated response (no RelayState) vendor candidates unchanged (no relay state to read)

Tests

New packages/plugins/plugin-auth/src/sso-saml-refusal-landing.test.ts, 15 cases.

  • End of the chain: a real AuthManager with the real sso() plugin over the in-memory engine, driven /sign-in/sso → IdP → POST ACS. The IdP is played with the samlify the installed @better-auth/sso resolves (loaded through createRequire from the vendor's own location, so no new dependency). It reads the vendor's SP metadata and AuthnRequest ID and answers a Response signed with an RSA key and a self-signed certificate generated in the test (a small DER builder checked by X509Certificate), so each refusal comes from the vendor's real pipeline.
    • CONTROL: a new account signs in, 302 to callbackURL, session cookie set.
    • Takeover: 302 to errorCallbackURL with error=account_not_linked, no session.
    • Takeover with no errorCallbackURL: the Console login page, the same page the vendor's own saml_error refusal lands on in the same sign-in shape.
    • Takeover with a relative errorCallbackURL: /oops?from=sso&error=account_not_linked.
    • Oversized response: errorCallbackURL, error=saml_error, description kept.
    • Tampered assertion (already on the error URL): unchanged.
  • Units: the path and method scope; reading the landing from a form or JSON body, the default, the absent or unreadable row; the safety rule (untrusted origin, trusted origin, //, /\, the ACS itself, a relative path); the rewrite keeps headers and both params, leaves a success alone even when its own URL carries error=, leaves an already-landed refusal and a non-redirect identical; no landing, or a throw while reading it, leaves the vendor answer.

Red first on origin/main 66bf5b4a (first version of the file, CONTROL + takeover): 1 failed, 1 passed; the takeover case received base: http://localhost:3000/after-sign-in for sign-in-failed.

Ablations (each through scripts/ablation-replace.mjs, restored with blob == HEAD 9e4e9e53 and `git diff HEAD` empty)

The test imports the module from src/ by relative path, so no dist/ rebuild sits between a mutation and its reading.

  1. The scope no longer wraps the SAML ACS (ssoCallbackOf matches method ABLATED-1 instead of POST): 5 failed / 10 passed (the four end-to-end refusal cases and the scope unit).
  2. The safety rule off (readSamlAcsLanding takes the raw error URL): 1 failed / 14 passed ("applies the vendor redirect safety rule").
  3. The success guard off (location === landing.success never true): 1 failed / 14 passed ("leaves a success alone, even one whose own URL carries error=").

Acceptance notes

  • Reading: "as the OIDC callback does" also covers the sign-in with no errorCallbackURL. The OIDC callback then lands on onAPIError.errorURL (the Console login page), and so does every other SAML refusal; this PR sends the account refusals there too instead of to callbackURL. The card's literal "when one is given" case is the first end-to-end refusal test.
  • The landing reads one vendor-internal spelling, the relay-state identifier auth-state:RELAY_STATE (better-auth getAuthStateVerificationIdentifier, not exported). A vendor bump that renames it makes readSamlAcsLanding find no row, and the end-to-end takeover cases go red (ablation 1 is the same shape), so it cannot fall back silently. plugin-auth always runs better-auth with a database, so the relay state is always database-stored (storeStateStrategy is never set here).
  • The safety rule is a copy of the vendor's (getSafeRedirectCandidate and isSafeSAMLRedirectPath are not exported); it only ever narrows: an error URL it refuses leaves the vendor's answer as is.
  • No new log line: the SAML cause log line belongs to plugin-auth SSO: SAML refusals name their cause (expiry, issuer, signature, signing key) once @better-auth/sso keeps samlify's error #31168.
  • Clause-② measured: the only answer that changes is the Location of a refused ACS POST (302 either way). Nothing is admitted, no status, body, error= or error_description changes, and no published type or export changes. So no, as the claim read it.
  • Upstream: the one-line fix would be callbackUrl → errorUrl in that result.error redirect, plus reading the relay state before the size check. Not filed here.

Verification

All local readings are at head ffdd6e0f.

  • pnpm --filter @objectstack/plugin-auth test (after pnpm --filter @objectstack/plugin-auth build, under the verify lock): Test Files 236 passed (236), Tests 4198 passed | 10 skipped (4208).
  • 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 (node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack, 95 families) after a full pnpm build (119 packages, exit 0): 95 derived, 95 run, every one :: exit 0; --ran reconciliation: 95 run, 0 NOT-MEASURED, 0 UNRUN. check-plugin-teardown-shape --self-test ran after fetching its fixture commit.

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

https://claude.ai/code/session_01FEkQ5mjnQAcpdnyqK2Xi6y


Generated by Claude Code

…IDC does

@better-auth/sso redirects an account refusal from handleOAuthUserInfo
(account_not_linked and its siblings) to the success callbackURL, and a
response over maxResponseSize to the app origin. The SSO callback refusal
scope now also wraps the SAML ACS: it reads the sign-in's relay state before
the vendor consumes it and re-bases any refusal that is not on the flow's
error URL onto it, error= and error_description unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEkQ5mjnQAcpdnyqK2Xi6y
@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 30 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), internalAdapter (symbol, a field of interface SamlLandingContext))
  • content/docs/permissions/sso.mdx (via error_description (literal, a string literal in rebaseSamlRefusal), /sso/saml2/sp/acs/:providerId (route, a path literal in a comment in AuthManager; a path literal in a comment on a changed line))

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

  • content/docs/releases/v17/17-0.mdx (via internalAdapter (symbol, a field of interface SamlLandingContext))
  • 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
  • 1 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 065bba721e4ba180c6bdbbf2c5fb787d49bac596 → packageMentionDocs.

Which tree this was computed on

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

node scripts/docs-audit/affected-docs.mjs --json 065bba721e4ba180c6bdbbf2c5fb787d49bac596

⚠️ 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 065bba721e4ba180c6bdbbf2c5fb787d49bac596 → 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#6 · os-project-manager · session_01FEkQ5p3T5YWhLjurajudnQ

席位核对 · ACCEPT · 2026-11-07T19:20Z · head ffdd6e0fc391d8ca76cf9aba4a490d1852563942

Seat domain:server#6 reviewed the diff of its own dispatch (claim 6710984037 on #30966, card thread session_01FEkQ5mjnQAcpdnyqK2Xi6y, report 6711645407). Read against GitHub, not the report.

  1. Shape: 6 files, +639 / -20. The SAML ACS (POST /sso/saml2/sp/acs/:providerId) now runs inside the same refusal scope as the OIDC callback (fix(plugin-auth): a refused enterprise OIDC sign-in names its cause #31194's seam): ssoCallbackOf picks OIDC or SAML-POST, runSsoCallbackScope keeps the OIDC branch as it was, and for SAML reads the relay-state row (auth-state:<RelayState>) through the vendor's own internalAdapter BEFORE the vendor consumes it. A vendor redirect carrying error= that is not the success URL is re-based onto the error URL, keeping error / error_description; success, IdP-initiated (no relay state), and unreadable state are left as the vendor answered. The error URL passes the vendor's redirect safety rule again (safeSamlTarget: no //, /\, encoded variants, foreign untrusted origin, or the ACS itself). Host member renamed runSsoOidcCallback → runSsoCallback (private). No vendored patch. Docs: one step added to the SAML flow in sso.mdx. Body says Fixes #30966; no other closing keyword.
  2. Premise: on origin/main an account refusal from handleOAuthUserInfo (account_not_linked and five siblings) lands on the success callbackURL with only ?error=, and an over-size response lands on the app origin; red reproduced at 66bf5b4a per the report, and the new test file's takeover / over-size cases pin both.
  3. Gates / check-runs: 50 runs on this head, 38 success, 12 skipped, 0 red, including Test Core 1–8/8, Type Check · workspace and Lint. mergeable_state clean. Dev: plugin-auth 236/236 files green, 95/95 derived gates exit 0 (pm-orders/server/30966-gates-ran.txt), three ablations red and restored.
  4. Accepted deviations / notes: with no errorCallbackURL, a refused SAML sign-in now lands on the platform error page (onAPIError.errorURL, the Console sign-in page) instead of the signed-in page; that is where OIDC and every other SAML refusal already land, and the PR's Acceptance notes and the changeset say so. Accepted as the fix itself.
  5. Out of scope / Skills-docs: the SAML refusal CAUSE (vendor's bare catch around parseLoginResponse) still waits on the vendor, as the module doc says; plugin-auth SSO: SAML refusals name their cause (expiry, issuer, signature, signing key) once @better-auth/sso keeps samlify's error #31168 untouched. Metadata-protocol: none; Skills-docs: not owed. Nothing filed.
  6. Landing: check-governed-merges --pr 31231: not governed, 659 changed lines. Clause-②: no (the package's named exports from sso-oidc-refusal-cause.ts are unchanged; only the Location of a refusal 302 moves), no packages/spec/src path, so no contract review is owed. Changeset 30966-saml-refusal-lands-on-error-url.md, patch, holds. Landing on the maintainer's standing words 「按照 pm-dispatch 规则复核过的都授权」 (2026-10-25T11:35Z) and 「你应该使用 pm-dispatch 技能审核和落地pr」 (2026-11-07T16:59Z). Relay pr_ready, then automerge_enable.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 7, 2026 19:21
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 7, 2026 19:21
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit b065fad Nov 7, 2026
51 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-f4lk8u branch November 7, 2026 19:45
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

Development

Successfully merging this pull request may close these issues.

plugin-auth SSO: a SAML account_not_linked refusal redirects to the success callbackURL and ignores errorCallbackURL (OIDC honours it)

1 participant