Skip to content

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

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

scale-avr[bot] wants to merge 4 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 4 1 of 1 sandbox PoC fail before and pass after

Merge risk: High. Review impact before merge.

Signal Grade Why
Alignment Poor The fix gave no security delta; 173 of 452 files named by the finding or the fix; not named: .github/dependabot.yml and 278 more
Impact Large Touches auth, permissions, dependencies, infrastructure, CI; 452 files
Verification Decent The PoC fails before the fix and passes after; AVR did not finish every check; no recording yet
Rollback cost Medium Changes infrastructure or CI files
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: Fixed the CI failures on this PR. The "unit" and "integration-local-slow" jobs failed for two causes. First, three snapshot_agent_state unit tests used export_state stubs that did not take the new headers argument. They now do. Second, the composed-universe integration test has a verifier that read…

Before merge:

  1. Confirm the unit shard and integration-local-slow pass in CI.
  2. Confirm giving verifiers the control token is acceptable: verifiers run on the harness side, never in the agent.
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.
Repository check passed python3 -m py_compile src/agent_env/task_step/task_steps/verifiers/env_outcome_verifier.py tst/unit/task_step/verifiers/test_env_outcome_verifier_step.py
Repository check run by AVR passed cd src/agent_env/utils/egress_proxy && go vet .
Repository check run by AVR passed cd src/agent_env/utils/egress_proxy && go test .
Repository check run by AVR failed, as on the base branch cd packages/agentenv-protocol && uv run --frozen --no-sync python -m pytest -q -rfE -p no:cacheprovider tests/test_a2a_agent.py tests/test_a2a_agent_clock.py te
Regression test in the diff written test_a_control_headers_parameter_gets_the_deployments_control_token in tst/unit/task_step/verifiers/test_env_outcome_verifier_step.py

Not fixed by this PR

  • Tests were not run locally: no network to install dependencies. CI must confirm.
  • Other verifier scripts that read guarded REST routes through the gateway without a token need the control_headers parameter. The scaleapi and synthetic-pipelines callers in the finding are outside this repository.

Files changed (4)

  • src/agent_env/task_step/task_steps/verifiers/env_outcome_verifier.py
  • tst/integration/cli/run_bundle_built_envs_test.py
  • tst/unit/task_step/verifiers/test_env_outcome_verifier_step.py
  • tst/unit/task_step/test_snapshot_agent_state.py

Other findings this PR fixes

an earlier finding

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

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, pending the required CI checks.

Summary

The PR guards older REST data routes with the deployment’s control token and updates framework callers to send it. The latest changes let verifier scripts request those headers and repair affected tests.

  • Legacy data routes behind MCP service proxies now require the control token.
  • Framework calls carry control headers to legacy environment routes.
  • Verifiers can read protected environment state with supplied headers.

The earlier shared-name authentication issue is fixed. No new actionable issues were found. CI still needs to confirm the unit and slow integration jobs pass.

Reviews (3) · Last reviewed commit: "test(snapshot): let the export_state stu..." · 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. #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 #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

scale-avr Bot added 2 commits November 20, 2026 14:45
…stubs

An env outcome verifier can take a control_headers argument, so a check that reads
a server's REST data routes through the gateway sends the deployment's control token.
The composed-universe test verifier and the snapshot state test stubs now match
the guarded routes.
@earakely-scale

Copy link
Copy Markdown
Collaborator

Superseded by #820 (released in v0.9.1639) and #822 (v0.9.1642, now the default gateway in dev and prod). #820 makes every agent-env caller of the older REST state routes send the deploy's control token, and #822 makes the gateway require it on those routes (/api/reset, /api/add, /api/bridge/apply, /export-state, /export-snapshot, /snapshot-dirty, /reset-memory, /validate-rows, /api/_state, /api/_reset, /api/debug/seed). The optional control_headers argument this PR adds for verify() scripts isn't needed: verify runs under Task.run's grant of each deployed env's token, so a script's calls through the protocol client or request_headers() already send it.

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