Repository navigation
fix(security): X-Source-Agent is authoritative only for a principal that can prove it names itself (abilityai/trinity-enterprise#614) - #2788
Merged
Conversation
…hat can prove it names itself (Abilityai/trinity-enterprise#614) `X-Source-Agent` is a raw client header that decides `triggered_by='agent'`, the AGENT_COLLABORATION activity and its WebSocket edge, the execution row's `source_agent_name`, and the actor on three SEC-001 audit sites. Its only check — SELF-EXEC-001 — was gated on `current_user.agent_name`, so it fired only for the agent-scoped keys that cannot lie anyway and never for a human, and its single caller was `/task`, leaving `/chat` and `/fan-out` unchecked. A permitted user could therefore record their own action as performed by any agent they named, with their identity dropped and the hash chain certifying the row, and could forge collaboration activity on an agent they cannot access. Third occurrence of this class (#1672, ent#265), so the repair is the gate rather than a fourth endpoint patch: - `dependencies.resolve_source_agent` honours the header only for an agent-scoped key naming its own agent or the event loopback's backend-vouched source, and refuses every other principal with a named 403. Allowlist over identity, so a scope invented later is refused by construction. - All six readers route through it. `/chat`, `/task` and `/fan-out` rebind the parameter so the raw value is unreachable downstream; loops, reminders and the manual schedule trigger resolve first and then prefer the validated key, since the MCP client sends no header on those paths. Resolving is never placed behind an `or` — that short-circuit would silently ignore a mismatched header. - The EVT-001 loopback proves itself with a `scope=event_loopback` claim in its SECRET_KEY-signed JWT, surfaced as `User.vouched_source_agent` and fenced to `POST /api/agents/{name}/task`; it was an unrestricted five-minute admin bearer. It vouches only for agent-originated events: `emit_event` writes a human's username into the event's source, and `emit_event_for_agent` is gated on read access, so neither may be certified as an agent. - Audit rows keep their shape and the agent branch gains the key owner's email plus, on fan-out replay, the presented credential — an agent row now joins back to a person. - The MCP schedules tool gates the header on agent scope like the chat tool. Behaviour changes: a non-agent principal sending the header now gets a 403 where it was silently trusted; an agent key naming a sibling gets a 403 on five routes; agent-started loops now record their origin; a human-emitted event no longer attributes its subscriber's execution to a phantom agent. Verified on a live instance: the reported exploit returns 403, the same call without the header is unchanged, an agent key naming itself is honoured, a sibling name is refused, and the resulting audit rows carry the agent together with its owner's email. Docs: the rule in security.md, the loopback in execution.md, IA-01's trust-boundary note closed, five feature flows, the demo recipe that taught the forbidden shape, and a learnings entry for the class. Refs Abilityai/trinity-enterprise#614 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Resolves the PR's conflict. One real conflict, in `docs/memory/learnings.md`: both sides appended a 2026-09-14 entry at the tail of the append-only ledger, so both are kept, dev's first since it landed first. `security.md`, `models.py` and `tests/registry.json` auto-merged and were verified rather than assumed: dev's `models.py` hunk adds fields to a different model, `registry.json` still parses with both entries and no duplicate, and the ent#614 paragraph in `security.md` is intact. No migrations in the incoming range, so the merge applies no schema change (backup taken regardless). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
vybe
approved these changes
Sep 14, 2026
vybe
left a comment
Contributor
There was a problem hiding this comment.
Validated via /validate-pr (Lane C) and /cso --diff: zero findings at the gate, 404 touched tests pass locally at head, all 25 CI checks green. One latent appendix item (loopback principal's actor_email on the agent audit branch is the admin user, unreachable today because the loopback sends no Idempotency-Key) — follow-up, not a blocker. Report: docs/security-reports/cso-diff-2026-09-14-1702-source-agent-attribution.md
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
X-Source-Agentis a raw client header, and its only check (SELF-EXEC-001) was gated oncurrent_user.agent_name— so it fired only for the agent-scoped keys that cannot lie anyway, never for a human — and its single caller was/task, leaving/chatand/fan-outunchecked. A permitted user could record their own action as performed by any agent they named, with their identity dropped and the hash chain certifying the row, and could forge anAGENT_COLLABORATIONactivity plus a WebSocket edge on an agent they cannot access.Changes
The gate —
dependencies.resolve_source_agent(allowlist over identity, so a scope invented later is refused by construction; the falsy check precedes anygetattr, and thegetattrdefault is the unprivileged one).The six readers —
/chat,/taskand/fan-outrebind the parameter so the raw value is unreachable downstream.loops,remindersand the manual schedule trigger resolve first and then prefer the validated key, because the MCP client sends no header on those paths (a header-only resolution would have wiped the origin of every agent-created reminder). The resolve call is never placed behind anor— that short-circuit skips the check for an agent principal and silently ignores a mismatched header, which is the failure mode this fix exists to end.The event loopback — proves itself with a
scope=event_loopbackclaim in its SECRET_KEY-signed JWT (narrower thanINTERNAL_API_SECRET, which the scheduler and MCP server also hold), surfaced asUser.vouched_source_agentand fenced inget_current_usertoPOST /api/agents/{name}/task; it was previously an unrestricted five-minute admin bearer. It vouches only for agent-originated events —emit_eventwrites a human caller's username into the event's source, andemit_event_for_agentis gated on read access, so neither may be certified as an agent.Audit rows — shape unchanged, and the agent branch gains the key owner's
actor_emailplus, on the fan-out replay row, the presented credential. An agent row now joins back to a person, which the issue's walkthrough called out as missing.MCP server —
tools/schedules.tsgates the header onscope === "agent"liketools/chat.ts; it was the one tool sending it for system-scoped keys too.Behaviour changes
source_agent_nameNULLsource_agent_namefrom the headerDeploy note: the backend refusal and the MCP tool change ship together in one compose build. A partial update that moves the backend alone would 403
trigger_agent_schedulefrom a system-scoped key until the MCP image is rebuilt.Test Plan
cd tests && pytest unit/test_ent614_source_agent_attribution.py -v— 92 tests: the helper matrix over eight principal kinds, the three dispatch routes end-to-end, the three attribution-only routes, the loopback JWT round-trip and its route fence,trigger_subscription's vouching in both directions, and the AST guard with self-tests that judge it in both directions.actor_type=agentwith the owner's email on the agent branch, andactor_type=useron the human branch.Docs
architecture/security.md(the rule),architecture/execution.md(the loopback), the IA-01 trust-boundary note (its one false-positive source is closed), five feature flows,AGENT_NETWORK_DEMO.md(its curl recipe taught the exact forbidden shape), and alearnings.mdentry for the class.Journey Impact: none — trust-boundary fix on existing endpoints; J10 drives agent-scoped keys and is unaffected.
Fixes abilityai/trinity-enterprise#614
Reviewer note on that reference: it is deliberately fully qualified, and the bare same-repo form must not be substituted for it. Public
abilityai/trinity#614is an unrelated merged frontend refactor, andissue-status-on-merge.ymlmatches a closing keyword followed directly by a plain number — so the unqualified spelling would stampstatus-in-devon that item while leaving the real issue stranded. The qualified form deliberately does not match that pattern. Since both the closing keyword and the promotion workflow are same-repo only, this PR neither closes nor relabels the private issue: setstatus-in-devon it by hand after merge, and close it at the release cut.🤖 Generated with Claude Code