Repository navigation
fix(agents): send proxy-unsafe crew names in the request body - #19981
Conversation
e71cbfc to
441a0a4
Compare
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. The diff changes only request paths and bodies in Notes
[UX-REVIEWED] b3275fa Description read[DESCRIPTION-READ] 0259cbcc4ba22fa3d6234517b8c149d9ba1513b7a7e79af197e2dd6751b2c376 That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design problem blocks this; the new routes only add to the old ones, and every route that already put the name in the path is unchanged. Notes
[DESIGN-REVIEWED] b3275fa Description read[DESCRIPTION-READ] 2bed14a17ddbf12341f487811a34892900f920335d16c52037636aaedbb4d8d9 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The fix itself is sound. The frozen Goal defers the base64url twins and the change-card Apply/Undo rewiring to #20083, but this diff ships both anyway. Notes
What this change shipsInventory (9 items) — 4 justifiedIntent: let a user save a crew whose name contains a space from a proxied dashboard. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] b3275fa Description read[DESCRIPTION-READ] e2356d69d89128927c4a3751ab804ac2bb159cf3a194440c97f155705b8f7837 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
8457133 to
5a69898
Compare
e8a36c7 to
dc347ef
Compare
dc347ef to
e4646c2
Compare
96c5838 to
4426ae4
Compare
|
HOLD at 4426ae4, reserved for human review. The r118 request is done. #20083 now lists every change-card Apply/Undo step that still builds a path-form URL, and Not a goal links it. #20083 also covers the seven sibling routes and the new-avatar Save gap. CI is green on this head, and every AI lane passes. The code looks right. Two non-blocking notes: the First Principles lane suggests folding the new Reviewed head: 4426ae4 — crew-pr-reviewer (r120) |
|
Reply to crew-pr-reviewer r120 (head 4426ae4). No new commit.
|
|
Backend Tests shard 4 (Linux and Windows) is failing with a DNS error on |
|
Backend Tests (Windows) (7) is failing on |
|
Rebased onto main @665bb6b86255a448d19ead6cb4c9f1a02e38ff8b. New head: 85ef862 (still 2 commits). How the conflict was resolved: the only conflict was in |
|
Correction to my previous comment: that rebase used a stale local copy of main (665bb6b), so the PR still conflicted. I have now rebased onto main @f265a529765a05c32d08834c924e8452cf30e33e. New head: d4d3136 (still 2 commits, same 9 files, +226/-7). The conflict was resolved the same way. The only conflict was in |
|
@iamwhatever head |
iamwhatever
left a comment
There was a problem hiding this comment.
Requesting changes at d4d3136.
The r118 and r120 items are done, and the code still looks right: _require_owner runs before the name is read from either the path or the body (crew_update.py L120-L143). CI is green and every AI lane passes on this head.
One untracked follow-up remains. The First Principles note on this head says #20083 leaves out the worker-kit routes, and that is accurate: routes/agents.py L53-L55 registers GET/PUT /api/agents/{name}/worker-kit and POST .../worker-kit/preview, and crewCapabilities.ts L104 still builds that path, so a space-named crew hits the same proxy 502 there. Please add these three routes to #20083 (and to Not a goal) and reply to the note.
Even with that done, this PR adds a new network route (PUT /api/agents) and changes how the owner-gated handler picks its target crew, so it stays reserved for human review.
— crew-pr-reviewer (r130)
|
Re r130 (iamwhatever, crew-pr-reviewer) and the First Principles note on
Understood that this PR stays reserved for human review. |
|
@iamwhatever the r130 item is addressed (worker-kit routes added to #20083 and to Not a goal; reply above). The branch was rebased onto main today, and head |
|
HOLD (policy_sensitive) at 85725b7. The r130 item is done: #20083 now lists the three worker-kit routes, and Not a goal names them. The code still looks right. Why HOLD: the PR adds a new network route, — crew-pr-reviewer (r135) |
|
@iamwhatever the follow-up from your change request at d4d3136 looks done at 85725b7. Could you re-review?
Your note that this PR adds a new network route ( |
|
Reply to the First Principles BLOCK (Framing contradicted by diff, items 3-6), head The base64url twins come from #28628. It was stacked on this branch and merged into it on 2026-11-04 by its owner, so its commit is now part of this PR rather than of What changed in this push:
What this push cannot do: the
On Note item 2 (two mechanisms for one cause): the body form stays for |
|
Reply to the First Principles BLOCK on Kept, not removed. The body-form Fixed: the What clears the lane is a maintainer choice:
The Goal / Not a goal mismatch from the earlier round still stands, since those sections are frozen (see the comment above). |
|
CI note on head f963fa9: the only red is |
bolichen97
left a comment
There was a problem hiding this comment.
Requesting changes on 2e94762. The approach looks right to me: PUT /api/agents with the name in the body, plus base64url twins that reuse each path-form route's handler so the owner check runs first and nothing after it changes.
The blocker is two new regexes in product code, which this repo does not take:
agent_url_path.py:48:_SEGMENT = re.compile(r"[A-Za-z0-9_-]+"), used bydecode_agent_nameto validate an incoming path segment. Please use a plain character check instead, for example a module-levelfrozenset(string.ascii_letters + string.digits + "-_")andsegment and all(c in _SEGMENT_CHARS for c in segment). The re-encode round-trip check you already do stays as the real gate.website/src/api/agentPath.ts:28:btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''). Plain string calls do the same:.replaceAll('+', '-').replaceAll('/', '_'), then strip trailing=with a short loop orsliceon the last index that is not=.
The tests you already have should carry over unchanged. All 97 checks pass on this head.
Fixes #19976 When a crew's config.json key contains a space (e.g. 'My Agent'), saving from the dashboard editor calls PUT /api/agents/My%20Agent. A reverse proxy that normalises percent-encoded paths decodes %20 to a literal space, which is the HTTP request-line delimiter and causes a 502. Fix: add PUT /api/agents (no path variable) that reads the crew name from a 'name' field in the JSON body. The frontend uses this body-form route automatically when encodeURIComponent(name) !== name, so a space-containing key is never placed in a URL path segment a proxy can misinterpret. The existing PUT /api/agents/{name} is unchanged for slug-keyed agents. The api_kirocrew_agent_update handler now serves both routes: it reads the name from the URL path when present, or from the request body when the path-variable route is not matched. The body name is used verbatim (never stripped) so a stored key that differs only by edge whitespace is not silently overwritten. Both forms share all update logic including _require_owner, so auth and owner checks are identical. change_card_catalog: add PUT /api/agents to HOOKED_ROUTES and describe_manual_change so memory events are recorded for body-form saves the same way they are for path-form saves. Security: test_agents_endpoints_owner_auth.py already walks all routes and verifies owner-gating; PUT /api/agents is added to its floor set. test_agent_update_body_form.py pins auth parity between both routes.
…th (#28628) Every crew route that names the crew in its URL path also answers under /api/agents/b64/{name_b64}..., an unpadded base64url segment, so a path-normalising proxy has no %20 to decode into a bare space (502). The twins reach the same handlers behind the same owner gate. The dashboard (delete, avatar upload and image, capabilities, worker kit) and change-card Apply/Undo steps use the twin or the body-form PUT for such names; the card hook reads a twin as its path-form route. Fixes #20083 Co-authored-by: Zezhen Xu <zezhexu@amazon.com>
bolichen97
left a comment
There was a problem hiding this comment.
Approving head b3275fa. The gate shows 97 checks passed, none red or pending. This replaces my change request on 2e94762.
Thanks for the quick fix. A range-diff from 2e94762 shows only the regex replacements, plus a line in the feature map:
agent_url_path.py:_SEGMENTis now_SEGMENT_CHARS = frozenset(string.ascii_letters + string.digits + "-_"), with an explicit empty-segment check beforeall(c in _SEGMENT_CHARS for c in segment). The re-encode round-trip is still the final gate.agentPath.ts:base64UrlusesreplaceAll('+', '-'),replaceAll('/', '_')and a trailing-=loop.- You also replaced the third pattern,
/[!'()*]/.test(name)inneedsProxySafePath, with a plain character check. Thanks for catching that one.
Nothing else changed, so the owner check still runs first on every base64url twin route, as before.
|
@bolichen97 Both regexes are gone, head b3275fa (rebased on main, CI green):
|
Fixes #19976
Problem / Motivation
Goal: Let users save a crew whose config key contains a space through the dashboard, even behind a reverse proxy that normalises percent-encoded paths.
When a crew's
config.jsonkey contains a space (e.g."My Agent"), the editor's Save button callsPUT /api/agents/My%20Agent. A reverse proxy that normalises percent-encoded paths decodes%20to a literal space in the HTTP request-line, which is the HTTP delimiter, producing a 502 Bad Gateway before the request reaches the gateway.Why it matters
Any user who created a crew with a space in the name (via CLI or by hand-editing
config.jsonbefore slug keys were introduced) cannot save that crew's settings through a tunnelled or proxied dashboard. The 502 is silent with no indication of why the setting change was lost.Not a goal
DELETE /api/agents/{name},GET /api/agents/{name}/avatar, orPOST /api/agents/{name}/avatarfor space-keyed crews (deferred: Six agent-update sibling routes still put the name in the URL path (follow-up to #19976) #20083).GET /api/agents/{name}/capabilities,POST /api/agents/{name}/capabilities/preview,POST /api/agents/{name}/capabilities/detach,PUT /api/agents/{name}/capabilities— that also put the name in the URL path (deferred: Six agent-update sibling routes still put the name in the URL path (follow-up to #19976) #20083).crewmate.updateApply/Undo still buildsPUT /api/agents/{name},crewmate.create/crewmate.importUndo buildsDELETE /api/agents/{name}, andcrewmate.capabilitiesbuilds the capabilities routes; the browser sends these paths as-is, so they cross the proxy too (deferred: Six agent-update sibling routes still put the name in the URL path (follow-up to #19976) #20083, now listed there).GET/PUT /api/agents/{name}/worker-kitandPOST /api/agents/{name}/worker-kit/preview, which also put the name in the URL path (deferred: Six agent-update sibling routes still put the name in the URL path (follow-up to #19976) #20083).What changed (motivation → approach → change)
The 502 is caused by placing the raw crew name in the URL path. The fix keeps the name out of the URL path for callers who need it.
PUT /api/agentsis added as a new route that accepts the crew name in the JSON body under the keyname. The existingPUT /api/agents/{name}is unchanged and continues to serve all current callers for slug-keyed agents.The
api_kirocrew_agent_updatehandler now serves both routes: it reads the name frommatch_info["name"]for the path-form route, or from the JSON bodynamefield for the body-form route. The body name is extracted before the mask-removal pass so it is never treated as a crew-record field to persist. All remaining update logic — including authentication, owner checks, validation, and the full save path — is shared by both routes.The body-form route is registered first in
routes/agents.pyso aiohttp's literal-path preference resolves it without ambiguity.The frontend
updateKirocrewAgentdetects whenencodeURIComponent(name) !== nameand usesPUT /api/agentswithnamein the body; for slug-keyed agents it usesPUT /api/agents/{name}as before. (Saves that also upload a new avatar first calluploadCrewAvatar, which posts toPOST /api/agents/{name}/avatar— that route still puts the name in the path and is deferred to #20083.)change_card_catalog.pyis updated to addPUT /api/agentstoHOOKED_ROUTESanddescribe_manual_change, so a body-form save records the same "updated mate <name> (<fields>)" change-card entry as a path-form save.Folded in from #28628 (merged into this branch, base
fix/agent-name-space-502). Every other crew route that names the crew in its path also answers under/api/agents/b64/{name_b64}..., an unpadded base64url segment ([A-Za-z0-9_-]only), so a path-normalising proxy has no%20to decode.src/kiro_crew/agent_url_path.pyowns the encoding,dashboard/agent_name_segment.pyreads either spelling for the handlers, and a malformed segment answers400 name_segment_invalid. The twins are registered on the same handlers as their path-form routes. The dashboard (website/src/api/agentPath.ts: delete, avatar upload and image, capabilities, worker kit) and the change-card Apply/Undo plans use the twin or the body-formPUTonly for a name that needs encoding; plain names keep the path form.Security
Both routes use exactly the same handler function (
api_kirocrew_agent_update)._require_owneris the first call in the handler, before the name is read from either the URL path or the body. This means the body-form route cannot bypass owner checks, CSRF protection, app-token rejection, or any other gate that the path-form route enforces.The comprehensive route-walk in
test_agents_endpoints_owner_auth.py(which enumerates every mutating route and asserts403 owner_onlyfor non-owner callers) now includesPUT /api/agentsin its floor set.test_agent_update_body_form.TestBodyFormAuthParityadds two direct 403/owner_only tests to pin the invariant: a non-owner caller is refused on the body-form route with the same code as the path-form route.Auth review guide
New route:
PUT /api/agents(body-form).Gate:
_require_owner(request, "agent.update")atcrew_update.py:116. This is the first statement in the handler, executed before the name is resolved from either the URL path (match_info["name"]) or the JSON body. A non-owner subject never reaches the name-parsing or data-write code paths.Parity tests (
test/test_agent_update_body_form.py, classTestBodyFormAuthParity):test_body_form_rejects_non_owner— patchesis_owner_dashboard_requesttoFalse, sendsPUT /api/agentswith a valid body, asserts403andcode == "owner_only".test_body_form_same_gate_as_path_form— same non-owner patch; sends bothPUT /api/agentsandPUT /api/agents/my-agentin one test, asserts identical403/owner_onlyon both.Route-walk coverage (
test/test_agents_endpoints_owner_auth.py):_EXPECTED_MUTATING_ROUTESincludes("PUT", "/api/agents"). The walk test enumerates every registered mutating route, asserts the floor set is a subset of found routes, then sends a non-owner request to each and asserts403 owner_only. Both forms are covered.Base64url twins (from #28628):
DELETE /api/agents/b64/{name_b64},GETandPOST /api/agents/b64/{name_b64}/avatar,GETandPUT /api/agents/b64/{name_b64}/capabilities,POST .../capabilities/preview,POST .../capabilities/detach,GETandPUT /api/agents/b64/{name_b64}/worker-kit,POST .../worker-kit/preview(routes/agents.py). Each is registered on the same handler as its path-form route, so it runs the same_require_ownercall first, before the segment is decoded.test/test_agent_b64_routes.py::test_every_b64_route_refuses_a_non_ownersends a non-owner to every twin and asserts403;test_every_b64_route_reaches_its_path_form_twins_handlerpins the handler identity; the route walk intest_agents_endpoints_owner_auth.pycovers the mutating twins.Existing callers unchanged:
PUT /api/agents/{name}calls the same handler function with the same gate. No existing call site is altered; the new route is purely additive.Intended? / Repro
Intended? No. The 502 is an unintended interaction: the HTTP-path encoding the browser sends is valid, but the proxy's path normalisation makes it invalid before forwarding.
Repro: Add an agent with a space-containing key to
~/.kiro/crew/config.json, access the dashboard through a reverse proxy that normalises percent-encoded paths, open the agent editor, and click Save without changing the avatar. The browser sendsPUT /api/agents/My%20Agent; the proxy decodes the path and the request line contains a literal space, causing a 502. After this fix the frontend detects the space-containing key and sendsPUT /api/agentswith{"name": "My Agent", ...}— a body field a proxy never rewrites. With #28628 folded in, the avatar upload and the other crew routes use the base64url twin for such a name, so a save that also picks a new avatar no longer 502s; the Known limitation note above predates that.Backwards compatibility
Compatible:
PUT /api/agents/{name}is unchanged. The newPUT /api/agentsroute is additive.Removes nothing: no existing endpoint, key, record, or behaviour is removed.
Tests
New file
test/test_agent_update_body_form.py(5 tests):TestBodyFormRoute: space-keyed crew saves through body form; missing-name body returns 400; path-form is unchanged for slug keys.TestBodyFormAuthParity: non-owner caller gets 403owner_onlyon body-form route; body-form and path-form return the same 403 for the same non-owner caller.New file
test/test_agent_b64_routes.py(from #28628): encode/decode round trip and canonical-only decode,agentPathandagent_record_writechoose the twin or body form only for names that need it, every twin reaches its path-form handler and refuses a non-owner, a malformed segment gets 400, a crew namedb64keeps its own routes, and card plans never put an encoded name in a path.test_agents_endpoints_owner_auth.py:PUT /api/agentsadded to_EXPECTED_MUTATING_ROUTESfloor set so the route-walk test covers it.Manual verification
N/A — unit coverage sufficient.
Screenshots / video
Why no screenshot: This change is entirely in the HTTP routing and handler layer; no user-visible frontend UI is modified beyond which endpoint the Save call targets.
Related Issues
Fixes #19976
Fixes #20083 (via #28628, merged into this branch)
Originally deferred to #20083 (seven remaining name-in-path agent routes:
DELETE /api/agents/{name},GET/POST /api/agents/{name}/avatar,GET /api/agents/{name}/capabilities,POST /api/agents/{name}/capabilities/preview,POST /api/agents/{name}/capabilities/detach,PUT /api/agents/{name}/capabilities)Pattern harvest
Rule candidate: free-form crew name in a URL path segment — when a route's path segment carries a free-form config key (not a slug), a proxy that normalises percent-encoded paths produces a 502. Fix by moving the identifier out of the path: body form for writes (PUT, POST, DELETE), base64url for reads (GET). #20083 applies this to the remaining seven routes. No semgrep rule addresses this class.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)