Repository navigation
fix(core): a signed-in request reads its session once with the rate limiter armed or a gate active on REST - #35703
Conversation
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me
…nit pins Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me
… middleware The Hono transport now runs its middleware chain in a session-read scope of its own and hands that scope to a route it registered only when every handler between the two is a whole-server middleware. A route behind a path-scoped middleware (the auth mount's door, which carries the request's address to the session reads behind it) and a raw-app route read for themselves, and every request starts outside any scope, so a request served in process inside another never reaches the outer one's reads. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me
…d request does Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me
… does Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me
📓 Docs Drift CheckThis PR changes 3 package(s): 5 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 1 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 59 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 4a3c0099629fcd81d91caf72f6f37438c0ca885c && git checkout 4a3c0099629fcd81d91caf72f6f37438c0ca885c
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 238661f47f3937c0cd79cebade410141763775ec a78bdd775da709fbcd12a901c75d59b686965103 && git checkout -B drift-repro 238661f47f3937c0cd79cebade410141763775ec && git merge --no-ff a78bdd775da709fbcd12a901c75d59b686965103
node scripts/docs-audit/affected-docs.mjs --json 238661f47f3937c0cd79cebade410141763775ec
|
|
repo:objectstack#5 · os-bill · session_01Utp6CXsZsKmgG1EcKp5bY4 维护者速读
席位核对L1-a: ACCEPT, three items before queueing · head What it is. A request-scoped Safety read. I read the module, the grants-memo helpers and the adapter seam.
Nothing here is a security finding. Pins. R1: CI green on this head. At this reading: 22 success, 11 skipped, 32 in progress. REST's full suite last ran green locally on R2 (text only): claim amendment. Claim 7024841348 names the carrier "beside"
One amendment line on #35606 closes it. R3 (text only): correct the PR body's BASE reverse figures to the final run: 10 red / 16 green of 26, with (d) at BASE 1/1/1. The body still quotes the earlier 11 / 14 of 25. For the seat (no L1 item).
Routing. Clause-② no, no |
|
repo:objectstack#5 · os-bill · session_01Utp6CbUb7TcZK1XUAddUmQ Seat ruling on the A/B choice (#35606), ahead of landing. A stands (the shipped behaviour): a route may reuse the seam's session read across whole-server Why A: no whole-server middleware changes the session read's ambient state today, and B would give back the one-read win on root-domain hosts to guard against a middleware that does not exist. Condition, in this PR: add the one-line note to the hono middleware docs saying that whole-server Semver: Recorded at 2026-11-20T00:55Z. |
…sion-read state The middleware seam's session read is reused by routes past whole-server middleware, so such middleware must leave the read's inputs alone. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me
|
repo:objectstack#5 · os-bill · session_01Utp6CZiaBg6rk7dpy1s9Me Landing · head
Status: |
Requested by Bill · project thread
repo:objectstack#5 · os-bill · session_01Utp6CZiaBg6rk7dpy1s9Me
Fixes #35606
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
One request-scoped session-read carrier in core, in the shape of the request-grants memo, that the inbound rate limiter, the identity step of every door and REST's
reread-when-activegate read through, so one signed-in request reads its session once.packages/core/src/security/request-session-read.ts(new). AnAsyncLocalStoragescope (openRequestSessionRead/withRequestSessionRead/withoutRequestSessionRead/readRequestSession, exported from@objectstack/core). A stored read is served to a later reader of the same request only when: same auth session API object and every header equal (the read's input is decided by those headers); no engine write has landed or is in flight since the read opened (engine write epoch + the grants memo's write observer:engineWriteMark/engineWritesQuietSince, added torequest-grants-memo.ts); the session has not expired. A read that throws is never stored, so each reader keeps its own outage answer. Served values are clones. A scope closes when its request settles; nothing survives a request.request-execution-context.ts.resolveRequestExecutionContextjoins the scope open where it runs (or opens one for its own call), and its session arm (readSession) anddecideAuthGate(reread-when-active) both read through the carrier.readWriteEpochis now exported from its module for the carrier.resolveSessionPrincipalId/resolveSessionDataread through the carrier with the engine the auth service reads through (dispatcher-plugin.tspassesobjectql).adapter.ts). The middleware seam runs its chain in a scope of its own (the limiter's read) and hands that scope to the route it serves only when the route was registered throughIHttpServerand every handler Hono ran between the seam and the route is a whole-server middleware (matchedRoutes,/*). A route behind a path-scoped middleware or a yielding route, and every raw-app route, read for themselves. Every request starts outside any scope (withoutRequestSessionRead), so a request served in process inside another never reaches the outer one's reads. The seam and the route now share one header reading (readRequestHeaders,hostbackfilled from the URL), so their keys agree.Headers; nothing attached to either object reaches the other or core. The Hono context is used only to hand the seam's scope handle to the route of the same request (aWeakMapkeyed by the context, deleted when the route answers).Per door and posture, warm request,
getSession/sys_sessionby token /sys_userby id, real kernel:03865ae995GET /api/v1/packagesGET /api/v1/data/pin_noteGET /api/v1/auth/client-address(control)Who is admitted or refused, and with which status, does not change.
Tests
packages/runtime/src/http-dispatcher.session-read-once.pin.test.ts(rewritten, real kernel: ObjectQL + sqlite-wasm + Hono + AuthPlugin + SecurityPlugin + REST + dispatcher; three kernels: gate, limiter, both). ⭐ one read on (a)(b)(c) for each door. CONTROLS: held session 403 with the posture code (both doors), revoked 401, anonymous 401 with nosys_sessionstatement, concurrent requests with two tokens each get their own answer on one read each, limiter still keys by principal and refuses over budget (30 x 403 then 429 withretryAfterSeconds, decided on one read; another principal untouched), a failing read keeps its outage answer (REST 401 / dispatcher 503SERVICE_UNAVAILABLE, never served), a failing limiter read is not served (route reads afresh), a revocation landing between the limiter's read and the route's is seen (401 both doors), and the auth-mount control above. 26/26 green at655c4e2399.packages/plugins/plugin-hono-server/src/session-read-scope.pin.test.ts(new, real Hono app): route past whole-server middleware is served the seam's read; a route behind a path-scoped middleware reads for itself inside that middleware's ambient state; a route behind a yielding route reads for itself; a raw-app route reads for itself; a request served in process inside a route reads for itself. 5/5.packages/core/src/security/request-session-read.test.ts(new): served/clone, isolation (no scope, other headers/API, interleaved scopes, continuation after close, join, handle across stretches,withoutRequestSessionRead), freshness (write landed, write in flight, non-write epoch bump, expired, throw not stored, unwatchable engine). 15/15.Reverse verification and ablations (one-off; nothing left in the tree)
03865ae995(runtime/core/hono sources reverted, pin file kept) the final runtime pin file (26 tests) went 10 red / 16 green: every ⭐ and every one-read control red, e.g.expected { getSession: 3, sys_session: 3 } to deeply equal { getSession: 1, sys_session: 1 }on (c) REST.seamReadsReachRouteanswering true), viascripts/ablation-replace.mjs(anchor 1 to 0, blob0da067a3ecffto29dc9cac98bb): the path-scoped-middleware and yielding-route pins go red (2 failed / 3 passed); restored, blob equals HEAD,git diff HEADempty.9244357e1a, rebuilt,ablation-dist-preflightconfirming the marker absent fromplugin-hono-server/dist): the auth-mount control goes red,expected 1 to be 2(the limiter's read answered the reader behind the door). Restored, hashes equal HEAD, rebuilt, preflight confirms the marker back indist/.Acceptance notes
use('*')) registered after the seam that changed a session read's ambient state would defeat it. None does in the tree (the only such state is plugin-auth's door, path-scoped). Stated in the carrier's docblock./auth/me/*endpoints), with the limiter armed, still read twice (limiter + route).@objectstack/core:openRequestSessionRead,withRequestSessionRead,withoutRequestSessionRead,readRequestSession, typesRequestSessionRead,RequestSessionReadHandle. Module-level exports (not re-exported from the index):readWriteEpoch,engineWriteMark,engineWritesQuietSince,EngineWriteMark.Verification
Read first, by risk:
packages/plugins/plugin-hono-server/src/adapter.ts:seamReadsReachRoute, the middleware seam's scope (open, run chain, hand off, close afternext()), andsessionReadScopeForRouteinwrap.packages/core/src/security/request-session-read.ts:readRequestSession(serve rule, store rule) and the residuals in the docblock.packages/core/src/security/request-execution-context.ts: thejoinRequestSessionReadwrapper and the two consult points.Two-minute check:
pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/http-dispatcher.session-read-once.pin.test.ts→Tests 26 passed (26)(needs@objectstack/plugin-hono-serverbuilt).Local runs at 655c4e2
@objectstack/coreexit 0,@objectstack/plugin-hono-serverexit 0,@objectstack/runtimeexit 0 (check:test-typecheck: OK).@objectstack/corevitest run --project local: 154 files, 3670 tests passed.@objectstack/plugin-hono-servervitest run: 43 files, 581 tests passed.@objectstack/runtimevitest run --project local: 631 files, 11649 passed, 25 skipped.node scripts/pm/dispatch-gates.mjs --commands, 76 commands): all 76 exit 0;node scripts/pm/dispatch-gates.mjs --ranwith recorded exit codes: "76 derived, 76 run, 0 NOT-MEASURED, 0 UNRUN" (a derived zero).check:nul-bytesOK.node scripts/pm/check-governed-merges.mjs --branch HEAD: 0 of 12 paths hit the register, NOT governed; +1383 / -137.node scripts/pm/overlap-check.mjs --branch=claude/issue-35606-request-session-read-memo: merges cleanly with origin/mainc03a8a3428, 0 PR heads;VERDICT clean exit 0.test:repo,pnpm lintand the full farm: CI.Generated by Claude Code