Repository navigation
fix(aws-control): refuse a drive key segment or install id that ends in a newline - #34888
Conversation
…in a newline Python's $ also matches just before a trailing newline, so validate_key accepted "a.txt\n" as a second object key beside "a.txt", and a bucket folder named "<32 hex>\n" read as an install id when listing other installs' backups and classifying an archive's owner. Anchor the AWS Control backend's two request-path patterns at \Z and register the package in the regex-anchor contract.
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. This is the repo's established [DESIGN-REVIEWED] f23d94f Description read[DESCRIPTION-READ] 61f7cac4c93708acfb8024d0c6a632676b9ab19dc27e16318d5edc8c143ec149 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 Nothing to check. What this change shipsInventory (4 items) — 4 justifiedIntent: refuse an AWS Control drive key or backup install id that ends in a hidden trailing newline (FIX).
[FIRST-PRINCIPLES-REVIEWED] f23d94f Description read[DESCRIPTION-READ] 70bae3876d9e2b30db8c0319cba552aa94a5d5a7d5a223605be24296088c15a5 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: |
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: |
bolichen97
left a comment
There was a problem hiding this comment.
Approve on f23d94f. I read the whole diff (163 lines), tests included.
- Strictness check, same ruling as #34592: main's
_KEY_SEGMENT_REand_INSTALL_ID_REalready mean to allow only their listed charset and length, and to reject anything else.$let one trailing\nslip past that. Ending at\Zcloses only that gap. A valid key segment or install id is unchanged, and the "without the newline are accepted" tests pin that. So it adds no new refusal class. - No new regex: both are main's existing patterns, with only the end anchor changed from
$to\Z.catalog.pyandbackup.pyimport the same_INSTALL_ID_REobject, so one edit covers them. - The tests cover
validate_keyon a trailing and a mid-segment newline, the upload route answeringinvalid_keybeforeput_file,classify_keynot treating<32 hex>\nas another install, and_stored_identityrefusing a newline id. AWS Control is registered intest_regex_anchor_contract.py, so the anchor stays. - All 96 checks are green, and nobody else has an open change request. Auto-merge is already set by javenciu.
* fix: port the wheel copy's newline refusal and crew runtime changes Carries kirodotdev/KiroCrew#34888 (a drive key segment or install id ending in a newline is refused), #24732 (the crew bundle excludes the mimocode credential file), #28535 (the crew container states the empty read-only path defaults) and #26624 (the hard-link refusal test runs on Windows). * test: pin the Kiro Crew test dependency at a commit carrying #24732 --------- Co-authored-by: KiroCrewCaptain <312312717+KiroCrewCaptain@users.noreply.github.com>
Problem / Motivation
Goal: an AWS Control drive key or backup install id that ends in a newline is refused, like every other malformed value.
aws_control/backend/storage.pychecks each segment of a drive object key with_KEY_SEGMENT_RE, andaws_control/backend/backup_parts/identity.pychecks install ids with_INSTALL_ID_RE. Both are$-anchored and used with.match. Python's$also matches just before a trailing"\n". On main:validate_key("a.txt\n")returns no error. The drive upload, folder, move, delete, download, share, preview and backup restore routes call it on a key from the query string or JSON body, sokey=a.txt%0Areaches the write path (on main the upload route answersempty_uploadfor an empty body instead ofinvalid_key). A newline in a middle segment (photos\n/a.txt) passes too.<32 hex>\nreads as an install id.classify_keyreports it as another install's archive with an owner id that holds a newline, andother_install_idsadds it to the set of other installs.idends in a newline is accepted as this install's id.test/test_regex_anchor_contract.pyholds a package's request-path validators to\Z, package by package (#12161 began it; #34336, #34465, #34534, #34592 and #34740 registered Mochi, pptx-maker, Meetings, Design Tweak and Spec Builder). AWS Control is not registered there yet.Why it matters
The key check is the gate between a request and an S3 object name. A key with a hidden trailing newline passes a gate meant to allow only letters, digits, spaces and
._()+@=-, and names a second object that looks the same as the first in the drive.Not a goal
aws_control/crew/._BUCKET_NAME_REand_VERSION_ID_REare used withfullmatchand are untouched.What changed (motivation → approach → change)
Approach: the repo's existing fix for this class. Anchor at
\Z, which matches only at the true end of the string, and register the package so the contract keeps it that way.src/kiro_crew/apps/builtins/aws_control/backend/storage.py:_KEY_SEGMENT_REends at\Z, with the reason in its comment.src/kiro_crew/apps/builtins/aws_control/backend/backup_parts/identity.py:_INSTALL_ID_REends at\Z, with the reason in its comment.catalog.pyandbackup.pyimport this same object, so one edit covers every use.test/test_regex_anchor_contract.py:aws_control.backendjoins_REQUEST_PATH_PACKAGES, and the two patterns join_VALIDATORSwith a valid input each.test/test_aws_control_trailing_newline.py: new file. It checksvalidate_key(last segment and middle segment), the upload route (400invalid_key, nothing written),classify_keyand a stored install id. No test creates a file or folder whose name holds a newline.Backwards compatibility
Compatible for every valid value: the patterns accept exactly what they did, minus a value with one trailing newline. A client that sent a key ending in a newline now gets 400
invalid_key.Tests
validate_keyaccepts four newline keys, the upload route answersempty_uploadinstead ofinvalid_key,classify_keyreturnsotherwith a newline in the owner, a stored id with a newline is an identity, both patterns acceptvalid + "\n", and the structural walk listsstorage._KEY_SEGMENT_REandidentity._INSTALL_ID_RE, plus thecatalogalias of the second).test/test_aws_control*.py,aws_control/tests/andtest/test_regex_anchor_contract.py: 2076 passed, three runs in a row at-n0.tests/, on a local merge with current main fails only the tests this environment fails on main itself (optional dependencies it lacks).flake8,isort, the black gate, the comment-history gate, CI's semgrep rules, frontend, source and mypy checks, the own-mp leak audit, and the flake-pattern and wait-discipline ratchets pass locally.python -m pytest test/test_aws_control_trailing_newline.py test/test_regex_anchor_contract.py -n0Manual verification
N/A: the tests call the route handler and the helpers.
Sibling sweep
Swept: every module-level compiled pattern under
src/kiro_crew/apps/builtins/aws_control/backendwith an unescaped$and nore.MULTILINE; the contract's structural walk lists none after this change. The only other compiled patterns there (_BUCKET_NAME_RE,_VERSION_ID_RE) have no$and usefullmatch.Sibling:
src/kiro_crew/apps/builtins/aws_control/backend/storage.py-- changed hereSibling:
src/kiro_crew/apps/builtins/aws_control/backend/backup_parts/identity.py-- changed herePattern harvest
Rule candidate: none new.
test/test_regex_anchor_contract.pyalready states the rule; this registers one more package under it.Screenshots / video
Why no screenshot: no markup change; a refused key is answered the way other malformed keys are.
Related Issues
None open for AWS Control. Same class as #34199, #34238, #34336, #34465, #34534, #34592 and #34740; the contract began in #12161.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement