Repository navigation
fix(deploy): quote the copyable remediation command in the TTL 409 - #19784
Conversation
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Check before merge: after this change, the next registry write permanently erases a hand- or agent-edited What this change shipsInventory (6 items) — 6 justifiedIntent: make the deploy 409's copyable fix command safe to paste whatever the stored profile or region holds. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] 5c2f9cd Description read[DESCRIPTION-READ] b71ce1097dc189f425d987184fac11af417ff39699abab515bd63b6d61238dfa That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that [DESIGN-REVIEWED] 5c2f9cd Description read[DESCRIPTION-READ] abfc7e5b0f6d396b9a99a07522c75660378a82f624d39913787cda5c7169510b 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 |
UX Review (Opus 5.5) — ⏭️ skippedRevision |
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: |
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: |
buluoray
left a comment
There was a problem hiding this comment.
Verdict: REQUEST CHANGES (head 608344be26)
What it fixes
The reaper_required 409 hands the dashboard a copyable fix command built with " ".join. A stored region such as us-west-2;touch${IFS}... therefore ran a second command when the user pasted it. The fix has two layers: shlex.join in the renderers, and validating registry entries when they are loaded.
What I verified
deploy/handlers.py:176-189_shell_line=shlex.join. Both renderers use it (:225,:255), and paths are spelled withas_posix(). The&&is still emitted unquoted between the two steps, as intended. Plain--profile dev --region us-west-2output is byte-identical.deploy/profiles.py:158-192_well_formed_entryrequires the RAW stored value to equal whatvalidate_fieldreturns. It is applied at:220,:236and the legacyconfig.jsonpath.- Mutations, each run on its own:
shlex.join→" ".jointurns 4 tests red (incl.test_template_and_script_paths_are_quoted_words); loader filter disabled turns 7 red; raw-vs-cleaned comparison weakened turnstest_registry_drops_an_entry_the_request_path_would_refuse[padded-region]red. - New tests plus the deploy/aws_control suites I ran pass at this head.
Blocking
1. The loader drops names a shipped writer registers, and then silently switches the default to a different account. The PR's writer sweep says every writer already refuses what the loader now drops. That is not true for the AWS control app. apps/builtins/aws_control/backend/routes.py:808 gates registration with aws_consent._PROFILE_RE (aws_consent.py:151), which deliberately admits @ and =. The loader checks against PROFILE_SPEC (constants.AWS_PROFILE_NAME_RE), which admits neither. I seeded a registry with default dev@corp (eu-central-1) and a second entry other. At this head:
load_registry()returns onlyother, anddefaultbecomesother(profiles.py:223-224, picking the first surviving entry).resolve_profile("")returns('other', 'us-east-1'). A deploy that names no profile now goes to a different AWS account and region with no error.- A no-op
locked_registry()write then rewrites the file withoutdev@corp, so the entry is permanently erased from disk.
Fix:
- Have the loader accept the union of what every writer can store.
@and=are inert onceshlex.joinquotes them, and the AWS CLI accepts them. - When the stored default is the entry that was dropped, set
defaultto""(so the user gets 400 "not configured"). Do not fall back to another profile. - Add a test that loads a registry whose default is an
@name, and assert both the default and the on-disk file after a write.
Non-blocking follow-ups
src/kiro_crew/docs/deploy-web.md(around:212) could say that malformed registry entries are ignored, and that the warning log names them.
Not verified
- I did not run the frontend, and I did not do a live paste into bash/Git Bash. I checked quoting only through
shlex.splitin the tests and by reading the code. - I did not trace
publish/personal_drive.py's registry reader beyond the PR's description.
608344b to
307ad8c
Compare
|
@buluoray thanks, the
PR body's writer sweep re-run on |
|
This PR fixes the TTL 409's copy-paste fix command at the root, in two layers: both renderers now use |
307ad8c to
b4a22dd
Compare
|
|
|
@iamwhatever both addressed at |
|
HOLD at 6e2cb91. This changes command-injection protection and the AWS profile registry. Dropped registry entries can later be erased on a write. Security, credentials and data-removal changes require a human maintainer here. @buluoray's change request is also still active. Please obtain that re-review rather than treating a claimed fix as clearance. Answer the current Design review about valid CLI names excluded by the stored-name rules. Also settle the current First Principles items with source-backed replies. I have not executed the copied command, accessed AWS, or run tests. — crew-pr-reviewer (r99) |
|
Answers for the current (PASS) lane notes on Design — a hand-edited entry with a valid AWS CLI name holding First Principles item 2 — First Principles item 6 — First Principles item 8 — @buluoray — your three blocking points from |
mbriones98
left a comment
There was a problem hiding this comment.
Checks green and PR Readiness passed at 6e2cb91; non-feature change.
buluoray
left a comment
There was a problem hiding this comment.
Re-review at 6e2cb91. Approve on the code; it needs a rebase before it can merge.
Both points from my change request at 608344b are fixed:
- Names the AWS control app registers are kept. Stored names are checked against
STORED_PROFILE_SPEC(deploy/profiles.py), whose pattern admits@and=and whose first-character set is a superset ofaws_consent._PROFILE_RE, so every name that writer can store loads.test_registry_keeps_names_the_aws_control_app_registersloadsdev@corpas the default, resolves it, quotes it in the remediation command, and checks the on-disk file still has both names after a write. - A dropped default no longer moves to another account.
_parse_registryclears the default to""when its own entry was present but malformed, and still falls back to the first profile only for a stale pointer that names no entry.str()on the raw names keeps a bare-number account-style name from being mistaken for a missing one.test_a_dropped_default_clears_instead_of_switching_accountspins both branches. The deploy-web.md line now says malformed entries are ignored with a warning and what the next write does.
The two v2 loaders now share _parse_registry, and the v1 config.json path is validated too. test/test_deploy_remediation_quoting.py passes on this head (16).
Before merge: src/kiro_crew/deploy/handlers.py conflicts with main. #22145 split that file into guards, content and sites owners, so _shell_line and the two renderers need to move with the code they belong to rather than a line-level merge. The approval will be dismissed by the rebase push; I will re-check the moved code then.
Follow-up question, not blocking: REGION_SPEC is narrower than aws_consent._REGION_RE. If the AWS control app can store a region REGION_SPEC refuses, the loader would now drop that entry too. Worth one line confirming no shipped writer stores such a region.
6e2cb91 to
41e5373
Compare
|
Rebased onto main after #22145 split @buluoray @mbriones98 GitHub dismissed your approvals on the force-push; could you re-approve once CI is green? |
Security Scope Review -- 🔴 could not complete (fails closed)No scope verdict for |
The finite-TTL 409 hands the dashboard a `remediation` command behind a copy button. Its `--profile` and `--region` words come from the deploy profile registry, an agent-writable file, so a stored value such as `us-west-2;touch /tmp/x` ran as a second command when pasted. Two layers now hold that line: * `_reaper_remediation` / `_base_remediation` (now in `deploy/handlers_guards.py`, where #22145 moved them) render every word with `shlex.join`; the script and template paths are spelled POSIX-style (`as_posix`) so Windows backslashes are not quoted into the command. * `load_registry` drops an entry whose name or region fails the stored field spec, clears a dropped default instead of switching accounts, and validates the legacy single-profile config the same way. Fixes #17789
41e5373 to
5c2f9cd
Compare
|
HOLD at 5c2f9cd, reserved for human review. This PR changes two things a human must review: the command-injection quoting of the copyable remediation command, and which AWS profile registry entries are kept. Dropped entries are also erased from disk on the next write. See KiroCrew/src/kiro_crew/deploy/handlers_guards.py Lines 170 to 215 in 5c2f9cd KiroCrew/src/kiro_crew/deploy/profiles.py Lines 168 to 240 in 5c2f9cd I found no defect:
The rebase moved the renderers into To clear the hold, get a human re-review of this head. Optionally, add — crew-pr-reviewer (r116) |
Problem / Motivation
Goal: The fix command in the deploy "auto-cleanup missing" error is safe to copy and paste, whatever the stored profile name or region contains.
A deploy with a time limit answers 409 when the account has no auto-cleanup. The payload carries a
remediationcommand, and the dashboard shows it with a copy button. That command was built with" ".join(parts), no shell quoting. The--profileand--regionwords come from the deploy profile registry (profiles.json), a file agents may write and thatload_registrydid not validate. A stored region such asus-west-2;touch${IFS}/tmp/pwnedmakesdescribe-stacksfail, so this exact 409 is reached every time, and the pasted command runstouch /tmp/pwnedon the user's machine, outside any sandbox.Why it matters
The copy button invites the user to run the string as-is. A hostile or merely odd registry value becomes a command the user executes with their own credentials.
Not a goal
nameandregion.ArtifactDeployPage.tsx; its profile now comes from a validated registry, and the script path it receives is already a quoted shell word.What changed (motivation → approach → change)
The pasted command broke because two layers were missing: the renderer trusted its words, and the registry trusted its file.
_reaper_remediation/_base_remediation(deploy/handlers.py)" ".join(parts)shlex.join(parts); paths spelled withas_posix()load_registry(deploy/profiles.py)namenameandregionpassSTORED_PROFILE_SPEC/REGION_SPEC; a dropped default clearsQuoting: every word of both commands goes through
shlex.join. Plain words stay bare, so--profile dev --region us-west-2reads exactly as before. A value with spaces, quotes or;/$is single-quoted and reachesinstall-reaper.shorawsas one literal argument. The command is a POSIX shell line on every host (the script is bash and the base step chains with&&), so the script and template paths are spelled POSIX-style: on Windowsstr(Path)carries backslashes thatshlex.joinwould single-quote, whileC:/Users/...stays bare and runs as-is in Git Bash.Registry:
_well_formed_entrychecks a storednameagainstSTORED_PROFILE_SPEC, the union of every writer's charset (the deploy routes'PROFILE_SPECplus the@and=the AWS control app's register route admits), andregionagainstREGION_SPEC. An entry is kept only when the validator returns the stored value unchanged (validate_fieldstrips NUL and padding before matching, so a cleaned copy passing is not enough). A malformed entry is dropped on load with one warning log naming it. When the dropped entry was the default,defaultbecomes""so a deploy naming no profile gets 400 "not configured" instead of silently going to another account; a default that never named an entry still falls back to the first profile as before. This is a load-time guarantee: a later profile edit may pick a new default under that route's own rules (the AWS control app's unregister fills an empty default with the first kept profile), which is unchanged behavior. The legacy single-profileconfig.jsongoes through the same check. An empty region is still fine;make_entryfills in the default.docs/deploy-web.mdsays so, including that the next write erases the entry.Backwards compatibility
Breaking: a
profiles.jsonentry whosenamefailsSTORED_PROFILE_SPECor whoseregionfailsREGION_SPECis no longer served; the registry reads as if it were absent, a default pointing at it clears, and the next registry write (profile POST/PUT/DELETE, aws_control register/unregister, anylocked_registry()block) saves the filtered list, erasing the malformed entry from disk for good. Writer sweep on origin/main @ b6a7b33:deploy/handlers.py:_save_config(PUT /config, both fields validated withPROFILE_SPEC/REGION_SPEC),deploy/handlers.py:_handle_profiles_postand_handle_profiles_put(same),deploy/profiles.py:create_aws_profile(same),apps/builtins/aws_control/backend/routes.pyregister route (name viaaws_consent._PROFILE_RE, which also admits@and=; region viaaccounts.configured_region, validated against the region pattern).STORED_PROFILE_SPECis the union of those two name charsets, so every shipped writer's output survives the loader; only a hand- or agent-edited file is affected.Reader:
deploy/handlers.py:_resolve_profile-- chat|app|crew page -- a dropped default answers 400 "not configured" instead of a 409 carrying the hostile command;test_registry_drops_an_entry_the_request_path_would_refuseReader:
deploy/handlers.py:_load_config/_handle_profiles_list-- crew page -- lists only well-formed entriesReader:
publish/personal_drive.py:_resolve_profile-- chat|app -- same registry contract, unknown or dropped names resolve to its existing "not registered" pathReader:
apps/builtins/aws_control/backend/routes.pyregister/unregister -- app -- re-adding a dropped name writes a validated entryTests
test/test_deploy_remediation_quoting.py, platform independent:nameandregion(separator,${IFS}, space, both quote styles,$(id)) survive as single shell words after their flag, for both renderers; notouchword escapes. Removingshlex.jointurns these red.&&, both steps quoted.load_registrydrops an entry with a hostile region, a hostile name, an option-shaped name, a non-string region, a NUL inside the name, a space-padded region, or a bare-number name, logging one warning per dropped entry; the default that named it clears andresolve_profile("")isNone. The NUL and padding cases pin that the RAW stored value must pass, not the validator's cleaned copy.@and=(what the AWS control app registers) are kept, resolve as default, render as one quoted word, and survive a no-op locked write on disk.config.jsonpath is validated too.Existing remediation tests keep passing: plain profile/region words are unchanged by
shlex.join.Intended? / Repro
Intended? No. Checked the introducing commits (#102 added
_reaper_remediation, #17744 added_base_remediation), their docstrings,docs/and the deploy skill: none says the command is meant to be unquoted; #17744's own review raised this issue. The registry module's docstring says "All values are schema-validated before reaching argv", which the load path did not honor.Repro, without the test suite: a standalone script seeded
profiles.jsonwith{"name": "p", "region": "us-west-2;touch${IFS}<tmp>/pwned"}, calledprofiles.resolve_profile("")andhandlers._reaper_remediationexactly as_do_deploydoes, then ran the string withbash -cagainst a stubinstall-reaper.sh. On main: the stub received--region us-west-2and the marker file was created. With this change: the entry is dropped (resolve_profilereturnsNone), and the renderers called directly with the same values print--region 'us-west-2;touch${IFS}...', the stub receives the literal, and no marker is created.Manual verification
Covered by the standalone repro above. N/A beyond that — unit coverage sufficient; the 409 path itself is unchanged.
Screenshots / video
N/A — no frontend change.
Related Issues
Fixes #17789
Pattern harvest
Rule candidate: semgrep
Pattern: a string built with
" ".join(...)or an f-string that is returned as aremediation/command/hintfield, or passed toshlex.split/subprocesswithshell=True, withoutshlex.join/shlex.quote.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)