Repository navigation
fix(runtime): a signed-in request reads its session once when an authentication policy is on - #35598
Conversation
… instead of reading the session again The dispatcher's ADR-0069 gate and the declared-endpoint fallback's principal lookup and gate re-read the session for a principal the request's own session read had already admitted. They now take the user id and posture the identity step recorded off that read, so one request reads its session once. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me
…declared-endpoint request 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
…ler the identity step did not admit Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me
…dispatcher test files Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CZiaBg6rk7dpy1s9Me
📓 Docs Drift CheckThis PR changes 2 package(s): 17 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 1 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 58 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 a50cd2088765218e2771326af4f393186a637dcb && git checkout a50cd2088765218e2771326af4f393186a637dcb
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin e35cf03556600d8dc4f065575fe40aeeade84274 805709420a999120f7572d0bcd84a627c6540356 && git checkout -B drift-repro e35cf03556600d8dc4f065575fe40aeeade84274 && git merge --no-ff 805709420a999120f7572d0bcd84a627c6540356
node scripts/docs-audit/affected-docs.mjs --json e35cf03556600d8dc4f065575fe40aeeade84274
|
|
repo:objectstack#5 · os-bill · session_01Utp6CZiaBg6rk7dpy1s9Me Final green head for L1: Checks at this head: 57 success, 11 skipped, 0 failed. Not governed ( Scope: Part of #35457, the gate half. With a session gate active, a dispatcher request now reads the session and the user once (was 2 each), and a declared endpoint reads once (was 3). The auth gate and the declared-endpoint fallback reuse the identity step's own read of this request; nothing is cached across requests. Pinned on a real kernel: the counts, plus held 403, revoked 401, anonymous 401 and 8 interleaved requests over two tokens. Reverse verification: 5 red at the base implementation. Two comment-only edits in |
|
repo:objectstack#5 · os-bill · session_01Utp6CXsZsKmgG1EcKp5bY4 维护者速读
席位核对L1-a: ACCEPT, with one required item before queueing · head Readings, my own.
The auth gate, read closely: the posture is the same value, not a new one.
Pins (names grepped).
R1 (required before queueing): amend the claim for Declaration: agreed.
"Part of" is right: the limiter and REST halves are #35606, and the REST double read is in the body's acceptance notes. Routing. Not governed and no contract face. ux-3 lands it after R1. |
|
repo:objectstack#5 · os-bill · session_01Utp6CZiaBg6rk7dpy1s9Me Landing · head
Status: |
Requested by Bill · project thread
repo:objectstack#5 · os-bill · session_01Utp6CZiaBg6rk7dpy1s9Me
Part of #35457 — this lands the gate half (the ADR-0069 gate and the declared-endpoint policy chain stop re-reading a session the identity step already read). The inbound rate limiter's read stays, because sharing it needs a per-request carrier in the HTTP transport, outside this claim's file surface (see Acceptance notes).
Clause-②: no
Metadata-protocol: none
维护者速读
What changes
Re-measured at
origin/main97f3420 on a real kernel (sqlite-wasm, realAuthPlugin, Bearer session, warm), getSession calls /sys_session-by-token statements per authenticated request:/api/v1/packages,/i18n/locales)/api/v1/data/...)HttpDispatcher.enforceAuthGate,http-dispatcher.ts:1665)decideAuthGatere-read)server.security.rateLimitarmedresolve-session-principal.ts:64, viadispatcher-plugin.ts:911) + identityresolvePrincipalId+readGatedSessionUser)Each getSession costs the session's token lookup, the session user's row and the grants resolution behind
customSession.security/admitting-credential.ts:sessionAdmittedPrincipal(request)— the user id and ADR-0069 posture the identity step recorded off the request's OWN session read (context.admission+ the resolved envelope).undefinedfor an anonymous caller, an API key, an OAuth access token or forward credential, and an identity step that degraded after the read; each of those keeps the read it had.HttpDispatcher.enforceAuthGate: after theisAuthGateActive()probe, a session-admitted principal is judged by that posture — no second read. The carrier is the existing per-requestHttpProtocolContext; nothing is cached across requests.dispatcher-plugin.tsdeclared-endpoint fallback:resolvePrincipalIdandreadGatedSessionUseranswer a session-admitted principal from the same record (readGatedSessionUserkeeps its probe first, so an inactive gate still answersundefined).packages/core(request-execution-context.tsdoor table,assemble-execution-context.tsfield doc) that said the dispatcher re-reads the session.After: gate active, one dispatcher request reads the session once (2 to 1); a declared endpoint reads it once (3 to 1). Session controls (revocation, idle/absolute timeout) run inside that one read, as before; the IP allow-list is a transport middleware on the auth routes and is untouched.
Tests
http-dispatcher.session-read-once.pin.test.ts(real kernel,passwordExpiryDays: 365so the gate is active): one warm request = 1sys_sessiontoken lookup and 1 better-authsys_userlookup. Controls: a held session (administrator-issued password change) is still 403PASSWORD_RESET_REQUIRED; a revoked session (row deleted) answers 401; an anonymous request answers 401 and issues nosys_sessionstatement; 8 interleaved concurrent requests with two tokens each get their own answer (200/403) and their own single read.dispatcher-plugin.endpoint-fallback.integration.test.ts, new top-level describe: a declared endpoint with the gate active is served on ONE getSession; a held session is still 403 with its code on one read; anonymous still 401; concurrent callers keep their own answers.http-dispatcher.auth-gate-outage.pin.test.tsCASE 2: its "an active gate reads once more" control now measures that on a caller the identity step did not admit (the gate still reads for it), and adds that a session-admitted principal costs no extra read, active or not.Reverse verification (one-shot, implementation reverted to 97f3420, tests at HEAD)
git restore --source=97f342037d -- packages/runtime/src/http-dispatcher.ts packages/runtime/src/dispatcher-plugin.ts, then the two pin files: 5 failed / 26 passed.expected { sys_session: 2, sys_user: 2 } to deeply equal { sys_session: 1, sys_user: 1 }(warm request, and each concurrent request)expected [ 'admin1', 'admin1', 'admin1' ] to deeply equal [ 'admin1' ](declared endpoint, 3 reads)Restored with
git checkout HEAD -- …;git diff HEADempty and both blob hashes match HEAD.Local runs
pnpm --filter @objectstack/runtime typecheck(tsc + check:test-typecheck) exit 0;vitest run --project local628/629 files, 11607 passed, 1 failed (the CASE 2 control above, since updated); the three edited/new files re-run at the final head: 3 files, 40 tests passed.dispatch-gates --commandsderived 73 families: 72 exit 0,check:dual-build-cjs-loadsexit 3 PREREQUISITE NOT MET (needs a fullpnpm build; NOT MEASURED locally, CI runs it).check:test-source-aliasfirst exit 1 (two edited test files reached a lazy@objectstack/metadataload), fixed with a module-top import, exit 0 at the final head with the other ratchet families.overlap-checkclean; full dogfood not owed (no!, no narrowing arm).Acceptance notes
server.security.rateLimitarmed, the inbound limiter reads the session in a transport middleware before every route. The Hono adapter's middleware seam runs the whole middleware chain to completion and only then calls the route, with a separate request object and no shared async scope, so nothing inpackages/runtimecan hand the limiter's read to the route without a cross-request cache (ruled out). It needs a per-request carrier at the transport (plugin-hono-server's seam) or a core-owned request memo that every door's session read consults.decideAuthGate(authGate: 'reread-when-active') each read the session: 2 reads per/api/v1/datarequest. Fix lives inpackages/core/packages/rest, outside this claim.test-budgetdeclared (no CI reading yet).Verification
Files to read first:
packages/runtime/src/http-dispatcher.ts(enforceAuthGate, thesessionAdmittedPrincipalbranch),packages/runtime/src/security/admitting-credential.ts,packages/runtime/src/dispatcher-plugin.ts(fallbackresolvePrincipalId/readGatedSessionUser).Two-minute check:
pnpm --filter @objectstack/runtime exec vitest run --maxWorkers=2 src/http-dispatcher.session-read-once.pin.test.ts— expect 6 passed, includingreads sys_session once and the session user once.Generated by Claude Code