Repository navigation
fix(plugin-hono-server): /auth/me/permissions outer catch answers the closed body - #23081
Conversation
… closed body
The outer catch of the /auth/me/permissions handler answered
{ authenticated, userId, objects, fields } with no systemPermissions, the
pre-ADR-0066 shape the console reads as "capabilities unknown" and fails
open on. It now answers the same closed body the resolver-rejection path
answers, built by one builder the success path also uses:
systemPermissions, positions, permissionSets and tabPermissions present
and empty. The log line is unchanged.
Claude-Session: https://claude.ai/code/session_01VoSxBQujKLZKPwK2u5ehQ6
Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VoSxBQujKLZKPwK2u5ehQ6 Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VoSxBQujKLZKPwK2u5ehQ6 Co-authored-by: Claude <noreply@anthropic.com>
…isible to the envelope count check:route-envelope counts only object-literal bodies and reads a bare call as a relayed one, so c.json(mePermissionsBody(...)) hid two bodies this file builds from its ruled unenveloped count (9 -> 7). Spread the builder's result into a literal at both call sites so the count stays an exact enumeration of what the file emits. Claude-Session: https://claude.ai/code/session_01VoSxBQujKLZKPwK2u5ehQ6 Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 1 package(s): 16 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 6 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 7 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 fc649c31f9fd76903dada4c1a0b2e66d23406eaf && git checkout fc649c31f9fd76903dada4c1a0b2e66d23406eaf
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 038d4c958837fb42e71842c18f062f37bd866811 54bc11877a8b1d43db3b7802e08d3707387a9d40 && git checkout -B drift-repro 038d4c958837fb42e71842c18f062f37bd866811 && git merge --no-ff 54bc11877a8b1d43db3b7802e08d3707387a9d40
node scripts/docs-audit/affected-docs.mjs --json 038d4c958837fb42e71842c18f062f37bd866811
|
Fixes #23047
Clause-②: no
What changed
Once
GET /api/v1/auth/me/permissionsknows who the caller is, it has two ways to fail, and for the caller they are the same event: the server could not compute the answer..catch(() => [])turns that into "no sets", and the success body reportssystemPermissions: []. This path was already closed.trythrows, for example the effective-object merge or a resolver that throws synchronously. The outercatchanswered the pre-ADR-0066 shape, with nosystemPermissions. The console reads that as "capabilities unknown" and fails open on it (objectui#4656 keeps that reading for a genuine pre-ADR-0066 server).The outer
catchnow answers the closed body. Both bodies below were measured on the test harness, base84c4fffbcdagainst head54bc11877a:The log line is unchanged:
[hono] /auth/me/permissions failedatwarn, with{ err: err?.message }, logged once.Design
mePermissionsBody(identity, grants)builds the authenticated body. The success path passes its computed grants. The outercatchpassesclosedMePermissionsGrants(): every grant key present and empty, with fresh values on each call.MePermissionsGrantsrequires all six grant keys, so tsc refuses a caller that drops one. The closed body is therefore the same shape as the success body, not a second literal (pinned: the two bodies have the same key set).identity(userId,tenantId) is captured before thetry, and the builder reads nothing but its two arguments.tenantId: the closed body now carries the session'stenantId(?? null), the same value the success body carries. The old catch body omitted it.positions: [], per the triage decision ("present and empty"): the server vouches for nothing it did not finish computing. The measurement below shows that no console reader takespositionsfrom this body./me/apps. The first three are byte-identical on the harness, base against head.c.json({ ...mePermissionsBody(...) }).check:route-envelopecounts only object-literal bodies and treats a bare call as a relayed one. A bare call took its ruledunenvelopedcount for this file from 9 to 7, although both bodies are still built in this file. With the spread the count stays an exact list at 9, and the gate script is not edited.Measurements
Does anything in the console read
positionsfrom this body? No.I read objectui
maine5c8ea7feand the console pin9646e2ed(shallow git fetch, read-only):packages/permissions/src/MePermissionsProvider.tsxhas 0 occurrences ofpositionsat both refs. ItsMePermissionsResponsedeclaresroles, notpositions. The context value it builds exposesroles(data?.roles ?? []),userId,systemPermissions,hasCapabilitiesandeffectiveObjects, and nothing taken frompositions.useWorkspaceAdminStatus(packages/auth/src/useWorkspaceAdminStatus.ts:220-222). It readsuser.positionsfromuseAuth(), which is the auth session. The expression scope'scurrent_user.positions(buildExpressionUser) also comes fromuseAuth().user.positions: []in this body opens no handle that the caller's real positions would close.What
/me/apps's catches answer (read only, not changed here)Measured on the same harness shape:
catchanswers{"apps":[]}and logs[hono] /me/apps failedonce. That fails closed.catcharound the resolution (catch { failOpen = true; }) lists every app when the resolver throws synchronously or its accessor throws, includingbilling, which requires a capability nobody holds. It logs nothing. An async rejection keeps filtering, so onlyopenis listed. This is an observation, not filed; see the acceptance notes.Tests
New file
current-user-endpoints-outer-catch-closed.test.ts, on the same mount shape ascurrent-user-endpoints-delegated-resolution.test.ts: a bare Hono app, the real registrar, and a locator that throws for an unregistered slot.Pin, three throw sites inside the
try, after the caller is known:buildEffectiveObjectPermissionsthrows on a non-objectobjectsvalue, the one input its doc says it throws on;.catch(() => [])attaches;permissionSetResolver(ctx)throws while reading the method.Each site answers
200with the exact closed body and logs the warn line once.Pin: the closed body has the same key set as the success body.
CONTROL: the resolver rejecting still answers
systemPermissions: []with the session's positions (["org_member","everyone"], non-empty on purpose), and never reaches the outer catch.CONTROL: the degraded branch answers its open body, byte for byte.
CONTROL: a caller with no session gets
{"authenticated":false}.Ablation, run at
54bc11877a:scripts/ablation-replace.mjsput the old literal back at the outer catch. It ran insideos-verify-lock.sh, so the mutation existed only while the lock was held (11 s). The anchor went from 1 to 0 and the old literal from 0 to 1, and the blob changed fromf30ec90107aato8a61d5281761.Tests 4 failed | 3 passed (7). The three throw-site pins and the key-set pin went red, and the three controls stayed green. The diff for the first red shows exactly the six missing keys.f30ec90107aaagain andgit diff HEADis empty.dist/is involved: the test imports./current-user-endpointsfrom source.Base-against-head measurement (one-off; scratch files deleted): the success, resolver-rejection, degraded and anonymous bodies are byte-identical. Only the three throw sites changed, from the old body to the closed one.
Verification at
54bc11877apnpm --filter @objectstack/plugin-hono-server test:Test Files 29 passed (29),Tests 336 passed (336).pnpm --filter @objectstack/plugin-hono-server typecheck: exit 0, ending incheck:test-typecheck: OK ... 0 file(s) / 0 error(s). The test program lists 466 files, and the new test is counted in it.Gates:
node scripts/pm/dispatch-gates.mjs --commandsderived 65 commands at54bc11877a, the same 65 the claim's paths derive. I ran all 65 on the clean final tree, with each exit code captured before any pipe, and all 65 exited 0. Reconciliation:dispatch-gates --ranprinted65 derived famil(ies) accounted for — 65 run, 0 NOT-MEASURED (a DERIVED zero — all 65 recorded an exit code and none of them is 3). Lines worth naming:check:route-envelopeprintsexempt, closed at unenveloped 9: packages/plugins/plugin-hono-server/src/current-user-endpoints.ts.check:nul-bytesprintsOK (scanned 11073 text file(s) ... no raw ASCII control bytes).check:dual-build-cjs-loadsandcheck:lean-entry-closurewere measured, not refused: the workspacedist/was present aftercheck:type-check-debt's own build.The derivation names what sits outside the 65 and is CI's to run: 51 artifact-roster families, 10 wide-population families, 6 families that take a workflow value, 5 path-scheduled CI jobs and 4 type-check lanes. At the time of this report the tree is 6 commits behind
origin/main038d4c9588. None of those commits touchesplugin-hono-serveror these files. The one derivation input they change,scripts/check-verify-stand-in-erasure.mjs, only addspackages/verifyentries.Lint, narrowed:
pnpm lint(eslint . --no-inline-config) is CI's run. Locally I ran the same binary and flags over the touched files, with three pieces of evidence:eslint.config.mjs, whose config objects match**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}andpackages/**/*.{ts,tsx,mts,cts}. Both touched.tsfiles are in it. The changeset.mdis not.--format json, 3 results. 2 files were linted with 0 errors and 0 warnings. The.mdwas reported as "File ignored because no matching configuration was supplied".parserOptions.projectorprojectService; its own header says so). So this diff cannot move the verdict on any untouched file.Acceptance notes
/me/appsinnercatchfails open, silently, on a synchronous resolver throw or a throwing accessor (measured above). This is not filed: there is no real producer. SecurityPlugin'sresolvePermissionSetsForContextisasync(packages/plugins/plugin-security/src/security-plugin.ts:6804), so it rejects and never throws synchronously, and the published service object exposes a plain method. Carrier: none.check:route-envelopeblind spot: a body built by a helper in the same file and handed over as a call is counted as relayed, so it drops out of the ruled count. I handled it here by how the call sites are written. The gate is unchanged. Carrier: none.check:type-check-debtbuilds the whole workspace (turbo run build,scripts/check-type-check-coverage.mjs:3505) outside the verify lock. In this session it ran while an earlier ablation's mutation was on disk, and it rebuilt this package'sdist/from the mutated source. I found this by readingdist/, then rebuilt it and proved the old literal absent (ablation-dist-preflight.mjs --absent). The final ablation ran inside the lock, and every gate above was re-run afterwards on the clean tree. Carrier: none.Generated by Claude Code