Skip to content

fix(aws-control): refuse a drive key segment or install id that ends in a newline - #34888

Merged
javenciu merged 1 commit into
mainfrom
fix/aws-control-anchor-validators
Nov 11, 2026
Merged

javenciu merged 1 commit into
mainfrom
fix/aws-control-anchor-validators

Conversation

@javenciu

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: an AWS Control drive key or backup install id that ends in a newline is refused, like every other malformed value.

aws_control/backend/storage.py checks each segment of a drive object key with _KEY_SEGMENT_RE, and aws_control/backend/backup_parts/identity.py checks install ids with _INSTALL_ID_RE. Both are $-anchored and used with .match. Python's $ also matches just before a trailing "\n". On main:

  • validate_key("a.txt\n") returns no error. The drive upload, folder, move, delete, download, share, preview and backup restore routes call it on a key from the query string or JSON body, so key=a.txt%0A reaches the write path (on main the upload route answers empty_upload for an empty body instead of invalid_key). A newline in a middle segment (photos\n/a.txt) passes too.
  • A bucket folder named <32 hex>\n reads as an install id. classify_key reports it as another install's archive with an owner id that holds a newline, and other_install_ids adds it to the set of other installs.
  • A stored install identity whose id ends in a newline is accepted as this install's id.

test/test_regex_anchor_contract.py holds a package's request-path validators to \Z, package by package (#12161 began it; #34336, #34465, #34534, #34592 and #34740 registered Mochi, pptx-maker, Meetings, Design Tweak and Spec Builder). AWS Control is not registered there yet.

Why it matters

The key check is the gate between a request and an S3 object name. A key with a hidden trailing newline passes a gate meant to allow only letters, digits, spaces and ._()+@=-, and names a second object that looks the same as the first in the drive.

Not a goal

  • No other package's patterns, and nothing under aws_control/crew/.
  • No change to what a valid key segment or install id is.
  • _BUCKET_NAME_RE and _VERSION_ID_RE are used with fullmatch and are 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/aws_control/backend/storage.py: _KEY_SEGMENT_RE ends at \Z, with the reason in its comment.
  • src/kiro_crew/apps/builtins/aws_control/backend/backup_parts/identity.py: _INSTALL_ID_RE ends at \Z, with the reason in its comment. catalog.py and backup.py import this same object, so one edit covers every use.
  • test/test_regex_anchor_contract.py: aws_control.backend joins _REQUEST_PATH_PACKAGES, and the two patterns join _VALIDATORS with a valid input each.
  • test/test_aws_control_trailing_newline.py: new file. It checks validate_key (last segment and middle segment), the upload route (400 invalid_key, nothing written), classify_key and a stored install id. No test creates a file or folder whose name holds a newline.

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 key ending in a newline now gets 400 invalid_key.

Tests

  • Before: on main 10 checks fail (validate_key accepts four newline keys, the upload route answers empty_upload instead of invalid_key, classify_key returns other with a newline in the owner, a stored id with a newline is an identity, both patterns accept valid + "\n", and the structural walk lists storage._KEY_SEGMENT_RE and identity._INSTALL_ID_RE, plus the catalog alias of the second).
  • After: every test/test_aws_control*.py, aws_control/tests/ and test/test_regex_anchor_contract.py: 2076 passed, three runs in a row at -n0.
  • The whole backend suite, with every app's own 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, the own-mp leak audit, and the flake-pattern and wait-discipline ratchets pass locally.
  • Reproduce: python -m pytest test/test_aws_control_trailing_newline.py test/test_regex_anchor_contract.py -n0
  • Proof: PROVEN test/test_aws_control_trailing_newline.py::TestKeyValidation::test_a_key_with_a_segment_ending_in_a_newline_is_refused[a.txt\n], test/test_aws_control_trailing_newline.py::TestKeyValidation::test_a_key_with_a_segment_ending_in_a_newline_is_refused[photos/a.txt\n], test/test_aws_control_trailing_newline.py::TestKeyValidation::test_a_key_with_a_segment_ending_in_a_newline_is_refused[photos\n/a.txt], test/test_aws_control_trailing_newline.py::TestKeyValidation::test_a_key_with_a_segment_ending_in_a_newline_is_refused[photos 2026/img (1).png\n], test/test_aws_control_trailing_newline.py::TestUploadRoute::test_upload_refuses_a_key_ending_in_a_newline_before_any_write (head f23d94f)

Manual verification

N/A: the tests call the route handler and the helpers.

Sibling sweep

Swept: every module-level compiled pattern under src/kiro_crew/apps/builtins/aws_control/backend with an unescaped $ and no re.MULTILINE; the contract's structural walk lists none after this change. The only other compiled patterns there (_BUCKET_NAME_RE, _VERSION_ID_RE) have no $ and use fullmatch.
Sibling: src/kiro_crew/apps/builtins/aws_control/backend/storage.py -- changed here
Sibling: src/kiro_crew/apps/builtins/aws_control/backend/backup_parts/identity.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 key is answered the way other malformed keys are.

Related Issues

None open for AWS Control. Same class as #34199, #34238, #34336, #34465, #34534, #34592 and #34740; 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

…in a newline

Python's $ also matches just before a trailing newline, so validate_key
accepted "a.txt\n" as a second object key beside "a.txt", and a bucket
folder named "<32 hex>\n" read as an install id when listing other
installs' backups and classifying an archive's owner. Anchor the AWS
Control backend's two request-path patterns at \Z and register the package
in the regex-anchor contract.
@javenciu
javenciu requested review from a team and KiroCrewCaptain as code owners November 10, 2026 23:16
@javenciu
javenciu requested a review from CrysisDeu November 10, 2026 23:17
@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 f23d94fb00506f17eada453384d908cd4df084ec 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

Design Review (Opus 5.5) — ✅ PASS

Design-level review of f23d94fb00506f17eada453384d908cd4df084ec — 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 established $ → \Z fix, registered with the existing anchor contract. The only values it refuses are malformed ones that end in a newline.

[DESIGN-REVIEWED] f23d94f

Description read

[DESCRIPTION-READ] 61f7cac4c93708acfb8024d0c6a632676b9ab19dc27e16318d5edc8c143ec149

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

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of f23d94fb00506f17eada453384d908cd4df084ec — 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 to check.

What this change ships

Inventory (4 items) — 4 justified

Intent: refuse an AWS Control drive key or backup install id that ends in a hidden trailing newline (FIX).

  1. A drive key with a segment ending in a newline is now refused with 400 invalid_key on every drive route — justified
  2. A bucket folder named <32 hex>\n no longer reads as another install's backup owner, and a stored install id ending in a newline is no longer accepted — justified
  3. The regex-anchor contract now covers the AWS Control backend package, so a new $-anchored validator there fails CI — justified
  4. A new test file pins the refusal at the helper, upload route, classify_key and stored-identity layers — justified

[FIRST-PRINCIPLES-REVIEWED] f23d94f

Description read

[DESCRIPTION-READ] 70bae3876d9e2b30db8c0319cba552aa94a5d5a7d5a223605be24296088c15a5

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

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] f23d94f

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

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

@javenciu
javenciu enabled auto-merge (squash) November 10, 2026 23:19
@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] f23d94f

False positive or not applicable? A repository writer can comment:
/ai-review override gpt f23d94fb00506f17eada453384d908cd4df084ec 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 11, 2026

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

Approve on f23d94f. I read the whole diff (163 lines), tests included.

  • Strictness check, same ruling as #34592: main's _KEY_SEGMENT_RE and _INSTALL_ID_RE already mean to allow only their listed charset and length, and to reject anything else. $ let one trailing \n slip past that. Ending at \Z closes only that gap. A valid key segment or install id is unchanged, and the "without the newline are accepted" tests pin that. So it adds no new refusal class.
  • No new regex: both are main's existing patterns, with only the end anchor changed from $ to \Z. catalog.py and backup.py import the same _INSTALL_ID_RE object, so one edit covers them.
  • The tests cover validate_key on a trailing and a mid-segment newline, the upload route answering invalid_key before put_file, classify_key not treating <32 hex>\n as another install, and _stored_identity refusing a newline id. AWS Control is registered in test_regex_anchor_contract.py, so the anchor stays.
  • All 96 checks are green, and nobody else has an open change request. Auto-merge is already set by javenciu.

@javenciu
javenciu merged commit c1d1a5e into main Nov 11, 2026
96 of 97 checks passed
@javenciu
javenciu deleted the fix/aws-control-anchor-validators branch November 11, 2026 01:08
KiroCrewCaptain added a commit to KiroCrewCaptain/kirocrew-app-aws-control that referenced this pull request Nov 13, 2026
* fix: port the wheel copy's newline refusal and crew runtime changes

Carries kirodotdev/KiroCrew#34888 (a drive key segment or install id ending
in a newline is refused), #24732 (the crew bundle excludes the mimocode
credential file), #28535 (the crew container states the empty read-only
path defaults) and #26624 (the hard-link refusal test runs on Windows).

* test: pin the Kiro Crew test dependency at a commit carrying #24732

---------

Co-authored-by: KiroCrewCaptain <312312717+KiroCrewCaptain@users.noreply.github.com>
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