Skip to content

fix(agents): send proxy-unsafe crew names in the request body - #19981

Merged
iamwhatever merged 2 commits into
mainfrom
fix/agent-name-space-502
Nov 7, 2026
Merged

iamwhatever merged 2 commits into
mainfrom
fix/agent-name-space-502

Conversation

@CrysisDeu

@CrysisDeu CrysisDeu commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

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.json key contains a space (e.g. "My Agent"), the editor's Save button calls PUT /api/agents/My%20Agent. A reverse proxy that normalises percent-encoded paths decodes %20 to 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.json before 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

Known limitation: Saving a new avatar for a space-named crew behind a path-normalising proxy still 502s. When the user picks a new image, the Save flow calls uploadCrewAvatar(name, …) first, which posts to POST /api/agents/{name}/avatar — a route in #20083's deferred list. Only Saves that do not change the avatar are fixed by this PR.

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/agents is added as a new route that accepts the crew name in the JSON body under the key name. The existing PUT /api/agents/{name} is unchanged and continues to serve all current callers for slug-keyed agents.

The api_kirocrew_agent_update handler now serves both routes: it reads the name from match_info["name"] for the path-form route, or from the JSON body name field 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.py so aiohttp's literal-path preference resolves it without ambiguity.

The frontend updateKirocrewAgent detects when encodeURIComponent(name) !== name and uses PUT /api/agents with name in the body; for slug-keyed agents it uses PUT /api/agents/{name} as before. (Saves that also upload a new avatar first call uploadCrewAvatar, which posts to POST /api/agents/{name}/avatar — that route still puts the name in the path and is deferred to #20083.)

change_card_catalog.py is updated to add PUT /api/agents to HOOKED_ROUTES and describe_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 %20 to decode. src/kiro_crew/agent_url_path.py owns the encoding, dashboard/agent_name_segment.py reads either spelling for the handlers, and a malformed segment answers 400 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-form PUT only 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_owner is 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 asserts 403 owner_only for non-owner callers) now includes PUT /api/agents in its floor set. test_agent_update_body_form.TestBodyFormAuthParity adds 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") at crew_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, class TestBodyFormAuthParity):

  • test_body_form_rejects_non_owner — patches is_owner_dashboard_request to False, sends PUT /api/agents with a valid body, asserts 403 and code == "owner_only".
  • test_body_form_same_gate_as_path_form — same non-owner patch; sends both PUT /api/agents and PUT /api/agents/my-agent in one test, asserts identical 403/owner_only on both.

Route-walk coverage (test/test_agents_endpoints_owner_auth.py): _EXPECTED_MUTATING_ROUTES includes ("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 asserts 403 owner_only. Both forms are covered.

Base64url twins (from #28628): DELETE /api/agents/b64/{name_b64}, GET and POST /api/agents/b64/{name_b64}/avatar, GET and PUT /api/agents/b64/{name_b64}/capabilities, POST .../capabilities/preview, POST .../capabilities/detach, GET and PUT /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_owner call first, before the segment is decoded. test/test_agent_b64_routes.py::test_every_b64_route_refuses_a_non_owner sends a non-owner to every twin and asserts 403; test_every_b64_route_reaches_its_path_form_twins_handler pins the handler identity; the route walk in test_agents_endpoints_owner_auth.py covers 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 sends PUT /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 sends PUT /api/agents with {"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 new PUT /api/agents route 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 403 owner_only on 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, agentPath and agent_record_write choose 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 named b64 keeps its own routes, and card plans never put an encoded name in a path.

test_agents_endpoints_owner_auth.py: PUT /api/agents added to _EXPECTED_MUTATING_ROUTES floor 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

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@CrysisDeu
CrysisDeu requested review from a team and KiroCrewCaptain as code owners October 13, 2026 22:29
@CrysisDeu
CrysisDeu requested a review from mbriones98 October 13, 2026 22:29
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 13, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/agent-name-space-502 branch 10 times, most recently from e71cbfc to 441a0a4 Compare October 14, 2026 00:13
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of b3275fa94906b7b692e7c65cc9b2003622542808 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] b3275fa

False positive or not applicable? A repository writer can comment:
/ai-review override gpt b3275fa94906b7b692e7c65cc9b2003622542808 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of b3275fa94906b7b692e7c65cc9b2003622542808 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing to check. The diff changes only request paths and bodies in agentPath.ts, agents.ts, crewCapabilities.ts and CrewAvatar.tsx's image URL. It adds or changes no user-visible control, label or state, so no screenshot is needed.

Notes

  • The PR description states the known limitation: saving a new avatar for a crew whose name contains a space still fails behind a proxy. The b64 avatar route in this diff looks like it covers that case. If it does, drop the limitation line from the description so readers aren't misled about the remaining failure.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of b3275fa94906b7b692e7c65cc9b2003622542808 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of b3275fa94906b7b692e7c65cc9b2003622542808 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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 ships

Inventory (9 items) — 4 justified

Intent: let a user save a crew whose name contains a space from a proxied dashboard. This is a FIX.

  1. Saving a space-named crew sends its name in the body to new PUT /api/agents — justified
  2. Settings-page change memory records body-form saves as "updated Bot …" — justified
  3. Delete, avatar fetch/upload, capabilities and worker-kit for encoded names go through new /api/agents/b64/… routes — oversized: listed under Not a goal
  4. A malformed base64 segment answers new 400 name_segment_invalid — rides along
  5. PUT /api/agents without a body name answers new 400 name_required — justified
  6. Change-card Apply/Undo plans use the body form or base64 paths for encoded names — oversized: listed under Not a goal
  7. The change-card hook reads a base64 twin as its path-form route for memory and undo guard — rides along
  8. Crew-mode and learn-cron-dashboard specs describe both proxy-safe forms — justified
  9. A _drained_to_thread comment in handlers/agents.py is shortened — undeclared

[FIRST-PRINCIPLES-REVIEWED] b3275fa

Description read

[DESCRIPTION-READ] e2356d69d89128927c4a3751ab804ac2bb159cf3a194440c97f155705b8f7837

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed b3275fa94906b7b692e7c65cc9b2003622542808 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] b3275fa

Verdict parsed from the review's SHA-scoped output markers for commit b3275fa94906b7b692e7c65cc9b2003622542808.

False positive or not applicable? A repository writer can comment:
/ai-review override fable b3275fa94906b7b692e7c65cc9b2003622542808 false-positive: <reason, 20 to 500 characters>

@CrysisDeu
CrysisDeu force-pushed the fix/agent-name-space-502 branch 4 times, most recently from 8457133 to 5a69898 Compare October 14, 2026 01:00
@CrysisDeu CrysisDeu changed the title fix(config): migrate legacy space-keyed agents to URL-safe slug keys on load fix(agents): send proxy-unsafe crew names in the request body Oct 14, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/agent-name-space-502 branch 3 times, most recently from e8a36c7 to dc347ef Compare October 14, 2026 01:54
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 14, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/agent-name-space-502 branch from dc347ef to e4646c2 Compare October 14, 2026 03:23
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 22, 2026
@iamwhatever
iamwhatever force-pushed the fix/agent-name-space-502 branch from 96c5838 to 4426ae4 Compare October 22, 2026 07:54
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 22, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

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. _require_owner runs before the name is read from the path or the body, and the body-form name must be a non-empty string (crew_update.py#L116-L139). crew-pr-reviewer will still not approve. This PR adds a network route (routes/agents.py#L56-L61) and changes how the owner-gated handler picks its target, so a human decides. This head has no human approval yet.

Two non-blocking notes: the First Principles lane suggests folding the new describe_manual_change branch into the {name} branch, and that note has no reply. The description says the memory line reads "updated crewmate", but the code now says "updated mate".

Reviewed head: 4426ae4

— crew-pr-reviewer (r120)

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Reply to crew-pr-reviewer r120 (head 4426ae4). No new commit.

  1. Description wording: Fixed. The description now says "updated mate <name> (<fields>)", which matches change_card_catalog.py.
  2. First Principles note (fold the PUT /api/agents branch into the {name} branch): Kept separate on purpose. The two branches differ in two ways: the body form takes the name from b["name"], and it drops name from the field list so it is not shown as an updated field. Folding them needs a conditional for both, which is not simpler. Happy to fold it if a maintainer prefers; it would be a new commit, so I am holding the head for human review as asked.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Backend Tests shard 4 (Linux and Windows) is failing with a DNS error on test_governance_policy_viewer.py::TestNoPolicyDefault::test_enterprise_unnamed_scope_reports_the_baseline. This test makes a real network call and is outside this PR's diff. It is tracked as a main red in issue #23986. Stopping reruns; will rebase once shard 4 is green on main.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Backend Tests (Windows) (7) is failing on test_session_control_steer_delivery.py::test_the_inter_stage_append_persists_before_returning_success. This test is outside this PR's diff (no session-control files changed) and is tracked as a known Windows flake in issue #14218. Run 40194468156, job 121184884681.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Rebased onto main @665bb6b86255a448d19ead6cb4c9f1a02e38ff8b. New head: 85ef862 (still 2 commits).

How the conflict was resolved: the only conflict was in docs/feature-map/README.md, where main had since rewritten neighbouring table rows. I kept main's version of every row and re-added this PR's single phrase to the Crew Members row (or `PUT /api/agents` (name in body; ...) after PUT /api/agents/{name}). The code commit applied cleanly with no change: _require_owner still runs before the name is read from the URL or the body. flake8, isort and black pass on the touched Python files.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

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 docs/feature-map/README.md: I kept main's rows and re-added this PR's or `PUT /api/agents` (name in body; ...) phrase to the Crew Members row. The code commit applied cleanly with no change, and _require_owner still runs before the name is read.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

@iamwhatever head d4d31365e is rebased onto current main and green: every check and AI review lane passes, and PR Readiness passed. Screenshot Evidence hung on a runner checkout (infra), so it has been rerun. Could you re-review when you have a moment? Thanks.

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Re r130 (iamwhatever, crew-pr-reviewer) and the First Principles note on d4d31365e: agreed, the worker-kit routes were missing. No code change; head stays d4d31365e.

Understood that this PR stays reserved for human review.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

@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 85725b71f6251cccf9fcd4e0d411f2bb9ab14103 is green: every check, every AI review lane and PR Readiness pass. Could you re-review when you have a moment? Thanks.

@iamwhatever

Copy link
Copy Markdown
Contributor

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. _require_owner runs before the name is read from the path or the body, and a missing body name returns 400 (crew_update.py#L120-L143). Every AI lane passes, CI is green and PR Readiness is green. The remaining Design and First Principles notes point at work that #20083 already tracks, so they do not block.

Why HOLD: the PR adds a new network route, PUT /api/agents (routes/agents.py#L61-L66), and changes how the owner-gated update handler picks its target crew. Policy reserves both for a human maintainer. There is nothing left for the author to change. Our earlier change requests on this PR are resolved and can be dismissed.

— crew-pr-reviewer (r135)

@bolichen97

Copy link
Copy Markdown
Contributor

@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 (PUT /api/agents) and changes how the owner-gated handler picks its target crew, so it needs a human review, still stands. All checks pass on this head (93 ok, 0 red, 0 pending).

iamwhatever
iamwhatever previously approved these changes Nov 4, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Reply to the First Principles BLOCK (Framing contradicted by diff, items 3-6), head 41de564b8a342599e4eb386f11aab0024b25733f.

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 main. That is a recorded owner choice, so this push keeps it and does not drop the #20083 work.

What changed in this push:

  • History rebuilt on current main as 2 commits: this PR's own fix (squashed with its docs commit) and fix(agents): keep proxy-unsafe crew names out of every agent route path #28628's commit. Tree is the same as before apart from the gate fixes below.
  • Gate fixes only: handlers/agents.py back to 2,000 lines (one-line import, walrus, shorter comment; same behaviour), history narration removed from comments, black on test_agents_endpoints_owner_auth.py.
  • The non-frozen body sections now describe the twins: What changed, Auth review guide (all ten twins, the shared owner gate, the tests that pin it), Tests, Repro, and Related Issues (Fixes #20083).

What this push cannot do: the **Goal:** line and ## Not a goal (including the Known limitation note) are frozen, so they still describe the narrower scope. The lane's own clear condition is "a human amends the Goal". @CrysisDeu, to clear it pick one:

On Note item 2 (two mechanisms for one cause): the body form stays for PUT /api/agents because it already shipped in this PR's own scope and has its own parity tests; replacing it with a PUT /api/agents/b64/{name_b64} twin is a design change for the owner, not a gate fix.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Reply to the First Principles BLOCK on 0d2495a51c00bc4a2f0ff9f12a41efb4af76ec54 (body-form PUT /api/agents duplicates the base64url twin).

Kept, not removed. The body-form PUT /api/agents is this PR's own reviewed design for #19976. It went through many review rounds as the fix, and the base64url twins arrived later from #28628 (stacked on this branch and merged into it). Swapping the save over to a PUT /api/agents/b64/{name_b64} twin and deleting the body route would reverse that recorded design, so that call is for a maintainer, not a gate fix.

Fixed: the Bob's disagreement. That part was a real defect in code this PR adds. The browser's save used encodeURIComponent(name) !== name, which misses !'()*, while the server's agent_record_write uses quote(safe=""). Head f9fa6c4efb40df263f32fb5361c5b633ea764a4a adds needsProxySafePath in website/src/api/agentPath.ts (the predicate agentPath already used), and both agentPath and updateKirocrewAgent now call it. So every name now has one spelling on both sides. agentPath.test.ts pins Bob's, a(b), x*, hi! and Nova Sky.

What clears the lane is a maintainer choice:

  • Keep both mechanisms: record the override for the duplicate finding.
  • Or ask for the save to move onto the base64url twin, so the body route goes away.

The Goal / Not a goal mismatch from the earlier round still stands, since those sections are frozen (see the comment above).

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

CI note on head f963fa9: the only red is Backend Tests (3.12, 7) (and Coverage Gate after it), in test_denied_commands_security_cost.py::test_the_scan_is_linear_not_quadratic. It is a timing check that ran 0.501s and then 0.599s against a 0.5s limit, and it is tracked as flake #28212. This PR does not touch that path. All AI lanes pass on this head.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. agent_url_path.py:48: _SEGMENT = re.compile(r"[A-Za-z0-9_-]+"), used by decode_agent_name to validate an incoming path segment. Please use a plain character check instead, for example a module-level frozenset(string.ascii_letters + string.digits + "-_") and segment and all(c in _SEGMENT_CHARS for c in segment). The re-encode round-trip check you already do stays as the real gate.
  2. 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 or slice on the last index that is not =.

The tests you already have should carry over unchanged. All 97 checks pass on this head.

CrysisDeu and others added 2 commits November 7, 2026 07:08
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 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. agent_url_path.py: _SEGMENT is now _SEGMENT_CHARS = frozenset(string.ascii_letters + string.digits + "-_"), with an explicit empty-segment check before all(c in _SEGMENT_CHARS for c in segment). The re-encode round-trip is still the final gate.
  2. agentPath.ts: base64Url uses replaceAll('+', '-'), replaceAll('/', '_') and a trailing-= loop.
  3. You also replaced the third pattern, /[!'()*]/.test(name) in needsProxySafePath, 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.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

@bolichen97 Both regexes are gone, head b3275fa (rebased on main, CI green):

  • agent_url_path.py: decode_agent_name checks the segment against a frozenset(string.ascii_letters + string.digits + "-_"); the re-encode round-trip is still the real gate, and re is no longer imported.
  • agentPath.ts: base64Url uses replaceAll plus a trailing-= loop, and needsProxySafePath checks !'()* with includes instead of /[!'()*]/.
    No other regex is added in product code; tests unchanged.

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

Labels

None yet

Projects

None yet

4 participants