Repository navigation
fix(dashboard): attest a session key before member scope trusts it - #12164
Conversation
|
Intent: Close a same-host impersonation hole: |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify the [DESIGN-REVIEWED] 1a2a5a6 |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The declared breaking change is the one residual: any out-of-tree internal caller sending only secret + bare The defect has checkable provenance: the base diff shows What this change shipsInventory (8 items) — 8 justifiedIntent: FIX — stop a same-host process holding the internal secret from impersonating another session by replaying its key.
[FIRST-PRINCIPLES-REVIEWED] 1a2a5a6 |
Opus 4.8 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
1d5c076 to
d660c36
Compare
|
self-added: yes
|
|
d660c36 to
de434f1
Compare
|
self-added: yes
|
de434f1 to
2fb3b7b
Compare
|
f35947b to
ab9cdeb
Compare
|
self-added: yes
|
|
member_request_scope read the caller-supplied X-Session-Key as the authenticated identity whenever the request carried the internal secret, so any same-machine process holding that secret could name another session's key and act inside that session's scope. The declared key is now accepted only behind one of the two transport attestations the sibling memory path already requires: the unix-socket kernel peer attestation, or a signed per-session token that verifies back to that same key. Both live in one shared helper, member_memory_auth.session_key_is_attested, so the two authorization sites answer the same question the same way. An unattested key yields an unverified scope, which the callers turn into their established 409 member_identity_unavailable / 403 refusals, and the canonical execution record is never read on a name the caller merely asserted. Two legitimate callers lacked an attestation, and both get a real one rather than an exemption. Script crons had neither: no signed pid mapping names a sandbox launcher's pid, so the peer walk cannot vouch for them. Their launcher now mints a stub session token for cron:<job id> and publishes its signed mapping before the spawn. One token per run: the mapping lives exactly as long as the run and is retracted in the run's finally, on every exit path including the early overlap return and the spawn exception, so completed runs leave nothing behind. retract_session_token is a thin public wrapper over the module's own removal primitive. Internal requests attached the token on one verb only. The gateway's session-scoped READS authorize on the declared key the same way the writes do, so _get / _patch / _put / _delete and the hand-built tool-policy request now carry it too. That read is why this matters: an unresolved managed tool policy fails closed, so a missing header there took out a session's whole tool surface rather than one call. The header now has one definition, session_token_sig.session_token_header, beside the verifier that reads it.
ab9cdeb to
1a2a5a6
Compare
|
Rebased onto 954fb69; CI re-running. Not a content change. |
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed against the pr-triage-pipeline gates plus a full-diff security audit.
fix(dashboard), 21 files. Stops member_request_scope and memory_request_identity from treating a caller-declared X-Session-Key as the authenticated member identity whenever the request carries X-Internal-Secret. The declared key is now trusted only if session_key_is_attested() confirms it.
Security-flagged Tier 2: three checklist answers YES (modifies_auth_or_authz, modifies_trust_boundary, adds_or_changes_secret_handling). Worth recording that the security-path denylist does NOT match this diff even though it is an auth change: member_memory_auth.py is not a token_auth* prefix, dashboard/handlers/_shared.py is not the denylisted handlers/session*, and session is a domain noun. The checklist caught it, not the path gate.
[Security: the risk is not realized by this change, it is closed by it. Before, the internal secret only proved 'came through the local gateway', so any same-machine process holding it could read another session's key off a transcript, declare it, and act inside that session's V2 member scope, reading and writing private member memory and parking directives. That is horizontal session impersonation across the internal trust boundary. After, attestation requires one of two channels that both bind the request to the key's true owner: request['peer_verified'], the kernel AF_UNIX peer attestation set server-side by middleware and unsettable via any header; or a signed X-Session-Token that must HMAC-verify against the SEL trust root AND map to that specific declared key. A caller holding only the internal secret plus a stolen key name has neither. A caller holding its own valid token cannot use it against a victim, pinned by test_token_naming_another_session_attests_neither, so there is no confused deputy. The residual is classic bearer-token replay by a process that can already read another process's environment or capture its loopback traffic, which exceeds the threat this fix targets; cron tokens are retracted in the run's finally on every exit path, bounding their window to the run. Fail-closed: attestation runs before the canonical read_session_execution, so the record is never read on an unattested name, and unattested resolves to MemberScope(session, False, None) yielding the established 409 member_identity_unavailable or 403. Legitimate members are migrated rather than exempted: script crons mint and publish a per-run stub token, and the mcp_core read verbs plus the mcp_shared tool-policy request now attach the token, closing the availability hole where a token-less read would leave a managed tool policy unresolved and fail-closed the whole tool surface. The blocking file I/O in the token branch runs via asyncio.to_thread, so there is no event-loop-blocking regression.]
One non-blocking follow-up: confirm no other internal route grants member scope off a bare X-Session-Key outside member_request_scope, memory_request_identity and internal_memory_scope. Those three plus the updated test surface were verified; every route was not exhaustively enumerated.
Problem / Motivation
Any program on the machine that knows the gateway's internal secret could act as another chat session. It read a victim's session key out of
~/.kiro/crew/sessions/*.jsonl, sent that key in theX-Session-Keyheader, andmember_request_scopebelieved it. The caller then got that session's memory store, its chat controls, its spawn and directive routes.Why it matters
This is the impersonation boundary between two agents on one host. A member's private memory is supposed to stay private from other members, and the chat-control refusals are supposed to hold per session. Both rest on
member_request_scopeanswering "who is calling" correctly. The sibling path for the same question,memory_request_identity, already demanded proof; this one took the caller's word.What changed (motivation → approach → change)
A header is a claim. Proof is what the two attestation channels carry, and
member_request_scopenow asks for one.X-Session-Keypeer_verified(unix-socket kernel attestation)X-Session-Tokenthat verifies to that keyRoot cause: the member-memory refactor moved scope resolution out of
member_memory_auth.memory_request_identityand into a new_resolvein_shared.pythat read the header directly. The gate did not come with it.The check now lives in one place,
session_key_is_attestedinmember_memory_auth.py, and both authorization sites call it, so the two cannot drift apart again. An unattested key returns an unverified scope, which existing callers already turn into 409member_identity_unavailableor a 403. The execution record is not read at all on a name nobody vouched for.Two legitimate callers had no attestation to offer, and both get a real one rather than an exemption.
Script crons had neither channel: nothing publishes a signed pid mapping for a sandbox launcher's pid, so the kernel peer walk cannot speak for them. Their launcher in
cron_script.pynow mints a stub session token forcron:<job id>and publishes its signed mapping before the spawn, using the primitives every ACP session already uses. One token per RUN: its mapping lives exactly as long as the run and is retracted in the run'sfinally, on every exit path including the early overlap return and the spawn exception, so completed runs leave no mapping behind and there is no cache to bound and nothing to orphan.Internal callers attached the token on one verb only. The gateway's session-scoped reads authorize on the declared key exactly as the writes do, so
_get/_patch/_put/_deleteinmcp_core.pyand the hand-built tool-policy request inmcp_shared.pynow carry it too. That read is the one that bites: an unresolved managed tool policy fails closed, so a header missing there darkened a session's whole tool surface rather than one call. The header has one definition now,session_token_headerinsession_token_sig.py, beside the verifier that reads it.Backwards compatibility
Breaking: a request carrying only the internal secret and an
X-Session-Keyno longer resolves to that session. Writer sweep re-run on fresh origin/main @ 954fb69:X-Session-Token, now on every verbpeer_verifiedScriptContext._postto/api/send-messageTests
test_member_memory_auth.pypins the four outcomes of the new gate, including that the canonical record is never read for an unattested key.test_session_token_header_parity.pydrives every transport helper and the tool-policy read for real and fails if one declares a key without the token, which is the defect class that took out the tool surface; it fails on a reverted_getand passes with it.test_directive_queue.pypins the 409 at a real route and that nothing is parked.test_cron_script_identity.pypins that the child's env carries a tokenverify_session_token()maps back to that job, that two jobs get different tokens, that a second run republishes one mapping instead of adding one, that an inherited token is overwritten, that two runs of one job get different tokens and leave no mapping, and that the mapping is retracted on the exception and early-return paths too;test_session_token_sig.pypins that retracting removes the file, drops the identity, and no-ops on an empty or unknown token. Eleven existing internal-caller doubles across seven files now carry an attestation, because a double without one is refused for a transport reason and stops measuring what it was written for.Manual verification
The
E2E (stub ACP backend, offline)lane is the end-to-end proof and runs in CI; this host has no usable sandbox backend (unshare(CLONE_NEWUSER)returns EPERM), so it cannot run locally and the parity test covers the same mechanism at the unit level instead.Related Issues
no linked issue: this is a regression found by code audit rather than a filed report. The refactor that dropped the gate is #11780.
Pattern harvest
Rule candidate: review-prompt
Pattern: one half of a two-part contract wired at some call sites and not others — an authorization decision that reads a caller-supplied identity while a sibling path requires proof of it, and a proof header attached on one verb while the others send the same claim bare.
Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)