Repository navigation
Description
Summary
The file-write endpoint PUT /api/agents/{name}/files enforces path_deny only by basename match on .env and config. The remaining 9 entries in the documented path_deny policy (.mcp.json, .credentials.enc, .ssh/*, /opt/trinity/*, etc.) are not evaluated. An authenticated agent owner can overwrite .mcp.json to inject arbitrary MCP tool definitions, then restart the agent to achieve root RCE inside the container and exfiltrate the per-tenant Anthropic OAuth token.
Context
AISEC (scan 3aad5469, 2026-04-28) demonstrated the complete chain on a live tenant:
PUT /api/agents/esc/files?path=.env → 403 "Cannot edit protected path: .env"
PUT /api/agents/esc/files?path=.mcp.json → 200 {"success":true} ← BYPASS
POST /api/agents/esc/stop → 200
POST /api/agents/esc/start → 200
POST /api/agents/esc/chat {"message":"x"} → 200
GET /api/agents/esc/files/download?path=content/m.txt
Body: uid=0(root) gid=0(root) groups=0(root)
cap_chown,cap_dac_override,...,cap_sys_chroot,cap_sys_ptrace,...
Reading /proc/1/environ then extracted:
CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-FM_... ← per-tenant Anthropic billing token
TRINITY_MCP_API_KEY=trinity_mcp_nt_t62_... ← platform MCP key (different prefix)
Why the prior fix (#183) did not close this:
UnderDefense issue #183 "Arbitrary File Write via Credential Injection Parameter Tampering" was marked [Fixed] on 2026-04-23. That fix added basename-matching for .env and config. The guardrails-runtime.json path_deny list contains 11 entries; only the first 2 are checked. The sibling credentials/inject endpoint also accepts {"files":{".mcp.json": "<attacker JSON>"}} without the basename check.
CVSS 9.9 (AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H), CWE-22 + CWE-94.
Acceptance Criteria
-
PUT /api/agents/{name}/filespath validation is driven by the samepath_denylist thatguardrails-runtime.jsonloads — not a hardcoded 2-entry subset - Path check uses canonical-path containment under an allow-list (
/home/developer/content/**) rather than basename matching -
POST /api/agents/{name}/credentials/injectrejects any filename that resolves outside/home/developer/content/or matches the deny list - Runtime config files (
.mcp.json,.credentials.enc,template.yaml) are moved to a path not writable by the agent owner (e.g.,/opt/trinity/only writable by root/platform) - Unit test: assert
PUT /files?path=.mcp.jsonreturns 403; assertcredentials/injectwith{".mcp.json": "x"}returns 403
Technical Notes
routers/agent_files.py— thePUT /fileshandler; look for the basename checkrouters/credentials.py—POST /credentials/injectalso writes files; needs the same deny-list enforcement- The current
path_denyinguardrails-runtime.jsonis the right source of truth — wire both endpoints to read from it at startup - Privileged container capabilities (
cap_dac_override,cap_sys_ptrace, etc.) are a separate hardening concern; address in a follow-up
Activity
pavshulin commentedon Apr 29, 2026
/claim
github-actions commentedon Apr 29, 2026
Claimed by @pavshulin. Label
status-in-progressadded.Next steps:
feature/590-<short-slug>Fixes #590test(security): integration tests for #590 AISEC-C2 bypass closure
sec(files): close .mcp.json RCE-by-config bypass (AISEC-C2, #590)
test(security): integration tests for #590 AISEC-C2 bypass closure
sec(files): close .mcp.json RCE-by-config bypass (AISEC-C2, #590)
sec(mcp): structure-validate .mcp.json content (AISEC-C2 Layer 2, #598)
sec(mcp): structure-validate .mcp.json content (AISEC-C2 Layer 2, #598)
Merge branch 'origin/dev' — resolve feature-flows + registry conflicts
vybe commentedon Jun 1, 2026
Shipped in v0.6.0 (released via #998).
feat(credentials): curated credential file-type injection (SA keys, c…
Release: v0.8.0 (#1529)
fix(agent): render .mcp.json.template at startup so declared MCP serv…
fix(agent-server): remove the unreachable /api/credentials/update end…