Repository navigation
fix(spec-builder): refuse a spec name or slot key that ends in a newline - #34740
Conversation
Python's $ also matches just before a trailing newline, so the spec name check accepted "live\n" as a second spelling of "live", the slot key check accepted a key with a newline that becomes a session file name, and the approval hash check let "<digest>\n" reach the document comparison (409 instead of 400). Anchor the Spec Builder backend's validators at \Z and register the package in the regex-anchor contract.
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks: a fix at mechanism level, using the repo's existing What this change shipsInventory (4 items) — 4 justifiedIntent: stop Spec Builder from accepting a spec name, slot key or approval hash that has a hidden trailing newline (FIX).
[FIRST-PRINCIPLES-REVIEWED] 2086f97 Description read[DESCRIPTION-READ] 47e8e0ef3aa1a0471f25b8702dbef5390f1b8180c86d0dc7f49644a408ecd50a 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: |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. This uses the repo's existing [DESIGN-REVIEWED] 2086f97 Description read[DESCRIPTION-READ] c1abba3f4f73ebfc7d8b80c95aeb31d883dae5640c75a94bfe745dd4ab699685 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 |
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.
Approved. The review checked this head (2086f97) and found nothing blocking. In parsers.py, the anchors on _NAME_RE, _SLOT_KEY_RE, _SLOT_SUFFIX_RE and _SHA256_RE change from $ to \Z. The callers in controls.py, execution_state.py, repository.py, runtime.py and repository_duplicate.py pick that up, and every valid name, slot key and hash is still accepted. The new test file and test_regex_anchor_contract.py pass on this head (101 passed). Putting $ back on each pattern makes at least one test fail, so every changed anchor is pinned.
Done well: the tests go through the real entry points. They cover the index loader dropping a planted "live\n" key, the slot key fallback, and the approve route answering 400 with nothing recorded. No test creates a file name that contains a newline, so they stay safe on Windows.
Optional:
- A stricter validator counts as a take-away change. You could add a
Reader:line under## Backwards compatibilitynamingwebsite/src/apps/spec-builder/api.tsapprove. It sends back the hash the server served, which never ends in a newline. This is a body edit, so no push is needed. - Only the approve route has a route-level test for the new 400. A run-task case next to it would cover the second call site in controls.py. The
Proof:line could also list the approve route test. - When spec_builder moves out under #26967, that change should delete the spec_builder imports and entries in test/test_regex_anchor_contract.py.
Port every backend change the built-in took after the snapshot this repository was ported from, so an adopted user runs them: - put a popped worker slot back only onto a free key (kirodotdev/KiroCrew#31829) - keep pasted blocks and the send id on the stored user row, queued or not, with the id checked by the host (kirodotdev/KiroCrew#31799, kirodotdev/KiroCrew#23167) - find a decision answer folded into a merged queue-drain row by every folded id, so it is not dispatched twice (kirodotdev/KiroCrew#33324) - refuse a name, slot key or hash ending in a newline (kirodotdev/KiroCrew#34740) - deliver a restored note hold above the next turn's row on a gateway without the chat slot seam (kirodotdev/KiroCrew#36128) - move the earlier decision record only as a regular file with one name, and settle an empty one when there is none, so a file planted at the old location later is never imported (kirodotdev/KiroCrew#33589) The test dependency moves to Kiro Crew af94fac51f so the new host names resolve where the suite runs; the tests the built-in added with these changes come along.
Port every backend change the built-in took after the snapshot this repository was ported from, so an adopted user runs them: - put a popped worker slot back only onto a free key (kirodotdev/KiroCrew#31829) - keep pasted blocks and the send id on the stored user row, queued or not, with the id checked by the host (kirodotdev/KiroCrew#31799, kirodotdev/KiroCrew#23167) - find a decision answer folded into a merged queue-drain row by every folded id, so it is not dispatched twice (kirodotdev/KiroCrew#33324) - refuse a name, slot key or hash ending in a newline (kirodotdev/KiroCrew#34740) - deliver a restored note hold above the next turn's row on a gateway without the chat slot seam (kirodotdev/KiroCrew#36128) - move the earlier decision record only as a regular file with one name, and settle an empty one when there is none, so a file planted at the old location later is never imported (kirodotdev/KiroCrew#33589) The test dependency moves to Kiro Crew af94fac51f so the new host names resolve where the suite runs; the tests the built-in added with these changes come along. Co-authored-by: KiroCrewCaptain <312312717+KiroCrewCaptain@users.noreply.github.com>
Problem / Motivation
Goal: a Spec Builder spec name, slot key or approval hash that ends in a newline is refused, like every other malformed value.
spec_builder/backend/parsers.pychecks four values with$-anchored patterns used with.match:_NAME_RE(spec name),_SLOT_KEY_RE(chat slot key),_SLOT_SUFFIX_RE(the eight hex digits at the end of a per-creation key) and_SHA256_RE(document hash). Python's$also matches just before a trailing"\n". On main:POST /specs/{name}/approveandPOST /specs/{name}/run-taskwith"hash": "<64 hex>\n"pass the format check and answer 409doc_changedinstead of 400invalid_hash.index.jsonis writable by the agent the app runs. An entry keyed"live\n"is loaded as a usable spec, and an entry whoseslot_keyis"spec-builder-live-0123abcd\n"becomes the spec's slot key. That key is a session file name.test/test_regex_anchor_contract.pyholds a package's request-path validators to\Z, package by package (#12161 began it; #34336, #34465, #34534 and #34592 registered Mochi, pptx-maker, Meetings and Design Tweak). Spec Builder is not registered there yet.Why it matters
The name and the slot key are the gate between a request body or
index.jsonand a directory name and a session file name. A value with a hidden newline passes the gate that is meant to allow only letters, digits,-and_.Not a goal
repository_duplicate.pyalready usesfullmatchfor its digest check, so it is 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/spec_builder/backend/parsers.py:_NAME_RE,_SLOT_KEY_RE,_SLOT_SUFFIX_REand_SHA256_REend at\Z, with the reason in a comment. The other modules of the package import these four, so one edit covers every use.test/test_regex_anchor_contract.py:spec_builder.backendjoins_REQUEST_PATH_PACKAGES, and the four patterns join_VALIDATORSwith a valid input each.src/kiro_crew/apps/builtins/spec_builder/tests/test_trailing_newline.py: new file. It checks the name, the slot key, a stored approval hash, the index loader (a name key and aslot_keythat end in a newline) and the approve route (400, nothing recorded).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 hash with a newline now gets 400 where it got 409.
Tests
valid + "\n", the structural walk lists the four names,_usable_name("live\n")is true,_owns_slot_keyaccepts a key with a newline, the index keeps a"live\n"entry and a slot key with a newline, a stored hash with a newline reads as an approval, approve answers 409 instead of 400).tests/,test/test_core_spec_builder_decoupling.pyandtest/test_regex_anchor_contract.py: 1219 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, and the flake-pattern and wait-discipline ratchets pass locally.python -m pytest src/kiro_crew/apps/builtins/spec_builder/tests/test_trailing_newline.py test/test_regex_anchor_contract.py -n0Manual verification
N/A: the tests call the route handler and the helpers, on real temporary directories.
Sibling sweep
Swept: every module-level compiled pattern under
src/kiro_crew/apps/builtins/spec_builder/backendwith an unescaped$and nore.MULTILINE; the contract's structural walk lists none after this change._TASK_LINE_REusesre.MULTILINEon purpose (per-line anchors overtasks.md) and is exempt.Sibling:
src/kiro_crew/apps/builtins/spec_builder/backend/parsers.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 value is answered the way other malformed values are.
Related Issues
None open for Spec Builder. Same class as #34199, #34238, #34336, #34465, #34534 and #34592; the contract began in #12161.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement