Repository navigation
fix(plugin-auth): an auth request is judged and executed as one account - #31469
Conversation
…nt (wip) Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude <noreply@anthropic.com>
…ctor-per-request Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 2 package(s): 13 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 7 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 176 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 22a462256f80fedbb9d6c97bd43a15acc5fb2b6b && git checkout 22a462256f80fedbb9d6c97bd43a15acc5fb2b6b
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 5ee59f5ef449de22926af221d8fc9b7baf78a2d0 69cda6363dea793f63bfd21ec3324489bd13c5e4 && git checkout -B drift-repro 5ee59f5ef449de22926af221d8fc9b7baf78a2d0 && git merge --no-ff 69cda6363dea793f63bfd21ec3324489bd13c5e4
node scripts/docs-audit/affected-docs.mjs --json 5ee59f5ef449de22926af221d8fc9b7baf78a2d0
|
…account rule, and the identity mount fails closed Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude <noreply@anthropic.com>
…ctor-per-request Claude-Session: https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f Co-authored-by: Claude <noreply@anthropic.com>
|
security#1 · sunhaolin · session_017xRBcT1w3zpekijraHJE4f 席位核对ACCEPT at
Implemented-by: os-dev (security#1 order, |
…the inherited admin cookie (objectstack-ai#31871) <!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi96VGP7vMPA9C54zyjz2LMch)_ Fixes objectstack-ai#31827 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:夜间 live 层的成员夹具改为只用成员自己的凭据发 API 请求(成员自己的会话 cookie 加它的 Bearer),成员登录也从空状态开始;`read-only-member-record.spec.ts` 只换成调用新助手,断言一条未动。 - 为什么改:在 `@playwright/test` 里,不指定 `storageState` 新建的请求上下文会继承配置里的管理员 cookie,于是成员请求同时带着管理员 cookie 和成员 Bearer。objectstack-ai#31469 起服务端拒绝这种「两个账号」的请求,数据路由回 401,夜间层因此变红。席位裁定:改夹具,不改产品。 - 风险与回滚:只动 `ui/e2e/live/` 下两个测试文件,不发布任何包,不动 `packages/`。回滚即 revert。 - 先看:`ui/e2e/live/member.ts` 的 `memberRequestContext` 和模块注释里的 ⛔ 段。 - 两分钟验证:起后端后跑 `OS_TEST_TIERS=nightly pnpm --filter @objectstack/example-showcase exec vitest run test/console-live-specs.live.test.ts`,预期 `28 passed`。 - 需要你做的:无,席位落地。 ## What changes - `ui/e2e/live/member.ts` gains `memberRequestContext(member)`: a request context carrying the member's own session cookie and its Bearer, with its `storageState` named so the config's administrator cookie is not inherited. - The member's sign-in context starts from an empty `storageState` (`{ cookies: [], origins: [] }`) instead of the inherited administrator cookie, so the sign-in request names the member only. - `read-only-member-record.spec.ts` builds its premise context with the helper. That is its only change: the `playwright` fixture it no longer uses leaves the destructuring, and no assertion moves. - The module comment states the trap: inside `@playwright/test`, `playwright.request.newContext()` and the imported `request.newContext()` both start with the config's `use.storageState`. No test was skipped, renamed or loosened. No change under `packages/`. ## Why The nightly live tier went red at `6be71abc` on `read-only-member-record.spec.ts:48`, premise step: the member's `GET /api/v1/data/showcase_inquiry/<id>` answered 401 where 200 was expected. Step 0 (seat ruling 6735238125): - **Bisect.** Each commit measured on a fresh backend booted by `ui/e2e/live/ci/start-backend.sh`, with the spec's request shape: | Commit | Result | |:--|:--| | `44a030bf` (last green nightly) | green, read 200 / write 403 | | `133f75aec0~1` | green, 200 / 403 | | `133f75aec0` objectstack-ai#31469 | **red**, 401 / 401 | | `ed4b83226b` objectstack-ai#31443 | red | | `59630d9357` objectstack-ai#31622 | red | | `8c9260f79c` objectstack-ai#31657 | red | | `f127b04e07` objectstack-ai#31686 | red | | `6be71abc` (red nightly) | red | - **Cause.** The member's context was `playwright.request.newContext({ extraHTTPHeaders: { Authorization: 'Bearer <member>' } })`. Inside `@playwright/test` that context inherits the config's `use.storageState`, which is the global setup's administrator cookie. Measured: the context's cookie equals the administrator's. So each premise request carried two accounts' credentials. Before objectstack-ai#31469 the bearer won. Since objectstack-ai#31469 the session read refuses such a request with `CREDENTIALS_NAME_DIFFERENT_ACCOUNTS`, and the data route answers its own anonymous 401. objectstack-ai#31469's acceptance notes describe exactly that data-route answer, so the product behaves as ruled and the fixture relied on what objectstack-ai#31469 ruled out. ## Sweep (owed by the ruling) Every live spec and helper under `ui/e2e/live/` that builds a request context or sends a credential: | Site | Accounts it sends | Action | |:--|:--|:--| | `read-only-member-record.spec.ts` premise context | admin cookie (inherited) + member Bearer | **moved onto `memberRequestContext`** | | `member.ts` sign-in context (`request.newContext()`) | admin cookie (inherited) on the member's sign-in | **moved onto an empty `storageState`** | | `read-only-member-record.spec.ts` member browser context | member `storageState` named explicitly | one account, unchanged | | `global-setup.ts` sign-in context | none (global setup runs before any `use` state exists) | one account, unchanged | | `inline-edit-polish-2572.spec.ts` `request` + Bearer | admin cookie + admin token from the same `state.json` | one account, unchanged | | `studio-customize-journey.spec.ts` `request` override | `storageState` passed by name (admin), no other credential | one account, unchanged | | `studio-object-designer.spec.ts` in-page `fetch` | admin page's own cookie + its own localStorage token | one account, unchanged | | every other spec's `request.get/post/…` (cascading-options, grid-file-upload, list-row-action-cel, master-detail, record-form-direct-url, record-history-display) | admin `request` fixture alone | one account, unchanged | Measured for the two inherited sites: the imported `request.newContext()` and `playwright.request.newContext()` each start with 1 cookie under this config; with `storageState: { cookies: [], origins: [] }` they start with 0. ## Verification All heavy runs went through `scripts/pm/os-verify-lock.sh`. Head `86082eb9b5`, backend closure and `pnpm console:build` rebuilt at the head first. - **Nightly live file, head:** `OS_TEST_TIERS=nightly pnpm exec vitest run test/console-live-specs.live.test.ts` in `examples/app-showcase`: Playwright `28 passed (1.3m)`, vitest `Test Files 1 passed (1)`, `Tests 1 passed (1)`. - **Ablation:** `scripts/ablation-replace.mjs` deletes the helper's `storageState` line in `member.ts` (anchor 1 → 0, blob `d4e1a39d33f5` → `dc6c2ff0d686`), so the inherited administrator cookie is back. The same run: `✘ read-only-member-record.spec.ts:48`, `Expected: 200`, `Received: 401`, `Test Files 1 failed (1)`. Restored: blob equals HEAD's (`d4e1a39d33f5`), `git diff HEAD` empty, `git status --porcelain` empty. - **Before the fix, on main `3487ccc1`:** the same nightly run was red, 1 of 28, the same 401. - **Dispatch gates:** see the os-dev-report on objectstack-ai#31827 for each command's exit code and the `--ran` reconciliation; `pnpm lint` and `eslint` over the two touched files are reported there too. No changeset: the diff publishes nothing (`ui/e2e/live/` only), so this PR carries `skip-changeset`. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (No `packages/spec` change.) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [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. (Publishes nothing; `skip-changeset`.) - [x] 6. `packages/spec` touched: n/a. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. (The 维护者速读 section is the seat's required Chinese summary.) - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmPpwZNVKwJLQGotdJy --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmPpwZNVKwJLQGotdJy)_ Co-authored-by: Claude <noreply@anthropic.com>
Clause-②: yes — this PR publishes one new error code,
CREDENTIALS_NAME_DIFFERENT_ACCOUNTS, in the@objectstack/specerror-code ledger.Metadata-protocol: none
维护者速读
401 CREDENTIALS_NAME_DIFFERENT_ACCOUNTS拒绝,两个账号都不写任何东西;改密码成功后的后续写入(改密时间戳、强制改密标记、密码历史)只落在端点实际改动的那个账号上;管理员撤销会话在仅用 bearer 登录时也认得出调用者。packages/plugins/plugin-auth/src/one-account-per-request.ts(规则与判定);auth-manager-before-hook.ts中新步骤的位置(所有门禁之前);auth-manager-after-hook.ts的/change-password一段。pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2 src/one-account-per-request.test.ts,预期 17 个用例全部通过。What changes
An auth request is judged and executed as one account.
401 CREDENTIALS_NAME_DIFFERENT_ACCOUNTS, and nothing is read or written for either account. The step runs first in the global better-auth before-hook (ahead of every ObjectStack gate and of the endpoint, over HTTP and for the in-process session read), and as a middleware on the identity mount ahead of its raw ObjectStack routes, which answer it with the same code in the ADR-0112 envelope.503 SERVICE_UNAVAILABLE./change-passwordstampspassword_changed_at, clears a forced change and appends the history entry on the account the endpoint acted on (ctx.context.session.user, the reading the change-email notice already takes), and only when the password checks before it ran for that same account; otherwise none of them lands and the operator is told./admin/revoke-user-sessionresolves a caller signed in by bearer alone, so a token that identifies no session is refused (404 RESOURCE_NOT_FOUND) on that lane as on the cookie lane.CREDENTIALS_NAME_DIFFERENT_ACCOUNTSis registered in the@objectstack/specerror-code ledger under@objectstack/plugin-auth(no existing 401 code means "credentials name different accounts"); the three generated reference pages that list the ledger are regenerated.Tests
one-account-per-request.test.ts(new, 17 cases, real ObjectQL over better-sqlite3 and the installed better-auth, two real accounts): the refusal on the session read (HTTP and in process), a data door's session leg,/change-password,/revoke-session,/update-userand the admin paths (/admin/set-role,/admin/revoke-user-session, the administrator on either credential), each asserting code and status and that nothing was written; same account on both credentials, cookie alone, bearer alone, a bearer or a cookie naming no signed-in account; the identity mount's raw admin route and its catch-all; the judgment's token reading and the 503 on a read that throws; an API key beside a session cookie is not refused by this rule; a request carrying both credentials whose judgment cannot be reached at the identity mount is answered503and goes no further.forced-password-change-new-password.test.ts: one new top-level describe (5 cases) — after-effects land on the account the change acted on, on the bearer lane, and on no other account.admin-revoke-user-session-match-guard.test.ts: one new top-level describe (3 cases) — the bearer lane is judged as the cookie lane.change-email-delete-user-wiring.test.ts: the two-account case now asserts the refusal, no mail and no address moved.Acceptance notes
401reaches the wire on the auth routes and the identity mount, not on the data routes. A door that re-reads an active authentication gate treats any failed session read as a store outage and answers503there. Carrying the code through those doors is a change inpackages/core/packages/runtime, outside this PR.createAuthClient.getSession, a coded401on the bearer-carrying read is followed by the cookie-only read, whose session and token are adopted.Verification
On head
7f088a82dc(origin/main merged in) unless stated. Round 2 (52faff29f) adds the API-key pin and the identity mount's503pin:pnpm --filter @objectstack/plugin-auth testTest Files 241 passed (241), Tests 4292 passed, 10 skipped; typecheck exit 0; each new pin ablated red, then restored.plugin-auth suite and typecheck
pnpm --filter @objectstack/plugin-auth typecheck: exit 0 (src, examples,check:test-typecheck).pnpm --filter @objectstack/plugin-auth test: Test Files 241 passed (241), Tests 4290 passed, 10 skipped (4300).Ablation (each leg reverted on disk, red, restored to HEAD with an empty diff)
/change-password,/revoke-session,/update-user, admin paths, change-email), 28 green.Derived gate families
dispatch-gates --commandsat7f088a82dc: 120 families; 120 run, reconciled with--ran(120 derived, 120 run, 0 unrun).check:skill-examplesrefused for an unbuilt@objectstack/client-reactand exited 0 once that closure was built;check:dual-build-cjs-loadsNOT MEASURED (it needs the whole workspace built), left to CI.pnpm --filter @objectstack/spec check:generated: one stale artifact (the reference docs) regenerated withgen:docs.