Repository navigation
fix(cloud): \Z-anchor validators, register anchor contract (#12128) - #12161
Conversation
|
Intent: Make every request-path validator under |
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify the writer-sweep claim that no legitimate caller feeds a newline-carrying value to these validators — it is the sole breaking-behavior premise. [DESIGN-REVIEWED] 5b17789 |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 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 4.8 Review — ✅ no blocking findingsReviewed Review detailsI've verified the full picture. This PR replaces
No regression: none of these validators (tags, regions, CIDRs, ARNs, digests) legitimately carries a trailing newline, and the No findings. [OPUS-REVIEWED] 5b17789 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Fix guards What this change shipsInventory (9 items) — 9 justifiedIntent: FIX — cloud input validators genuinely refuse trailing-newline values reaching subprocess/IAM/CloudFormation sinks, and the anchor-contract test now covers
[FIRST-PRINCIPLES-REVIEWED] 5b17789 |
8f4325f to
9b2e6c4
Compare
|
9b2e6c4 to
123bc8a
Compare
123bc8a to
289ff8e
Compare
Python's $ anchor matches before one trailing newline, so every $-anchored cloud validator used with .match accepted its own valid input plus "\n" -- including _REPO_RE/_REF_RE, whose values reach a git clone argv in EC2 UserData behind a charset guard. Convert all 20 $ anchors under src/kiro_crew/cloud/ to \Z (18 from the issue enumeration plus _HOSTNAME_RE and _SECRET_NAME_RE, whose multi-line re.compile calls the issue's one-line grep missed), and escape the literal $ inside _CONTROL_OR_SHELL_RE's character class so the contract walk's documented heuristic does not flag it. Register kiro_crew.cloud and kiro_crew.cloud.fargate in the anchor contract test (pkgutil.iter_modules walks direct children only, so the sub-package registers alongside its parent) and add each canonical validator to _VALIDATORS, locking the class against drift-back. Update the two tests pinning _TAG_RE's exact pattern string to the new spelling. Closes #12128
289ff8e to
5b17789
Compare
|
Rebased: main's |
iamwhatever
left a comment
There was a problem hiding this comment.
Reviewed the diff: all 19 \Z conversions present, no $-anchored pattern left under cloud/, contract test covers fargate via walk_packages; tightening only.
…v#12128) (kirodotdev#12161) Python's $ anchor matches before one trailing newline, so every $-anchored cloud validator used with .match accepted its own valid input plus "\n" -- including _REPO_RE/_REF_RE, whose values reach a git clone argv in EC2 UserData behind a charset guard. Convert all 20 $ anchors under src/kiro_crew/cloud/ to \Z (18 from the issue enumeration plus _HOSTNAME_RE and _SECRET_NAME_RE, whose multi-line re.compile calls the issue's one-line grep missed), and escape the literal $ inside _CONTROL_OR_SHELL_RE's character class so the contract walk's documented heuristic does not flag it. Register kiro_crew.cloud and kiro_crew.cloud.fargate in the anchor contract test (pkgutil.iter_modules walks direct children only, so the sub-package registers alongside its parent) and add each canonical validator to _VALIDATORS, locking the class against drift-back. Update the two tests pinning _TAG_RE's exact pattern string to the new spelling. Closes kirodotdev#12128 Co-authored-by: Nick Bowers <nrb@amazon.com>
…v#12128) (kirodotdev#12161) Python's $ anchor matches before one trailing newline, so every $-anchored cloud validator used with .match accepted its own valid input plus "\n" -- including _REPO_RE/_REF_RE, whose values reach a git clone argv in EC2 UserData behind a charset guard. Convert all 20 $ anchors under src/kiro_crew/cloud/ to \Z (18 from the issue enumeration plus _HOSTNAME_RE and _SECRET_NAME_RE, whose multi-line re.compile calls the issue's one-line grep missed), and escape the literal $ inside _CONTROL_OR_SHELL_RE's character class so the contract walk's documented heuristic does not flag it. Register kiro_crew.cloud and kiro_crew.cloud.fargate in the anchor contract test (pkgutil.iter_modules walks direct children only, so the sub-package registers alongside its parent) and add each canonical validator to _VALIDATORS, locking the class against drift-back. Update the two tests pinning _TAG_RE's exact pattern string to the new spelling. Closes kirodotdev#12128 Co-authored-by: Nick Bowers <nrb@amazon.com>
Problem / Motivation
Every regex validator under
src/kiro_crew/cloud/was anchored with$. InPython,
$matches just before one trailing newline, so each of thesevalidators used with
.matchaccepts its own valid input with"\n"appended. A cloud tag of
my-crew\n, a CIDR of10.0.0.0/16\n, or a git refof
main\nall pass validation that was written to refuse them. The sharpestcase:
_REPO_REand_REF_REguard values that reach agit clone --branch '<ref>' '<repo>'line in EC2 instance UserData, where thecomment above them promises charset validation keeps crafted values inside
their quotes.
Why it matters
These are request-path validators on security-sensitive sinks (subprocess
argv, IAM role names, CloudFormation parameters). The bound is small — exactly
one trailing newline, no arbitrary suffix — but the repo has an established
\Zconvention for this class and a contract test built to stop it driftingback, and
cloud/was not registered with that guard. This PR's scope issrc/kiro_crew/cloud/only, per #12128: other packages still carry$-anchored patterns and are separate work — the contract test's_REQUEST_PATH_PACKAGESregistry is the extension point for converting andguarding them package by package.
What changed (motivation → approach → change)
Cloud's input validators now genuinely refuse a value with a trailing newline,
and the contract test that guards this defect class now covers
cloud/so thebug cannot drift back — the fix is the mechanical anchor conversion plus that
registration.
test/test_regex_anchor_contract.pyalready guards the class two ways —behaviorally (every registered validator must reject valid-input+
"\n") andstructurally (a package walk flags any module-level pattern carrying an
unescaped
$) — but its package registry only listed the Papyrus backend,which is why
cloud/escaped it.All 19 remaining
$anchors undersrc/kiro_crew/cloud/become\Z: theissue enumerated 18, plus
_HOSTNAME_RE(login_target.py) and_SECRET_NAME_RE(fargate/identity.py), whose multi-linere.compilecallsa one-line grep misses; the 20th,
_USERNAME_REinssm.py, landed on mainvia #12106 with the same
\Zspelling, so this diff no longer touches thatfile. The literal
$inside_CONTROL_OR_SHELL_RE'scharacter class is spelled
\$(a semantic no-op inside[...]) so thestructural walk's documented heuristic does not flag it, with comments on both
sides recording why that escape is load-bearing.
kiro_crew.cloudis registered in_REQUEST_PATH_PACKAGES, and the contracttest's package walk is now recursive (
pkgutil.walk_packages), socloud/fargate/and any sub-package added under a registered root later arecovered without editing the test. Each canonical validator gains a
_VALIDATORSentry — includingec2._PROFILE_SPEC.pattern, which is aliasedfrom
deploy/profiles.pyand would otherwise stay outside both halves of theguard. The test's docstring distinguishes patterns matched raw (directly
tightened) from those routed through
validation.validate_field, whoseboundary strips before matching, making
\Zdefense-in-depth there. All cloudmodules were verified import-safe for the walk (no client construction,
credentials, network, or filesystem effects at import).
Backwards compatibility
Breaking: values carrying exactly one trailing newline are now refused by these
cloud validators (19 in this diff, plus ssm.py's
_USERNAME_REvia #12106) —that refusal is the fix. Writer sweep on
origin/main@653f44b7a: no caller can legitimately supply one.CloudConfig.loadreads JSON (json.loadsstrips nothing into values;a stored tag was validated before save), wizard/CLI inputs are stripped or
argv-shaped,
normalize_start_urllowercases and strips before matching, andno
.read()call feeds any of these patterns. The CloudFormationAllowedPatternmirrors are full-string matches and unaffected.Tests
test_regex_anchor_contract.py: 21 new behavioral entries, each locking inthat the validator accepts its canonical input and rejects it with
"\n"appended; the structural walk now covers every module under
cloud/andcloud/fargate/, so a future$-anchored cloud validator fails withoutediting the test; the walk-guard pins
ec2andfargate.identityasreached. Reverting the production hunks makes 21 tests fail (verified).
test_cloud_ec2.py/test_cloud_config.py: the two assertions pinning_TAG_RE's exact pattern string updated to the\Zspelling; theirpurpose (the
{1,51}IAM cap lockstep) is unchanged.Manual verification
N/A — unit coverage sufficient: the change is regex-anchor spelling with the
accept/reject behavior locked by the contract test; full backend suite, isort,
flake8, mypy, and the black/encoding gates all pass locally.
Related Issues
Fixes #12128
Pattern harvest
Rule candidate: agents-md
Pattern: "$-anchored validator on a request path — anchor with \Z and register
the package in test_regex_anchor_contract.py; the contract test's registry, not
per-validator tests, is what stops the class drifting back"
Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)