Repository navigation
Commit c0665c0
fix(plugin-auth): SSO-user doors admit the stamped organizationId when it is the session's, so console Import Users and Add User work (#34966)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} -->
_Requested by **Yibo Wang** · [project
thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBXim82sEGBUBXqH4hkWyBJX)_
Fixes #34912
repo:objectstack#3 · os-support-ai · session_01WGufzi3ezPzTysQPDEjmVz
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- **改了什么**:三个 SSO
用户入口(`admin/import-sso-users`、`admin/add-sso-user`、`admin/remove-sso-user`)现在接受请求体里的
`organizationId`,但只在它等于调用者会话当前组织时接受;不等、类型不对、或会话没有当前组织都会被 400 拒绝,且什么都不写。
- **为什么改**:控制台的「导入用户」「添加用户」经服务端动作转发到 `/api/v1/auth/`,转发统一附带调用者的
`organizationId`,而这三个入口拒收任何未知键,所以托管环境里每个管理员点这两个按钮都必然 400。
-
**风险与回滚**:组织范围仍只取自会话,请求体里的值只做相等校验、从不参与范围;风险面是「请求体能否改写组织」,已有拒绝用例与消融钉住。回滚即还原
`pending-sso-users.ts` 一个文件。
- **先看**:`packages/plugins/plugin-auth/src/pending-sso-users.ts` 的
`refuseForeignOrganization`(三个入口共用的校验);同文件三处 `unknownBodyKeys`
调用;`pending-sso-users.test.ts` 末尾的 `[#34912]` 用例组。
- **两分钟验证**:`pnpm --filter @objectstack/plugin-auth exec vitest run
--maxWorkers=2 src/pending-sso-users.test.ts -t 34912`,预期 14 个用例全绿。
- **需要你做的**:无,席位落地。
## What changes
- `pending-sso-users.ts`: one shared check, `refuseForeignOrganization`,
runs in all three doors right after their closed-key check.
`organizationId` is the only key admitted beyond each door's own set
(`unknownBodyKeys`), and only as a statement the session already makes:
- absent: unchanged;
- equal to `deps.getCallerActiveOrganizationId()` (the caller's own
session, read with the request's headers through `authApi.getSession`;
the route wiring already passes it to these doors, so no wiring change):
admitted, then never read again. Scope stays the session's: single-org
binds the sole organization as before, multi-org joins the session
organization in `settleRequest` as before;
- a different string: `400 INVALID_REQUEST`, the sentence names the
organization sent and the one the session holds;
- not a non-empty string (`null`, `''`, a number): `400
INVALID_REQUEST`;
- any value while the session works in no organization: `400
NO_ACTIVE_ORGANIZATION`.
Every refusal happens before any read, write or host call. Both codes
are already in the error-code ledger; no new code.
- The generic identity-route stamp in `buildApiActionRequest`
(`packages/runtime/src/action-execution.ts`) is unchanged (seat ruling
A).
- Changeset: `@objectstack/plugin-auth` patch, with both declaration
lines.
## Tests
- `packages/plugins/plugin-auth/src/pending-sso-users.test.ts`, new
top-level describe in the shared harness (real `AuthManager` and real
route mount, real bearer sessions):
- for each of add, import and remove: absent key accepted; equal key
accepted (membership in the session organization); a different
organization refused 400 naming both, with nothing written and no host
told; no active organization in the session plus a body organization
refused 400 `NO_ACTIVE_ORGANIZATION` (and, on add, a CONTROL: the same
request without the key still answers 201);
- add: `null`, `''` and `42` refused 400;
- over fakes with multi-org tenancy on: a foreign body organization is
refused and the join never runs; an equal one is admitted and the join
is handed the session's value.
- `packages/runtime/src/domains/api-action-forward.test.ts` (the
`buildApiActionRequest` harness), CONTROL describe: the declared
`sys_user.import_sso_users` and `add_sso_user` actions are still stamped
with the caller organization, `ban_user` (another identity route) keeps
the stamp, and a caller with no organization gets no stamp.
- Ablation of the equality check (`if (sent !== current) {` to `if
(false) {`, via `scripts/ablation-replace.mjs`, anchor 1 to 0, blob
`ed0b3c405d81` to `2cd498db4bb9`): exactly the four foreign-organization
legs go red (add, import, remove, multi-org fake), 10 others stay green;
restored, blob back to `ed0b3c405d81` = HEAD, `git diff HEAD` empty.
<details><summary>Test and type-check readings</summary>
- `pnpm --filter @objectstack/plugin-auth test` (tree at c8d32b0; head
ce3609c adds only the changeset): Test Files 285 passed (285), Tests
5983 passed, 10 skipped. Exit 0.
- `pnpm --filter @objectstack/plugin-auth typecheck`: exit 0. `pnpm
--filter @objectstack/runtime typecheck` (includes
`check:test-typecheck` over the test file): exit 0.
- `vitest run src/domains/api-action-forward.test.ts` (runtime): 89
passed (89).
- `vitest run src/pending-sso-users.test.ts -t 34912`: 14 passed.
- Ablation run: `Tests 4 failed | 10 passed`; the failed names are the
three "a different organization is refused 400 naming both" legs and
"the body organization never feeds scope".
</details>
## Acceptance notes
- `admin/remove-sso-user` has no declared console action: no `sys_user`
action targets it, although the auth route ledger note says Setup →
Users posts it. Its live reading posts the body an identity-route
forward would send. Noted, not filed.
- The Import Finished result dialog draws its fields and per-row table
past the dialog's right edge (screenshot `after-2-import-result.png` in
the live readings). Reported to the seat as a separate UX finding; not
touched here.
- **Claim amendment (seat order, 2026-11-17 19:52Z): docs fold.** The
doc and the ledger now describe the bodies this PR changes. Commit
7f0c346 changes prose and ledger `note` strings only, with no code
path changed:
- `content/docs/permissions/authentication.mdx`, in the cloud-managed
two-doors section: one paragraph says that add-sso-user,
import-sso-users and remove-sso-user take an optional `organizationId`.
It is admitted only when it equals the session's active organization. A
different or non-string value gets `400 INVALID_REQUEST`, and a body org
with no session org gets `400 NO_ACTIVE_ORGANIZATION`. Nothing is
written before either refusal, and the value never widens scope. The
remove-sso-user line points to that paragraph.
- `packages/plugins/plugin-auth/src/auth-route-ledger.ts`: the three
`note` strings for those routes state the same rule.
- At 7f0c346, dispatch-gates derives 104 families, and all 104 ran
with 0 UNRUN. Seven waited on builds and passed on rerun after the
builds. One is NOT MEASURED: the teardown self-test, whose fixture
commit is not in the shallow clone. check:auth-mount-ledger,
check:route-ledger-census and check:error-code-casing exit 0.
overlap-check is clean, including against #34969 and #34738, which also
edit authentication.mdx.
- L1 ACCEPT 6959151659 and seat L2 PASS were read at ce3609c. This
fold answers the doc nit both of them named.
## Verification
Live readings on a cloud-managed showcase (`OS_CLOUD_MANAGED=1`), driven
through the real console, before (origin/main's door) and after (this
head): posted as a PR comment.
<details><summary>Local gates at ce3609c</summary>
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack`: 71 commands. All 71 run: 69 exit 0; 2 exit
3, read as NOT MEASURED: `node scripts/check-plugin-teardown-shape.mjs
--self-test` (pinned fixture commit not reachable from this shallow
clone; script untouched) and `pnpm check:dual-build-cjs-loads`
(PREREQUISITE NOT MET: whole-tree gate, unbuilt packages outside this
diff). CI runs both.
- `--ran` reconciliation: 71 derived, 71 run, 0 UNRUN.
- Run beyond the derivation, roster gates whose roster sits under a
changed directory: `check:auth-mount-ledger`, `check:error-code-casing`,
`check:route-ledger-census`, all exit 0.
- `node scripts/pm/overlap-check.mjs --branch=HEAD`: `VERDICT clean exit
0` against origin/main 8e49847 and 0 PR heads.
</details>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01WGufzi3ezPzTysQPDEjmVz
<!-- signed: repo:objectstack#3 · os-support-ai ·
session_01WGufzi3ezPzTysQPDEjmVz -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 4443014 commit c0665c0
6 files changed
Lines changed: 375 additions & 9 deletions
File tree
- .changeset
- content/docs/permissions
- packages
- plugins/plugin-auth/src
- runtime/src/domains
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1346 | 1346 | | |
1347 | 1347 | | |
1348 | 1348 | | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
1349 | 1363 | | |
1350 | 1364 | | |
1351 | 1365 | | |
| |||
1414 | 1428 | | |
1415 | 1429 | | |
1416 | 1430 | | |
1417 | | - | |
1418 | | - | |
1419 | | - | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
1420 | 1435 | | |
1421 | 1436 | | |
1422 | 1437 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
263 | | - | |
264 | | - | |
265 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
| |||
0 commit comments