Repository navigation
feat(gateway): a keyed deploy's role key, forwarded headers, and triggers by route (FD-4683) - #443
Open
williamloo-scale wants to merge 1 commit into
Open
williamloo-scale wants to merge 1 commit into
williamloo-scale wants to merge 1 commit into
Conversation
williamloo-scale
marked this pull request as ready for review
November 3, 2026 00:24
| prefix = forwarded_prefix(_first(headers.get(b"x-forwarded-prefix"))) | ||
| if prefix: | ||
| scope["root_path"] = unquote(prefix) + scope.get("root_path", "") | ||
| scope["path"] = unquote(prefix) + scope["path"] |
There was a problem hiding this comment.
Reserved paths reach site handlers
Adding the forwarded prefix to scope["path"] breaks _unreserved, which still checks that full path with reserved_path. For a site with @api.post("/{rest:path}"), a request to /agentenv/unknown with X-Forwarded-Prefix: /website/shop now runs the site's handler instead of returning 404. A write handler could change site data on a request that should be refused.
Check the site-relative path with get_route_path(request.scope) in _unreserved, as _Fallback now does.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/agentenv-protocol/src/agentenv_protocol/website/environment.py
Line: 348
Comment:
**Reserved paths reach site handlers**
Adding the forwarded prefix to `scope["path"]` breaks `_unreserved`, which still checks that full path with `reserved_path`. For a site with `@api.post("/{rest:path}")`, a request to `/agentenv/unknown` with `X-Forwarded-Prefix: /website/shop` now runs the site's handler instead of returning 404. A write handler could change site data on a request that should be refused.
Check the site-relative path with `get_route_path(request.scope)` in `_unreserved`, as `_Fallback` now does.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
williamloo-scale
force-pushed
the
wloo/website-notes-example
branch
from
November 3, 2026 21:50
d76be33 to
a68ff2a
Compare
williamloo-scale
force-pushed
the
wloo/website-gateway-auth
branch
from
November 3, 2026 21:50
8dcebd1 to
4c1fcc1
Compare
williamloo-scale
force-pushed
the
wloo/website-notes-example
branch
from
November 3, 2026 22:52
a68ff2a to
f1a665a
Compare
williamloo-scale
force-pushed
the
wloo/website-gateway-auth
branch
from
November 3, 2026 22:52
4c1fcc1 to
22947c3
Compare
williamloo-scale
force-pushed
the
wloo/website-gateway-auth
branch
from
November 3, 2026 23:47
22947c3 to
253eaec
Compare
…gers by route (FD-4683) This PR's change, rebased as one commit onto #429. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
williamloo-scale
force-pushed
the
wloo/website-notes-example
branch
from
November 4, 2026 03:37
250afe3 to
30113cb
Compare
williamloo-scale
force-pushed
the
wloo/website-gateway-auth
branch
from
November 4, 2026 03:37
253eaec to
18b1b98
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #429.
The gateway side of website/v1: roles that can't be spoofed, the address a site is reached at, and triggers matched by route.
keyed_roles(deploy_env'skeyed_roles: true, orenv deploy --keyed-roles) draws a secret role key, gives it to the gateway (AGENTENV_ROLE_KEY) and to each website server (WEBSITE_ROLE_KEY), and records it on the deployed env (DeployedEnv.role_key, sent byrole_headers(role)). Its gateway believes a role other thandefault, on REST and MCP, only besideAgentEnv-Role-Keyequal to the key. It strips a client's key and sends its own upstream only beside a verified role, so SDK sites believe it.deploy_agent, the episode proxy, post-turn hook/stepcalls and the generated MCP CLI send the key. Any other deploy draws none, and its gateway believes the role header alone, as before. A step asking forkeyed_rolesof an env whose provider doesn't take them is refused at save./svcand/websitesetX-Forwarded-Host,-Protoand-Prefixand drop the client's copies. The SDK takes the prefix as the root path, sobase_url,request.urland redirects name the gateway's address.whenmay nameop, a route of the site's card, and then matches only requests that reach it. Registration refuses an op the card doesn't name. triggers/v1 declareswebsite_op, so an older gateway is refused.Before merging
keyed_rolesdeploy, a caller that sends a non-defaultrole withoutrole_headers(role)isdefault; agentenvhub-sdk and the hub don't send the key yet, so their tasks shouldn't turn it on until they do. Unkeyed deploys, the default, are unaffected.cliisdefaulton a keyed deploy.Test
Unit suite: 12,712 passed (one GitHub-clone test from main, which hangs on the local machine on main too, deselected).
🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge, with the earlier non-blocking reserved-path finding still open.Fix with agent prompt
Summary
Adds optional role keys, forwards the website’s public address, and lets website triggers match named routes.
Diagram
sequenceDiagram participant Caller participant Gateway participant Website participant Triggers Caller->>Gateway: Request with role and optional key Gateway->>Gateway: Check role key when enabled Gateway->>Website: Verified role and forwarded address Website-->>Gateway: Response Gateway->>Triggers: Match method, upstream path, and named route Triggers-->>Gateway: Complete any response barrier Gateway-->>Caller: ResponseReviews (12) · Last reviewed commit: "feat(gateway): a keyed deploy's role key..." · Reviewed by Greptile