Repository navigation
Commit eac6d96
fix(rest)!: security/explain refuses an explicit empty userId with 400 instead of explaining the caller (#27714)
domain:server#2 · os-sales · session_01L6bhgUCizoYWQVJWjhdR6F
<!-- claude-projects-attribution: {"github_login":"os-sales"} -->
_Requested by **Sales** · [project
thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuPMZ8BHWtPf6nBTp51qSM64)_
Fixes #27442
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: updated here — `content/docs/permissions/explain.mdx` now
says an empty `userId` is refused `400 VALIDATION_FAILED`, beside "omit
`userId` to explain yourself". No file under `skills/**` teaches an
empty `userId`: `skills/objectstack-data/rules/security.md` names the
query parameters as a list (`?object=&operation=&userId=`) and says
nothing about an empty value, so no skill line changes.
## 维护者速读
- **改了什么**:权限解释接口(`GET/POST /api/v1/security/explain`)收到显式的空
`userId`(`"userId": ""` 或 `?userId=`)时,改为回 `400
VALIDATION_FAILED`,不再悄悄解释调用者本人;不传 `userId` 仍解释调用者本人。
-
**为什么改**:路由在校验前把空串当成「没传」丢掉,引擎又按真值判断,于是「解释某个空用户」答成了「解释我自己」,管理员会误以为看到的是别人的权限。
- **风险与回滚**:只收窄这一个请求值;不传 `userId`、传真实用户 id、传不存在的 id 三种行为与 main
一致。引擎侧同步改为 `userId !== undefined` 才算「解释自己」,直接调用引擎的代码传空串会得到 403 或
404。回滚即还原 `security-routes.ts` 与 `security-plugin-explain-access.ts`
各一处。
- **先看**:`packages/rest/src/security-routes.ts` 新增的 `src.userId === ''`
拒绝分支;`packages/plugins/plugin-security/src/security-plugin-explain-access.ts`
的 `request.userId !== undefined` 判断。
- **两分钟验证**:`pnpm --filter @objectstack/rest exec vitest run
src/security-routes.test.ts -t 27442`,预期 3/3 通过。
- **需要你做的**:无,席位落地(收窄卡,进队前席位排契约复核)。
## What changes
- **The door (`@objectstack/rest`).** `GET`/`POST
{basePath}/security/explain` answers `400 VALIDATION_FAILED` when
`userId` is the empty string, through the family's one refusal emitter
(the same ADR-0112 envelope and code its schema refusals answer), before
any explanation is computed. Before, the route dropped an explicit `""`
along with an omitted value, so the request fell through to a
self-explanation of the caller.
- **GET counts as explicit.** `?userId=` names the key, and the query
parser hands the route `""` (measured on the showcase boot), so it is
refused the same way. Only a request that does not name `userId` at all,
or sends JSON `null`, is "explain me", as before.
- **The engine (`@objectstack/plugin-security`).**
`explainAccessForCaller` enters the other-user arm when `request.userId
!== undefined` (was a truthy test). An empty id therefore meets the
existing gates there: a caller without the right to explain others gets
the same `403 PERMISSION_DENIED`, and a `manage_users` caller gets the
`404 RECORD_NOT_FOUND` an unknown id gets. A direct caller of the engine
can no longer reach the self-explain fold with `""`. Every in-tree
caller of `security.explain` omits `userId` (measured: `rest-server.ts`,
`runtime/domains/automation.ts`, `service-storage` x2,
`plugin-webhooks`, `plugin-sharing`, `plugin-audit`), so none of them
moves.
- **No new code, no spec edit.** `VALIDATION_FAILED` is an existing
ledgered code, and `ExplainRequestSchema` is untouched (its
`z.string().optional()` admits `""`, which is why the refusal sits at
the route).
- **Docs.** `content/docs/permissions/explain.mdx` states the refusal
next to "omit `userId` to explain yourself".
## Tests
- `packages/rest/src/security-routes.test.ts` — new block `[#27442]`:
POST `userId: ""` → `400`, `success: false`, `error.code`
`VALIDATION_FAILED`, no `allowed`, `explain` never called; GET
`?userId=` → the same, `explain` never called; omitted `userId` (POST
and GET) still calls `explain` without one, and a real other id is still
passed through.
- `packages/plugins/plugin-security/src/security-plugin.test.ts` — new
block `[#27442]`: a `manage_users` caller asking `userId: ""` gets
`ExplainUserNotFoundError` (`RECORD_NOT_FOUND`, 404) instead of an
explanation of itself; a plain member gets `PermissionDeniedError`
(403); an omitted `userId` still explains the caller.
- `packages/qa/dogfood/test/explain-unknown-user.dogfood.test.ts` — new
case `[empty]` on the showcase boot (the #26641 sibling, same boot, no
new one): the seed admin's POST `userId: ""` and GET `?userId=` both
answer `400 VALIDATION_FAILED` with no verdict and no principal. The
file's existing `[existing]` case keeps pinning that an omitted `userId`
explains the caller and a real other id is answered.
## Acceptance notes
- Red first, through the door: before the fix the two route cases
answered `200` (`expected 200 to be 400`) and the engine case answered
an explanation of the caller.
- Ablations (each restored, blob == HEAD, `git diff HEAD` empty):
- Route guard disabled (`if (src.userId === '')` replaced by a
never-true marker, rebuilt, `ablation-dist-preflight` proved the marker
in `packages/rest/dist/index.{js,cjs}`): the unit file goes `2 failed |
17 passed` (`expected 200 to be 400`) and the dogfood file `1 failed | 5
passed`, answering `404 RECORD_NOT_FOUND` naming user `''` — the
engine's own line holding once the door's is gone. Rebuilt after
restore; preflight `--absent` clean.
- Engine check reverted to the truthy `request.userId &&`: the engine
block goes `1 failed` (`expected { allowed: true, … }` to be the
refusal).
- Order of checks at the door is unchanged: anonymous `401` first, then
`501` when no explain service, then this `400` with the schema refusals.
- `null` in a POST body keeps reading as omitted (unchanged); the ruling
refuses only an explicit empty string.
- Branch is the harness-pinned `claude/project-thread-sbdkgo` (claim
6504756487 names it); card-thread session
`session_01L6bhgTYZasLoBBaTy45mgo`.
## Verification
All readings on head `821c2ced` (the fix `297d9907` merged with
`origin/main` `86f2afeb`), in a worktree of
`objectstack-ai/objectstack`, under `scripts/pm/os-verify-lock.sh`.
<details><summary>Unit suites and typecheck</summary>
- `pnpm --filter @objectstack/rest exec vitest run`: `Test Files 344
passed (344)`, `Tests 6945 passed | 344 skipped (7289)`.
- `pnpm --filter @objectstack/plugin-security exec vitest run`: `Test
Files 237 passed (237)`, `Tests 5119 passed | 45 skipped (5164)`.
- `pnpm --filter @objectstack/rest typecheck` and `pnpm --filter
@objectstack/plugin-security typecheck` (including
`check:test-typecheck`, 0 errors): exit 0.
- Red before the fix: `security-routes.test.ts` `2 failed | 17 passed`
(`expected 200 to be 400`); the engine block `1 failed` (an explanation
of the caller where the refusal was expected).
</details>
<details><summary>Door (dogfood) and the full battery</summary>
- `pnpm --filter @objectstack/dogfood exec vitest run
test/explain-unknown-user.dogfood.test.ts`: `Tests 6 passed (6)`.
- Full battery, `pnpm --filter @objectstack/dogfood test` after the
closure build (`turbo run build --filter='@objectstack/dogfood^...'`),
no shard, no path: `Test Files 352 passed | 3 skipped (355)`, `Tests
2845 passed | 20 skipped (2865)`, lock VERDICT command-exit 0.
</details>
<details><summary>Gates</summary>
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 95 families; each was run and its
exit code captured before any pipe; `--ran` reconciliation: `95 derived,
95 run, 0 NOT-MEASURED, 0 UNRUN`.
- Four first readings were prerequisites (exit 3, or the generated-tree
refusal), not verdicts, and were rerun green after meeting them:
`check-plugin-teardown-shape --self-test` (pinned fixture commit
fetched, 48 cases pass), spec `check:docs` and `check:skill-examples`
(after `gen:schema`), `check:dual-build-cjs-loads` (after building the
seven packages it listed with no `dist/`).
- `pnpm lint` (repo-wide `eslint . --no-inline-config`): exit 0.
- No `packages/spec`, `docs/adr/**`, `skills/**` or `.github/**` path is
touched. The claim measured no open PR editing either source file.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L6bhgUCizoYWQVJWjhdR6F)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L6bhgUCizoYWQVJWjhdR6F
Co-authored-by: Claude <noreply@anthropic.com>1 parent ecd944f commit eac6d96
7 files changed
Lines changed: 135 additions & 2 deletions
File tree
- .changeset
- content/docs/permissions
- packages
- plugins/plugin-security/src
- qa/dogfood/test
- rest/src
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
74 | 76 | | |
75 | 77 | | |
76 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
137 | 140 | | |
138 | 141 | | |
139 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3891 | 3891 | | |
3892 | 3892 | | |
3893 | 3893 | | |
| 3894 | + | |
| 3895 | + | |
| 3896 | + | |
| 3897 | + | |
| 3898 | + | |
| 3899 | + | |
| 3900 | + | |
| 3901 | + | |
| 3902 | + | |
| 3903 | + | |
| 3904 | + | |
| 3905 | + | |
| 3906 | + | |
| 3907 | + | |
| 3908 | + | |
| 3909 | + | |
| 3910 | + | |
| 3911 | + | |
| 3912 | + | |
| 3913 | + | |
| 3914 | + | |
| 3915 | + | |
| 3916 | + | |
| 3917 | + | |
| 3918 | + | |
| 3919 | + | |
| 3920 | + | |
| 3921 | + | |
3894 | 3922 | | |
3895 | 3923 | | |
3896 | 3924 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
| |||
108 | 111 | | |
109 | 112 | | |
110 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
111 | 132 | | |
112 | 133 | | |
113 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
157 | 205 | | |
158 | 206 | | |
159 | 207 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
207 | 218 | | |
208 | 219 | | |
209 | 220 | | |
210 | | - | |
| 221 | + | |
211 | 222 | | |
212 | 223 | | |
213 | 224 | | |
| |||
0 commit comments