Repository navigation
fix(design-tweak): refuse a request id that ends in a newline - #34592
Conversation
Python's $ also matches just before a trailing newline, so the request id check accepted "req1\n" as a second spelling of "req1". A follow-up link carrying such an id was stored as sent, and send, delivered, clear, delete, delete-comment and thread each looked the id up instead of answering 400. Anchor the request id pattern at \Z and register the Design Tweak backend in the regex-anchor contract. The upstream header name pattern sees no newline (http.client stops at a malformed header line), so it changes only to keep the package free of $, including the one inside its character class.
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS This fix works at the mechanism level. It changes the one shared validator that every id route uses ( Notes
What this change shipsInventory (4 items) — 3 justifiedIntent: make Design Tweak refuse a request or comment id that ends in a newline, as it refuses any other malformed id. FIX.
[FIRST-PRINCIPLES-REVIEWED] 4eec4d3 Description read[DESCRIPTION-READ] 7fa783016d30104d2ca2722540b87b7703c451c1b83445742228bef397c87cce That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: it is the repo's existing [DESIGN-REVIEWED] 4eec4d3 Description read[DESCRIPTION-READ] c1879db4421a77749555f63d15b4b46a954206e11c622a30294bc4479000dc46 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 |
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: |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (5 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: anchors the design-tweak request-id and upstream header-name patterns with \Z, so an id ending in a newline is refused with 400 like any malformed id; adds route and anchor-contract tests.
bolichen97
left a comment
There was a problem hiding this comment.
Read the whole diff at 4eec4d3 (two backend files and three test files). Approving without auto, since the author holds it.
What I checked against main:
- The change is anchor-only.
REQUEST_ID_REgoes from$to\Z, and_HEADER_NAME_REgets the same anchor with$escaped inside the class. Both patterns keep their character sets, so no new pattern is added, and the two are registered in the anchor-contract test. - A request id ending in a newline passed on main because
$matches before a trailing newline. Main then did nothing useful with it:request_filejoins it to<id>.json, which names a file that does not exist, so the send, delivered, clear and delete routes find nothing. Only the follow-up link stored the string. The submit route already sets an invalidfollowUpToto an empty string, and the test shows the newline-ended one now gets the same treatment. So this applies the validator main already has, with no new kind of refusal. - The routes now answer a newline-ended id with the 400 they give any other malformed id. No request that worked on main stops working, and nothing here creates a file whose name has a newline.
- The header name case keeps the same character set. The comment says http.client never yields a name with a newline, so real traffic does not change.
- Tests cover the file lookup, each route, both comment-id routes, the follow-up link, the valid header-name characters, and the contract list. All 96 checks pass.
Problem / Motivation
Goal: a Design Tweak request id that ends in a newline is refused, like every other id the app refuses.
design_tweak/backend/request_state.pychecks every request id and comment id withREQUEST_ID_RE(also bound asserver._ID_RE). It is$-anchored and used with.match, and Python's$also matches just before a trailing"\n". On mainPOST /submitwith"followUpTo": "prev-comment-id\n"stores that value on the comment, and/send,/delivered,/clear,/delete,/delete-commentand/threadtake?id=req1%0Aas an id and look it up (404 or an empty result) instead of answering 400 like any other malformed id.test/test_regex_anchor_contract.pyholds a package's request-path validators to\Z, package by package (#12161 began it; #34336, #34465 and #34534 registered Mochi, pptx-maker and Meetings). Design Tweak is not registered there yet.Why it matters
The id check is the one gate between a query string or JSON body and the queue file lookup, and the stored follow-up link is read back by the agent as an id. A value with a hidden newline passes the gate that is meant to allow only letters, digits,
.,_and-.Not a goal
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/design_tweak/backend/request_state.py:REQUEST_ID_REends at\Z, with the reason in a comment.src/kiro_crew/apps/builtins/design_tweak/backend/server.py:_HEADER_NAME_REends at\Zand writes the$in its character class as\$. It judges a header name from the dev server's response, andhttp.clientstops parsing at a malformed header line, so no name with a newline reaches it and a match is unchanged. It changes only because the contract walks the wholebackendpackage and flags every unescaped$.test/test_regex_anchor_contract.py:design_tweak.backendjoins_REQUEST_PATH_PACKAGES, and the two patterns join_VALIDATORSwith a valid input each.test/test_design_tweak_queue_routes.py: a new class checks that the six id routes answer 400 for an id or comment id plus"\n", that_request_filerefuses it, and that a follow-up id plus"\n"is stored as empty.test/test_design_tweak_backend_dev_proxy.py: the header name check refuses a name plus"\n"and still accepts every token character, including$.Backwards compatibility
Compatible for every valid value: the patterns accept exactly what they did, minus a value with one trailing newline.
Tests
valid + "\n", the structural walk lists three$-anchored names, six routes answer 404 instead of 400,_request_filedoes not raise, the follow-up id is stored with its newline).test/test_design_tweak*.py, the package's owntests/andtest/test_regex_anchor_contract.py: 722 passed, three runs in a row at-n0. Another 30 fail the same way on main in this environment (static preview cases intest_design_tweak_backend.pythat answer 403 instead of 200, andTestClassifyProjectintest_design_tweak_devproc.py); neither file is touched here.flake8,isort, the black gate, the comment-history gate, CI's semgrep rules and source gates, and the flake-pattern and wait-discipline ratchets pass locally.python -m pytest test/test_design_tweak_queue_routes.py test/test_design_tweak_backend_dev_proxy.py test/test_regex_anchor_contract.py -n0Manual verification
N/A: the tests call the route handlers and the id helper, on real temporary directories.
Sibling sweep
Swept: every module-level compiled pattern under
src/kiro_crew/apps/builtins/design_tweak/backendwith an unescaped$and nore.MULTILINE; the contract's structural walk lists none after this change.Sibling:
src/kiro_crew/apps/builtins/design_tweak/backend/request_state.py-- changed hereSibling:
src/kiro_crew/apps/builtins/design_tweak/backend/server.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 id is answered the way other malformed ids are.
Related Issues
None open for Design Tweak. Same class as #34199, #34238, #34336, #34465 and #34534; the contract began in #12161.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement