Skip to content

fix(env): send the control token to the REST routes behind the gateway - #728

Closed
andrewpark-scaleai wants to merge 1 commit into
mainfrom
andrewpark/vuln-5158-callers-send-control-token
Closed

andrewpark-scaleai wants to merge 1 commit into
mainfrom
andrewpark/vuln-5158-callers-send-control-token

Conversation

@andrewpark-scaleai

@andrewpark-scaleai andrewpark-scaleai commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Why

The gateway's data plane calls send the control token. This PR makes agent-env's calls to the older REST state routes send it too, so a later gateway change can require it there.

What changed

  • reset_via_rest, add_via_rest, export_state and reset in legacy_protocol take headers. Without them, each call sends the run's grant (request_headers).
  • The legacy loads and resets of MCP servers and websites send their record's token (data_plane_headers).
  • service_state and the snapshot step send the deployment's token to /export-state and to a streamed /export-snapshot.
  • granted_headers matches a URL to a grant only when the URL resolves under the grant's address, by whole path segments.
  • A legacy reset that the server refuses with 401 or 403 now raises instead of falling back to the <name>_reset MCP tool.

Scope

  • Covers every caller in this repo of /api/reset, /api/add, /export-state and /export-snapshot.
  • Leaves the gateway as it is.

Verification

  • New unit tests check the Authorization header on each legacy route when a token exists, and its absence when none does.
  • pytest packages/agentenv-protocol/tests tst/unit/env tst/unit/task_step -n 4: 7808 passed, 1 skipped, 0 failed. ruff check is clean.
  • tst/integration/env/envs/multi_env_local_test.py passed on local Docker.

RetriggerView in GreptileConfidence Score: 5/5

This PR appears safe to merge; no blocking issues were found.

Summary

This PR adds control-token headers to legacy state calls and streamed snapshots, while keeping tokens scoped to the destination address.

  • Legacy loads and resets send the token for their service address.
  • Control tokens follow only URLs inside their granted address.
  • State snapshots send the service token to legacy export routes.

No actionable issues found. Gateway enforcement remains separate in PR #740; its callers remain compatible with these changes.

Reviews (2) · Last reviewed commit: "fix(env): send the control token to the ..." · Reviewed by Greptile

@andrewpark-scaleai
andrewpark-scaleai force-pushed the andrewpark/vuln-5158-callers-send-control-token branch 2 times, most recently from 51545f0 to ffa4ca9 Compare November 18, 2026 18:55
@andrewpark-scaleai
andrewpark-scaleai marked this pull request as ready for review November 18, 2026 19:23
@andrewpark-scaleai
andrewpark-scaleai requested a review from a team as a code owner November 18, 2026 19:23
@andrewpark-scaleai andrewpark-scaleai changed the title fix(env): send the control token to the legacy REST routes behind the gateway fix(env): send the control token to the REST routes behind the gateway Nov 19, 2026
The legacy REST helpers (reset_via_rest, add_via_rest, export_state, reset)
take headers and default to the run's grant. Legacy loads, resets, state reads
and streamed snapshots send the deployment's token. A grant covers a URL only
when it resolves under the grant's address, by whole path segments. A legacy
reset refused with 401 or 403 raises instead of falling back to the MCP tool.
@andrewpark-scaleai
andrewpark-scaleai force-pushed the andrewpark/vuln-5158-callers-send-control-token branch from ffa4ca9 to 58f18f0 Compare November 19, 2026 18:48
@andrewpark-scaleai
andrewpark-scaleai deleted the andrewpark/vuln-5158-callers-send-control-token branch November 19, 2026 18:52
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