You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 38c528e
Browse filesBrowse the repository at this point in the historyBrowse files
fix(plugin-auth): a refused IdP-initiated SAML sign-in lands on the platform's sign-in page with its error (#32193)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwB5566d24165XFeca3tgBhXU)_Fixes#32132
Clause-②: no
Metadata-protocol: none
## 维护者速读
- **改了什么:** 企业用户在 IdP 门户(如 Okta 应用图标)直接发起 SAML 登录、而服务端拒绝时(默认没有开「允许 IdP
发起登录」),拒绝现在落到 Console 登录页
`/_console/login?error=unsolicited_response`,和其他 SAML 拒绝、OIDC
拒绝是同一个页面。只改 plugin-auth 的 SAML 拒绝落地层,没有新增任何接受路径。
- **为什么改:** 以前这次拒绝跳到站点根 `/?error=unsolicited_response`,根路径再跳
`/_console/` 时把参数丢了,登录页什么都不显示,用户只看到被弹回来(cloud#3666 的 Okta 实测遇到)。
- **风险与回滚:** 只移动拒绝响应的 `Location`:拒绝照旧是拒绝,不发会话、不建用户(测试有断言);允许 IdP
发起时的成功登录照旧落站点根;运营方给 provider 配了自己的 `idpInitiatedCallbackUrl`
的,拒绝照旧落那里。回滚 = revert 本 PR。
- **先看:** `packages/plugins/plugin-auth/src/sso-oidc-refusal-cause.ts` 的
`readSamlAcsLanding`(无 relay state 时的新分支)和 `isOnBareFallback` /
`landSamlRefusal`(只改写站点根上的拒绝);然后是测试文件里新增的 describe。
- **两分钟验证:** `pnpm --filter @objectstack/plugin-auth exec vitest run
src/sso-saml-refusal-landing.test.ts`,预期 31 个测试全绿;其中 `off (the default)`
一条断言落点是
`http://localhost:3000/_console/login`、`error=unsolicited_response`。
- **需要你做的:** 无,席位落地。之后 UI 卡 #32087 在 `ssoCallbackRefusal.ts` 为
`unsolicited_response` 加一行文案。
## Step 0: the three readings (at `origin/main` `45f0f81f`)
Taken through the real SAML ACS harness
(`sso-saml-refusal-landing.test.ts`: a real `AuthManager` and the real
`@better-auth/sso` 1.7.12, the IdP played with `samlify`) and the OIDC
harness (`sso-oidc-refusal-cause.test.ts`), with the source of both
modules at `45f0f81f` and a throwaway probe that wrote each 302
`Location` to a scratch file (removed; `git diff HEAD` empty
afterwards).
| Refusal | Test | 302 `Location` at `45f0f81f` |
|---|---|---|
| SAML `account_not_linked`, sign-in with no `errorCallbackURL` |
`takeover with no errorCallbackURL: lands on the platform error page, …`
| `http://localhost:3000/_console/login?error=account_not_linked` |
| SAML `saml_error` (tampered assertion), same sign-in | same test |
`http://localhost:3000/_console/login?error=saml_error&error_description=Invalid+SAML+response`
|
| **SAML `unsolicited_response`** (IdP-initiated, toggle off) | `off
(the default): an unsolicited Response is refused …` |
`http://localhost:3000/?error=unsolicited_response&error_description=IdP-initiated+SSO+not+allowed`
|
| SAML IdP-initiated, toggle on (success, control) | `on: the same
Response signs the person in` | `http://localhost:3000` |
| OIDC `state_not_found` (IdP-initiated, toggle off) | OIDC `off (the
default): a stateless callback is refused …` |
`http://localhost:3000/_console/login?error=state_not_found` |
With an `errorCallbackURL`, every SAML refusal lands there instead
(`takeover: lands on errorCallbackURL …`, `a refusal the vendor already
lands on errorCallbackURL …`).
**OIDC (PR #32129, merged as `cc8c4b0f`).** That PR changes no server
code: its files are all under `ui/**` plus a changeset. OIDC's landing
is the vendor's own: `@better-auth/sso` sends `state_not_found` to
`onAPIError.errorURL`, which plugin-auth sets to the console login page
(`auth-manager-auth-instance.ts`, `getConsolePageUrl('/login')`). The
SAML refusal now lands on that same URL.
**Why SAML landed on the root** (read in `@better-auth/sso` 1.7.12,
`processSAMLResponse` and `validateInResponseTo`). With no relay state,
the vendor's target is the first safe one of the provider's
`idpInitiatedCallbackUrl`, the plugin's `saml.idpInitiatedCallbackUrl`
and the provider's `callbackUrl`, else the bare app origin. The Register
SAML Provider bridge stores `callbackUrl` as the ACS itself, which the
vendor's safety rule refuses, and sets neither IdP-initiated callback,
so the target is the app origin. For a response with no relay state the
error target is that same URL, and `validateInResponseTo` builds
`unsolicited_response` on it. plugin-auth's SAML landing scope read the
relay state only, so it left this answer alone.
## FROM → TO
| | Landing |
|---|---|
| FROM |
`http://localhost:3000/?error=unsolicited_response&error_description=IdP-initiated+SSO+not+allowed`
(then `/` redirects to `/_console/` and the query is gone) |
| TO |
`http://localhost:3000/_console/login?error=unsolicited_response&error_description=IdP-initiated+SSO+not+allowed`
|
**Door: the landing, not the root redirect.** The refusal can know the
login URL: the SAML landing scope already reads `onAPIError.errorURL`
before the vendor runs, and only skipped a response with no relay state.
Keeping the query through the `/` redirects in
`packages/cli/src/utils/console.ts` would put the user on
`/_console/?error=…`, which is not the page that reads `?error=` (the
login page is), so it would also need a console change, and it would
change every `/` visit. `console.ts` is not touched.
## What changes
`packages/plugins/plugin-auth/src/sso-oidc-refusal-cause.ts` (internal
module, not exported from the package):
- `readSamlAcsLanding`: a response with no relay-state row to read (no
`RelayState`, no row, an unreadable row, or one that names no
`callbackURL`) now answers `{ fallback: appOrigin, error:
platformErrorPage }` instead of nothing. The platform error page is the
default a sign-in with no `errorCallbackURL` lands on
(`onAPIError.errorURL`, else `baseURL/error`), checked with the same
vendor safety rule; an unsafe one still answers nothing, and the
vendor's answer stands.
- `landSamlRefusal`: for that landing, only a redirect that carries
`error=` and sits on the bare fallback (the site root, no fragment, no
query but `error` and `error_description`) is re-based onto the platform
error page, `error` and `error_description` as the vendor wrote them,
every other header kept. A success (`http://localhost:3000`, no query)
and any IdP-initiated callback an operator configured are returned
untouched.
- The module docblock's "SAML: where a refusal lands" section states the
new case; `auth-manager.ts` `runSsoCallback`'s docblock names it
(comment only).
**Security posture.** The vendor still runs and refuses exactly as
before. Only the `Location` of a 302 that already carries `error=`
moves, to the platform's own login page, through the vendor's redirect
safety rule. No unsolicited Response is newly accepted; the tests assert
the refused Response sets no session cookie and creates no user.
**Same class, same rule.** With the toggle on, an IdP-initiated sign-in
refused for another reason (`SELF_REGISTRATION_CLOSED`,
`account_not_linked`, `saml_error`) sat on the same root and lost its
error the same way. The one rule covers it; the tests pin each.
## Tests
All in the shared harness
`packages/plugins/plugin-auth/src/sso-saml-refusal-landing.test.ts` (its
`makeRp` gains a `samlConfig` option, `idpInitiated` a `shapeResponse`):
- `off (the default) …` now asserts the landing `{ base:
'…/_console/login', error: 'unsolicited_response' }`, status 302, no
session cookie and no user created; `another provider's toggle does not
open this one` asserts the same landing.
- New describe `a refused IdP-initiated SAML sign-in lands on the
platform error page, as one with no errorCallbackURL does`:
`SELF_REGISTRATION_CLOSED`, `account_not_linked` and `saml_error`
(tampered Response) each land on the login page with no session; CONTROL
an allowed IdP-initiated sign-in still lands on `http://localhost:3000`
with a session; CONTROL a provider's own `idpInitiatedCallbackUrl` keeps
its `unsolicited_response` there.
- Unit: `readSamlAcsLanding` answers the fallback landing for no
`RelayState`, no row, an unreadable row and a row with no `callbackURL`;
the `baseURL/error` default; no landing for an unsafe platform page.
`landSamlRefusal` re-bases a root refusal (absolute and relative) and
leaves the success and six other shapes alone (a configured callback,
the root with a query of its own, a fragment, another origin, a
protocol-relative URL).
## Acceptance notes
- The UI half, one `unsolicited_response` row in
`ui/apps/console/src/pages/auth/ssoCallbackRefusal.ts`, is #32087's.
Until it lands, the login page shows the generic SSO sentence with the
code under Technical details.
- `content/docs/permissions/sso.mdx` ("IdP-initiated sign-in") already
says this refusal "redirects to the error page with
`error=unsolicited_response`". After this PR that is what happens, so
the page is not edited.
- The unreleased `.changeset/30966-saml-refusal-lands-on-error-url.md`
says every SAML refusal now lands where OIDC's does. This PR closes the
IdP-initiated exception to that sentence, so it becomes true and is not
edited.
- One shape the bare-fallback rule cannot tell apart: an IdP-initiated
callback an operator configures as the site root with an `error` query
of its own (`/?error=x`). A successful sign-in there would be re-based
to the login page, still signed in. Nobody configures that; noted, not
handled.
## Verification
Readings name the head they were taken at.
<details>
<summary>plugin-auth tests, build, typecheck, eslint</summary>
At `9d1fa1e5` (the fix and its changeset; `623d29e3` after it changes
two docblocks only), under `scripts/pm/os-verify-lock.sh`:
- `vitest run src/sso-saml-refusal-landing.test.ts
src/sso-oidc-refusal-cause.test.ts`: Test Files 2 passed (2), Tests 67
passed (67); the same two files at `45f0f81f`: 59 passed.
- `vitest run` over the whole package: Test Files 255 passed (255),
Tests 4595 passed, 10 skipped (4605), exit 0.
- `pnpm --filter @objectstack/plugin-auth build`: exit 0. `pnpm
typecheck` (tsc, the examples project, `check:test-typecheck`): exit 0.
At `6be22da7` (after `git merge origin/main`: 9 commits, none under
`packages/plugins/plugin-auth` or `packages/cli`): `pnpm install
--frozen-lockfile` exit 0; `pnpm --filter '@objectstack/plugin-auth...'
build` exit 0; the whole package again Test Files 255 passed (255),
Tests 4595 passed, 10 skipped, exit 0; `pnpm typecheck` exit 0.
`eslint --no-inline-config` over the three changed source files: exit 0.
`node scripts/check-nul-bytes.mjs`: exit 0.
</details>
<details>
<summary>Ablation (the landing pin, once)</summary>
At `9d1fa1e5`, `node scripts/ablation-replace.mjs` on
`sso-oidc-refusal-cause.ts`: anchor `return error ? { fallback:
appOrigin, error } : undefined;` (x1 to x0) replaced by `return
undefined; // ABLATED-32132 …` (x0 to x1), which puts the old landing
back (a response with no relay state keeps the vendor's answer); blob
`0679c797` to `903ad1f7`. The tests import the source directly
(`./auth-manager`), so no build sits between the mutation and the run.
- `vitest run src/sso-saml-refusal-landing.test.ts`: 7 failed, 24 passed
(31). The `off (the default)` case received `base:
"http://localhost:3000/"` against the expected
`http://localhost:3000/_console/login`: the FROM landing. The other six
reds are the new describe's three refusals, `another provider's toggle`,
and the two `readSamlAcsLanding` cases. The two CONTROL cases and the
`landSamlRefusal` unit cases stayed green, as they should.
- Restored: blob after restore `0679c797` equals the HEAD blob, `git
diff HEAD` empty.
</details>
<details>
<summary>Derived gates (dispatch-gates --commands, then --ran)</summary>
`node scripts/pm/dispatch-gates.mjs --commands` derived 74 families for
the 4 changed paths (241 changed lines). Each ran serially; the record
is `CMD :: exit N` per line.
- At `6be22da7` (the head this PR opens with): 74 of 74 exit 0.
`dispatch-gates --ran`: "74 derived, 74 run, 0 NOT-MEASURED, 0 UNRUN".
- At `623d29e3` (before the main merge, same 74-family list): 73 exit 0;
`check:dual-build-cjs-loads` exit 3 (PREREQUISITE NOT MET: unbuilt
dist), measured exit 0 at `6be22da7` once the post-merge build had built
plugin-auth's dependents.
`check:changeset-no-major`, `check-empty-changeset` and
`check:adr-0087-registration` (all in the 74) read the committed
changeset `.changeset/32132-saml-idp-initiated-refusal-landing.md`
(`@objectstack/plugin-auth` patch).
</details>
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(n/a, not touched)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes. (no formatter ran; eslint
over the three changed source files exit 0; the repo-wide run is CI's
`Lint & Repo Gates`)
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
(`@objectstack/plugin-auth` patch)
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (n/a)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [ ] 8. Title, body and comments are in English. (the 维护者速读 section is
in Chinese, as the dispatch order asks)
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufzfp1uE2GE28SdQSaqN)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(plugin-auth): a refused IdP-initiated SAML sign-in lands on the platform's sign-in page with its error
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
A SAML sign-in the identity provider starts on its own (an Okta or Entra app tile) carries no relay state, so `@better-auth/sso` redirected every refusal of it to the bare app origin, for example `/?error=unsolicited_response` when the provider's `allowIdpInitiated` option is off. The Console's root redirect drops the query string, so the sign-in page showed nothing. Such a refusal now lands on the platform's sign-in page (`/_console/login`), the same page a sign-in that names no `errorCallbackURL` lands on, with `error=` and `error_description` unchanged: `unsolicited_response`, and also `SELF_REGISTRATION_CLOSED`, `account_not_linked` or `saml_error` when the option is on. The refusal is unchanged otherwise, and nobody is signed in. An allowed IdP-initiated sign-in still lands on the app origin, and a provider whose stored SAML configuration names its own `idpInitiatedCallbackUrl` keeps sending its refusals there.
0 commit comments