Skip to content

fix(security): Older REST data routes behind the gateway proxy (/api/reset, /export-state, /export-snapshot) take no control token - #776

Open
scale-avr[bot] wants to merge 2 commits into
mainfrom
avr-sast/d1b3a780cc20
Open

scale-avr[bot] wants to merge 2 commits into
mainfrom
avr-sast/d1b3a780cc20

Conversation

@scale-avr

@scale-avr scale-avr Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Findings Files Proof
1 of 1 3 1 of 1 sandbox PoC fail before and pass after

Merge risk: Medium. Review verification before merge.

Signal Grade Why
Alignment Poor The fix gave no security delta; 4 of 9 files named by the finding or the fix; not named: src/agent_env/env/envs/_deployment.py and 4 more
Impact Medium Touches auth; 9 files; the fix gave no security delta
Verification Decent The PoC fails before the fix and passes after; AVR did not finish every check; no recording yet
Rollback cost Low Plain revert
Error detection Poor No alert, metric or log line reported for a failure of this change

Not checked: The reproduction of an earlier fix reproduces on the new code and on the code before this change. This change did not undo that fix. Review must confirm that the earlier fix still holds.

Finding: src/agent_env/env/gateway/gateway.py

Root cause: The REST helpers reset_via_rest, add_via_rest and _export_state_at in legacy_protocol.py now pass their final URL through protocol_v1.request_headers. A call that names no headers takes the token granted to its env. This fixes shared-name loads, where MultiEnv grants the token through protocol_v1.a…

Details: proof ladder, not fixed, files

How sure is this fix?

Level Result Evidence
Sandbox PoC (gVisor, no network) before: fail, after: pass .avr/tests/legacy_data_routes_poc.py written by AVR's accepted proof. Before the fix it coverage not checked: the finding names no file and line.
Regression test in the diff written tst/unit/env/test_legacy_protocol.py::test_a_rest_call_without_headers_takes_the_token_its_env_was_granted

Not fixed by this PR

  • Tests were not run in this session (no network, no pytest). CI must run them.
  • Failing checks unit, integration-local-slow and the browser chromium compose test show no link to the changed files in the logs given.

Files changed (3)

  • src/agent_env/env/legacy_protocol.py
  • tst/unit/env/test_legacy_protocol.py
  • tst/integration/env/envs/multi_env_local_test.py

Other findings this PR fixes

an earlier finding

Findings Files Proof
1 of 1 8 1 of 1 sandbox PoC fail before and pass after

Merge risk: Medium. Review verification before merge.

Signal Grade Why
Alignment Poor The fix gave no security delta; 3 of 8 files named by the finding or the fix; not named: src/agent_env/env/envs/_deployment.py and 4 more
Impact Medium Touches auth; 8 files; the fix gave no security delta
Verification Decent The PoC fails before the fix and passes after; AVR did not finish every check; no recording yet
Rollback cost Low Plain revert
Error detection Poor No alert, metric or log line reported for a failure of this change

Not checked: The reproduction of an earlier fix reproduces on the new code and on the code before this change. This change did not undo that fix. Review must confirm that the earlier fix still holds.

Finding: src/agent_env/env/gateway/gateway.py

Root cause: The gateway now takes its control token on the older REST routes behind /svc/mcp-<name>/: api/reset, export-state, export-snapshot, snapshot-dirty, reset-memory and validate-rows. It matches them with the same dot-segment normalisation, case folding and encoding rules as the MCP endpoint. A gateway…

Before merge:

  1. Run tst/unit/env/gateway/control_token_test.py and tst/unit/env/test_legacy_protocol.py in CI.
  2. Confirm scaleapi and synthetic-pipelines callers send the token before the gateway release.
Details: proof ladder, not fixed, files

How sure is this fix?

Level Result Evidence
Sandbox PoC (gVisor, no network) before: fail, after: pass .avr/tests/legacy_data_routes_poc.py written by fireworks_ai/deepseek-v4p1-flash-1017. Before the fix it coverage not checked: the finding names no file and line.
Repository check passed python -m py_compile <changed files>
Repository check error python -m pytest tst/unit/env/test_legacy_protocol.py tst/unit/env/gateway/control_token_test.py
Regression test in the diff written control_token_test.py: legacy routes (plain, dot-segment, encoded, mixed case) get 401 without a token and pass with it; no token means no guard; website routes
Regression test in the diff written test_legacy_protocol.py: reset, add and export send the Bearer token; legacy service_state sends it

Not fixed by this PR

  • Tests were not run: pytest and the project dependencies are not installed in the sandbox. CI must run them.
  • Callers outside this repository (hub backend, worker run_next_turn, modal-proxy, synthetic-pipelines tooling) must send the control token before this merges, or their calls get 401.
  • The existing open-proxy test expecting /svc/mcp-svc/export-state to be open was changed to expect a guard.

Files changed (8)

  • src/agent_env/env/gateway/gateway.py
  • src/agent_env/env/legacy_protocol.py
  • src/agent_env/env/envs/_deployment.py
  • src/agent_env/env/envs/website.py
  • src/agent_env/env/envs/mcp_server.py
  • src/agent_env/task_step/task_steps/snapshot_env.py
  • tst/unit/env/gateway/control_token_test.py
  • tst/unit/env/test_legacy_protocol.py

RetriggerView in GreptileConfidence Score: 5/5

The reviewed changes appear safe to merge; CI still needs to run the tests.

Summary

The PR requires control tokens on older MCP data routes and updates callers to send them. The follow-up fixes shared-name loads by letting REST helpers use the token granted by MultiEnv.

  • Legacy MCP data routes now require the gateway's control token.
  • Legacy environment calls send the token when they use protected data routes.

Reviews (2) · Last reviewed commit: "fix(gateway): send the granted control t..." · Reviewed by Greptile

@scale-avr
scale-avr Bot requested a review from a team as a code owner November 18, 2026 17:19
Comment thread src/agent_env/env/legacy_protocol.py Resolved
@earakely-scale

Copy link
Copy Markdown
Collaborator

🤖 Automated Claude routine — Env Pod PR Context Review. This is a bot, not Edgar Arakelyan; not a human review.

Context from outside this diff: two other open PRs are already guarding these same routes, so whoever reviews this probably wants to decide which version is the one to keep.

  • src/agent_env/env/gateway/gateway.py:1857 here introduces LEGACY_DATA_PATHS = /api/reset, /export-state, /export-snapshot, /snapshot-dirty, /reset-memory, /validate-rows, folded into token_paths at line 1869. feat(gateway): take the control token on the older /svc REST state routes #740 introduces LEGACY_STATE_ROUTES at src/agent_env/env/gateway/constants.py:195 with those same six literals plus /api/add, /api/bridge/apply, /api/_state, /api/_reset and /api/debug/seed, wired in through Gateway._takes_control_token, and additionally closes a site's /website route onto them (SITE_LEGACY_STATE_ROUTES / _site_reserved).
  • The caller-side half of this PR (env/legacy_protocol.py, env/envs/_deployment.py, env/envs/mcp_server.py, env/envs/website.py, task_step/task_steps/snapshot_env.py) is the same source file set as fix(env): send the control token to the REST routes behind the gateway #728, which also updates packages/agentenv-protocol/src/agentenv_protocol/client.py.

One concrete gap inside this PR, independent of which list wins: add_via_rest now sends the token on /api/add (legacy_protocol.py, the add_via_rest hunk), but /api/add is not in this PR's LEGACY_DATA_PATHS, so the gateway here takes no token on that route — it is in #740's list.

Both of those are still drafts, so this PR may simply be ahead of them; flagging it only because the overlap isn't visible from this diff alone.


Generated by Claude Code

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant