Skip to content

fix(design-tweak): refuse a request id that ends in a newline - #34592

Merged
javenciu merged 1 commit into
mainfrom
fix/design-tweak-anchor-validators
Nov 10, 2026
Merged

javenciu merged 1 commit into
mainfrom
fix/design-tweak-anchor-validators

Conversation

@javenciu

Copy link
Copy Markdown
Contributor

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.py checks every request id and comment id with REQUEST_ID_RE (also bound as server._ID_RE). It is $-anchored and used with .match, and Python's $ also matches just before a trailing "\n". On main POST /submit with "followUpTo": "prev-comment-id\n" stores that value on the comment, and /send, /delivered, /clear, /delete, /delete-comment and /thread take ?id=req1%0A as 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.py holds 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

  • No other package's patterns.
  • No change to what a valid id is.

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_RE ends at \Z, with the reason in a comment.
  • src/kiro_crew/apps/builtins/design_tweak/backend/server.py: _HEADER_NAME_RE ends at \Z and writes the $ in its character class as \$. It judges a header name from the dev server's response, and http.client stops 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 whole backend package and flags every unescaped $.
  • test/test_regex_anchor_contract.py: design_tweak.backend joins _REQUEST_PATH_PACKAGES, and the two patterns join _VALIDATORS with 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_file refuses 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

  • Before: on main the 12 new or extended checks fail (the two patterns accept valid + "\n", the structural walk lists three $-anchored names, six routes answer 404 instead of 400, _request_file does not raise, the follow-up id is stored with its newline).
  • After: every test/test_design_tweak*.py, the package's own tests/ and test/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 in test_design_tweak_backend.py that answer 403 instead of 200, and TestClassifyProject in test_design_tweak_devproc.py); neither file is touched here.
  • The whole backend suite on a local merge with current main fails only the tests this environment fails on main itself (optional dependencies it lacks).
  • No test creates a file whose name holds a newline.
  • 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.
  • Reproduce: python -m pytest test/test_design_tweak_queue_routes.py test/test_design_tweak_backend_dev_proxy.py test/test_regex_anchor_contract.py -n0
  • Proof: PROVEN test/test_design_tweak_backend_dev_proxy.py::TestUpstreamHeaderNamesAreTokens::test_a_trailing_newline_is_not_part_of_a_token, test/test_design_tweak_queue_routes.py::TestTrailingNewlineIsNotAnId::test_the_request_file_lookup_refuses_an_id_ending_in_a_newline, test/test_design_tweak_queue_routes.py::TestTrailingNewlineIsNotAnId::test_a_request_id_ending_in_a_newline_is_refused[/send-_h_send], test/test_design_tweak_queue_routes.py::TestTrailingNewlineIsNotAnId::test_a_request_id_ending_in_a_newline_is_refused[/delivered-_h_delivered], test/test_design_tweak_queue_routes.py::TestTrailingNewlineIsNotAnId::test_a_request_id_ending_in_a_newline_is_refused[/clear-_h_clear] (head 4eec4d3)

Manual 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/backend with an unescaped $ and no re.MULTILINE; the contract's structural walk lists none after this change.
Sibling: src/kiro_crew/apps/builtins/design_tweak/backend/request_state.py -- changed here
Sibling: src/kiro_crew/apps/builtins/design_tweak/backend/server.py -- changed here

Pattern harvest

Rule candidate: none new. test/test_regex_anchor_contract.py already 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

  • 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

Contribution License Agreement

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.
@javenciu
javenciu requested review from a team and KiroCrewCaptain as code owners November 10, 2026 15:22
@javenciu
javenciu enabled auto-merge (squash) November 10, 2026 15:22
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 4eec4d381c13d5a355a4f5d1116af66c0352e54b touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 4eec4d381c13d5a355a4f5d1116af66c0352e54b — 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

This fix works at the mechanism level. It changes the one shared validator that every id route uses (_ID_RE appears at 9 call sites in http_api.py), and it uses the repo's existing \Z contract instead of adding a new one.

Notes

  • Item 2 — rides along: the description says the header-name change happens "only because the contract walks the whole backend package." No user-visible harm is named, and the item exists only to satisfy the scan this PR switches on for the package.

What this change ships

Inventory (4 items) — 3 justified

Intent: make Design Tweak refuse a request or comment id that ends in a newline, as it refuses any other malformed id. FIX.

  1. Six id routes answer 400 instead of looking up an id that ends in \n, and /submit drops a follow-up link that ends in \n — justified
  2. The upstream header-name check is anchored at \Z with $ escaped; no match changes — rides along
  3. Design Tweak's backend is registered in the regex-anchor contract, so a $-anchored pattern there fails the build — justified
  4. New tests for the routes, the lookup helper and the header token — justified

[FIRST-PRINCIPLES-REVIEWED] 4eec4d3

Description read

[DESCRIPTION-READ] 7fa783016d30104d2ca2722540b87b7703c451c1b83445742228bef397c87cce

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: it is the repo's existing \Z fix, applied to one built-in that adoption-pins.json does not pin, and it narrows only newline-ended ids.

[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 .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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 4eec4d3

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

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

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 4eec4d3

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

@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 Nov 10, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 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.

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_RE goes from $ to \Z, and _HEADER_NAME_RE gets 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_file joins 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 invalid followUpTo to 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.

@javenciu
javenciu merged commit 026b96c into main Nov 10, 2026
100 checks passed
@javenciu
javenciu deleted the fix/design-tweak-anchor-validators branch November 10, 2026 17:07
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants