Skip to content

SEC: PUT /api/agents/{name}/files guardrail bypass → .mcp.json write → RCE and Anthropic token exfiltration (AISEC-C2) #590

Closed

Description

@vybe

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}/files path validation is driven by the same path_deny list that guardrails-runtime.json loads — 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/inject rejects 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.json returns 403; assert credentials/inject with {".mcp.json": "x"} returns 403

Technical Notes

  • routers/agent_files.py — the PUT /files handler; look for the basename check
  • routers/credentials.py — POST /credentials/inject also writes files; needs the same deny-list enforcement
  • The current path_deny in guardrails-runtime.json is 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

  1. added
    priority-p0
    security
    pentest
    on Apr 29, 2026
  2. pavshulin commented on Apr 29, 2026

    @pavshulin
    Contributor

    /claim

  3. github-actions commented on Apr 29, 2026

    @github-actions

    Claimed by @pavshulin. Label status-in-progress added.

    Next steps:

    1. Create branch: feature/590-<short-slug>
    2. Implement the feature
    3. Open a PR with Fixes #590
  4. added
    status-in-progress
    on Apr 29, 2026
  5. added a commit that references this issue on Apr 30, 2026
  6. added
    status-in-dev
    and removed
    status-in-progress
    on Apr 30, 2026
  7. vybe commented on Jun 1, 2026

    @vybe
    ContributorAuthor

    Shipped in v0.6.0 (released via #998).

  8. added
    complexity-low
    theme-security
    and removed
    status-in-dev
    on Jun 1, 2026
  9. added a commit that references this issue on Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complexity-lowpentestpriority-p0securityseverity-criticaltheme-security

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions