Repository navigation
fix(mochi): refuse a pack id, slot, petdex slug or language tag that ends in a newline - #34336
Conversation
…ends in a newline
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. All three patterns go through one existing mechanism, the Inventory (5 items) — 5 justifiedIntent: stop Mochi from accepting a pack id, slot, slug or language tag that ends in a newline. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] ff3819b Description read[DESCRIPTION-READ] 73eac0f8722912aaa96fa8293643de4e33cf866339e29265330e26f259d8da04 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. This is the repo's usual [DESIGN-REVIEWED] ff3819b Description read[DESCRIPTION-READ] 2dce2535b18e3b5099b25091b16d70ccda16c85fc9459c72a76a1c9339462cc5 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: |
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: |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (6 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: three Mochi validation regexes now end at \Z instead of $, so a value with a trailing newline is refused, with tests and the package added to the regex anchor contract.
Problem / Motivation
Goal: a Mochi pack id, slot name, petdex slug or language tag that ends in a newline is refused, like every other malformed value.
Mochi validates these client-supplied values with
$-anchored patterns and.match. Python's$also matches just before a trailing"\n", so each pattern accepts its own valid value plus one newline:appearance_store._SAFE_IDchecks a sprite pack'soverwriteIdand every slot name. The id becomes a directory name and the slot becomes<slot>.png, so on mainsave_sprite_pack(data_dir, {"assignments": {"idle": png, "happy\n": png}, "overwriteId": "abc\n"})succeeds. It creates a directory namedabc\nwith a file namedhappy\n.png, and returns"abc\n", whichget_pack_detail(data_dir, "abc")does not find. Windows refuses such names with anOSError.settings._LANGUAGE_TAG_REchecks thelanguagesetting.save_settings(data_dir, {"language": "en\n"})stores and returns"en\n", and a stored"en\n"is kept on load instead of falling back to"", thoughtest_malformed_tag_is_rejectedsays a malformed tag is a client bug and is refused.petdex_import._SLUG_REchecks the slug that addresses a path segment on the petdex host. It has the same shape.test/test_regex_anchor_contract.pyholds a package's request-path validators to\Z, package by package (#12161 began it; #34199 and #34238 fixed the same shape elsewhere). Mochi is not registered there yet.Why it matters
A newline in a directory or file name is a value the validator's own comment says it keeps out ("safe to use as a single path segment"), and a pack saved that way cannot be found again by its id. A stored language tag with a newline is an unresolvable code handed to the dashboard's i18n setup.
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/mochi/appearance_store.py:_SAFE_IDends at\Z, with a comment saying why.src/kiro_crew/apps/builtins/mochi/settings.py:_LANGUAGE_TAG_REends at\Z.src/kiro_crew/apps/builtins/mochi/petdex_import.py:_SLUG_REends at\Z.test/test_regex_anchor_contract.py: themochipackage joins_REQUEST_PATH_PACKAGES, so the structural walk refuses a$-anchored module-level pattern anywhere in it, and the three patterns join_VALIDATORSwith a valid input each.test/test_mochi_appearance_store.py:abc\njoins the unsafe pack ids, andtest_a_trailing_newline_never_reaches_a_directory_or_file_namesaves a pack with a newline in the overwrite id, then in a slot name, and checks the save is refused and no name on disk holds a newline.test/test_mochi_settings.py:en\njoins the malformed tags, andtest_a_stored_tag_with_a_trailing_newline_falls_backloads a stored"en\n"as"".Backwards compatibility
Compatible for every valid value: the three patterns accept exactly what they did, minus the value with one trailing newline. A pack directory already saved with a newline in its name is not reachable by any valid id before or after this change.
Tests
DID NOT RAISE PackErrorfor the id and both save cases,DID NOT RAISE ValueErrorforen\n,assert 'en\n' == ''for the stored tag, and the contract's three accept-and-reject cases plus its structural walk over the package.test_mochi_appearance_store.py,test_mochi_settings.py,test_mochi_routes.pyandtest_regex_anchor_contract.py: 282 passed, three runs in a row at-n0.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_mochi_appearance_store.py test/test_mochi_settings.py test/test_regex_anchor_contract.py -n0Manual verification
N/A: the tests call the store and settings functions the routes call, on a real temporary data directory.
Sibling sweep
Swept: every module-level compiled pattern under
src/kiro_crew/apps/builtins/mochiwith an unescaped$and nore.MULTILINE(an AST walk over the package, the same rule the contract's structural half applies).Sibling:
src/kiro_crew/apps/builtins/mochi/appearance_store.py-- changed hereSibling:
src/kiro_crew/apps/builtins/mochi/settings.py-- changed hereSibling:
src/kiro_crew/apps/builtins/mochi/petdex_import.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 Mochi. Same class as #34199 and #34238; the contract began in #12161.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement