Skip to content

fix(mochi): refuse a pack id, slot, petdex slug or language tag that ends in a newline - #34336

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

javenciu merged 1 commit into
mainfrom
fix/mochi-anchor-validators

Conversation

@javenciu

Copy link
Copy Markdown
Contributor

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_ID checks a sprite pack's overwriteId and every slot name. The id becomes a directory name and the slot becomes <slot>.png, so on main save_sprite_pack(data_dir, {"assignments": {"idle": png, "happy\n": png}, "overwriteId": "abc\n"}) succeeds. It creates a directory named abc\n with a file named happy\n.png, and returns "abc\n", which get_pack_detail(data_dir, "abc") does not find. Windows refuses such names with an OSError.
  • settings._LANGUAGE_TAG_RE checks the language setting. 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 "", though test_malformed_tag_is_rejected says a malformed tag is a client bug and is refused.
  • petdex_import._SLUG_RE checks the slug that addresses a path segment on the petdex host. It has the same shape.

test/test_regex_anchor_contract.py holds 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

  • No other package's patterns; each package is its own registration.
  • No change to what a valid id, slug or tag 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/mochi/appearance_store.py: _SAFE_ID ends at \Z, with a comment saying why.
  • src/kiro_crew/apps/builtins/mochi/settings.py: _LANGUAGE_TAG_RE ends at \Z.
  • src/kiro_crew/apps/builtins/mochi/petdex_import.py: _SLUG_RE ends at \Z.
  • test/test_regex_anchor_contract.py: the mochi package joins _REQUEST_PATH_PACKAGES, so the structural walk refuses a $-anchored module-level pattern anywhere in it, and the three patterns join _VALIDATORS with a valid input each.
  • test/test_mochi_appearance_store.py: abc\n joins the unsafe pack ids, and test_a_trailing_newline_never_reaches_a_directory_or_file_name saves 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\n joins the malformed tags, and test_a_stored_tag_with_a_trailing_newline_falls_back loads 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

  • Before: on main the new cases fail: DID NOT RAISE PackError for the id and both save cases, DID NOT RAISE ValueError for en\n, assert 'en\n' == '' for the stored tag, and the contract's three accept-and-reject cases plus its structural walk over the package.
  • After: test_mochi_appearance_store.py, test_mochi_settings.py, test_mochi_routes.py and test_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.
  • Reproduce: python -m pytest test/test_mochi_appearance_store.py test/test_mochi_settings.py test/test_regex_anchor_contract.py -n0
  • Proof: PROVEN test/test_mochi_appearance_store.py::TestPathConfinement::test_unsafe_pack_ids_are_rejected[abc\n], test/test_mochi_appearance_store.py::TestPathConfinement::test_a_trailing_newline_never_reaches_a_directory_or_file_name[overwriteId], test/test_mochi_appearance_store.py::TestPathConfinement::test_a_trailing_newline_never_reaches_a_directory_or_file_name[slot], test/test_mochi_settings.py::TestLanguage::test_malformed_tag_is_rejected, test/test_mochi_settings.py::TestLanguage::test_a_stored_tag_with_a_trailing_newline_falls_back (head ff3819b)

Manual 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/mochi with an unescaped $ and no re.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 here
Sibling: src/kiro_crew/apps/builtins/mochi/settings.py -- changed here
Sibling: src/kiro_crew/apps/builtins/mochi/petdex_import.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 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

  • 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

@javenciu
javenciu requested review from a team and KiroCrewCaptain as code owners November 10, 2026 05:16
@javenciu
javenciu enabled auto-merge (squash) November 10, 2026 05:16
@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 ff3819b89c8882448f5402bf7ffca05e6468bd16 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 ff3819b89c8882448f5402bf7ffca05e6468bd16 — 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

Nothing blocks. All three patterns go through one existing mechanism, the \Z anchor plus the package registration in test/test_regex_anchor_contract.py. Grep finds no $-anchored pattern left in mochi.

Inventory (5 items) — 5 justified

Intent: stop Mochi from accepting a pack id, slot, slug or language tag that ends in a newline. This is a FIX.

  1. A sprite-pack overwrite id ending in a newline is refused, so no directory named abc\n gets created — justified
  2. A slot name ending in a newline is refused, so no happy\n.png gets written — justified
  3. A language tag ending in a newline is refused on save, and a stored one falls back to "" on load — justified
  4. A petdex slug ending in a newline is refused before it reaches the host path — justified
  5. The anchor contract now covers the whole mochi package, so a future $ pattern there fails CI — justified

[FIRST-PRINCIPLES-REVIEWED] ff3819b

Description read

[DESCRIPTION-READ] 73eac0f8722912aaa96fa8293643de4e33cf866339e29265330e26f259d8da04

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 ff3819b89c8882448f5402bf7ffca05e6468bd16 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks. This is the repo's usual \Z fix, applied in place to a built-in app that apps/adoption-pins.json doesn't list, and the only values it now refuses already failed lookup by id.

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

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] ff3819b

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

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] ff3819b

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable ff3819b89c8882448f5402bf7ffca05e6468bd16 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 (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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants