Skip to content

fix: tighten a git publish check - #30774

Merged
bolichen97 merged 1 commit into
mainfrom
fix/18520-tighten-publish-check
Nov 6, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/18520-tighten-publish-check

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A git push whose destination cannot be determined before it runs is refused in the case the linked issue reports.

The publish check could accept a push in one spelling as a feature-branch push while the shell would run it against a different branch.

Why it matters

The publish check is what keeps an agent from pushing straight to a protected branch. A misreading lets that push through.

Not a goal

  • Other spellings, or other commands. This closes only the case in the linked issue.
  • Changing the refusal text.

What changed (motivation → approach → change)

The check read one part of a push command as fixed text, while the shell can turn that part into different words when the command runs. That part now gets the treatment the check already gives such text elsewhere in a push: the push is refused as unverifiable, with no opt-out. Quoting the value keeps the command allowed. On Windows, whose shell does not split that text into words, the check reads the command as it did before. The src/kiro_crew/security change comes with a matching paragraph in the security spec under docs and one regression test under test.

Backwards compatibility

Breaking: on Linux and macOS, a push written in the spelling the linked issue reports is refused where main allowed it; quoting the value is the working form. Windows is unchanged. Writer sweep on origin/main @ 8a123e1: no shipped skill, script, doc or workflow writes that spelling.

Tests

Three regression tests: the reported spelling is refused as unverifiable; the quoted forms of the same value are still allowed, and an ordinary non-push command still runs; on Windows the same spelling of a feature-branch push stays allowed.

Determinism: 20/20 runs at -n0, 10/10 at -n 4 --dist loadgroup --max-worker-restart=2 beside a sibling test file, and the whole test file green in a shuffled order (seed 16048).

Proof: PROVEN test/test_push_branch_gate.py::TestGitPushEnforcement::test_an_unquoted_expansion_before_the_subcommand_is_unverifiable, test/test_push_branch_gate.py::TestGitPushEnforcement::test_a_dollar_quote_before_the_subcommand_is_one_word (head a2086ad)

Manual verification

N/A — unit coverage sufficient: the check is a pure function of the command text, and the test drives it through the real enforcement point.

Screenshots / video

N/A — no user-visible frontend surface.

Related Issues

Closes #18520

Sibling sweep

Siblings: none -- this changes the one place that reads a push's target; other spellings are outside this PR (see Not a goal)

Pattern harvest

Not generalizable: one reading gap in one command check, closed by reusing the posture that check already applies elsewhere.

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

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 5, 2026 21:13
@bolichen97
bolichen97 enabled auto-merge (squash) November 5, 2026 21:13
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security/argv_floor_git.py

  • @buluoray approved a2086ad with a complete reasoning template.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision a2086ad01fbdb6359aa7653c6446ce66743e648a touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of a2086ad01fbdb6359aa7653c6446ce66743e648a — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the change gives a shell command line the $ posture the check already uses for refspecs. The Breaking line lists the new refusal, and no shipped writer uses that spelling.

Notes

  • An unquoted $ before push is now refused with no opt-out. Agents commonly write git -C $WORKTREE push …, so this will produce false refusals. Make sure the refusal text tells the agent that quoting the variable is the working form.

[DESIGN-REVIEWED] a2086ad

Description read

[DESCRIPTION-READ] c32d407c8b198978ddbffd55cbe6b61ba575a1723b7e8d9840f2e44b91ab186a

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

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of a2086ad01fbdb6359aa7653c6446ce66743e648a — 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 (5 items) — 5 justified

Intent: stop an agent pushing to a protected branch through git -C $d push …, where $d splits into more words when the shell runs it. This is a FIX (#18520).

  1. On Linux/macOS, a push with an unquoted $ word between git and push is now refused as unverifiable — justified
  2. The quoted "$d" form and the $'…' / $"…" forms of that word are still allowed — justified
  3. Windows (PowerShell) still reads such a push the way it did before — justified
  4. The security spec has a new paragraph on this posture — justified
  5. Three regression tests pin the refusal, the allowed quoted forms and the Windows reading — justified

[FIRST-PRINCIPLES-REVIEWED] a2086ad

Description read

[DESCRIPTION-READ] 36d4d9a1413e085dcc47e217df084c291231a578dc5e2249fe6dab395895d35f

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

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] a2086ad

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

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

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] a2086ad

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

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

Which legitimate operations does a2086ad01fbdb6359aa7653c6446ce66743e648a newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: adjudicated, zero confirmed regressions.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 13 classified, 0 newly refused, 13 still allowed.
  • ubuntu-latest (platform posix): 13 classified, 0 newly refused, 13 still allowed.
  • windows-latest (platform windows): 6 classified, 0 newly refused, 6 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

Reason: The new check refuses only a push whose words before the push subcommand contain an active, unquoted $ expansion, and only on non-Windows hosts. I wrote 19 boundary candidates: quoted expansions, $'...', tilde paths, env-prefix assignments, wrapped payloads, non-push subcommands, and PowerShell/cmd spellings. None of them is in the refused shape, and the harness passed back no confirmed regressions. One overlap is named under UNADJUDICATED and does not block: an ordinary unquoted git -C $WORKTREE push origin feat/x on posix is now refused. It is the threat's own shape, so it is not encoded as a row.

TIGHTENING: the git-publish argv floor (_git_push_args in src/kiro_crew/security/argv_floor_git.py) now puts any skipped pre-subcommand word that carries an active $ at the front of the returned args. The caller's "$" in tok check then tags it _GIT_PUBLISH_UNGATED, which is reported as rule=git-publish-target-unverifiable. The threat is a word-splitting variable that smuggles a protected refspec in front of the subcommand: "with d='x push origin main', git -C $d push origin feature can push main. It is returned first, where the caller's $ check ungates it." The hunk is args: list[str] = [word for word in raw_tokens[start + 1 : i] if not platform_compat.IS_WINDOWS and any(step.active and step.char == "$" and word[step.offset + 1 : step.offset + 2] not in ("'", '"') ...)].

ADJUDICATED: 19 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: The diff makes two platform assumptions: posix shells word-split an unquoted $VAR, and on Windows the shell is PowerShell, which does not. There are 13 posix rows. They probe the edge of the active-$ test from the allowed side:

  • a double-quoted -C, --git-dir and --work-tree value
  • a $ inside a quoted -c value
  • an ANSI-C $'...' path
  • a pre-subcommand tilde path and a literal absolute path
  • an unquoted variable in a separate cd segment
  • an env-prefix assignment before the git anchor
  • a bash -c wrapped push
  • unquoted -C $WORKTREE before the non-push subcommands status, fetch and log

There are 6 windows rows. They probe the IS_WINDOWS exemption through PowerShell $env:WORKTREE, $PWD, $HOME\ with backslashes, and git.exe --git-dir=$env:GIT_DIR, plus a drive-letter path and cmd-style %WORKTREE%, neither of which has a $. No any rows were written, because every row names an executable and a path. One assumed spelling has no row: a Windows host whose agent shell is Git Bash or WSL bash rather than PowerShell. A command line cannot tell the classifier which shell is running, so a row could not express this.

UNADJUDICATED: There is a narrowing overlap that I argued but could not confirm with a row. Under the new hunk, a posix push with an unquoted variable before the subcommand is now refused under the non-waivable git-publish-target-unverifiable key. Examples are git -C $WORKTREE push -u origin feat/example and git --git-dir=$GIT_DIR push origin feat/example. Workers and scripts that export a worktree path and leave it unquoted will lose these pushes. That shape is exactly the threat, since the gate cannot see the variable's value, so I did not write it as a candidate. Encoding it would be a row that admits the attack. The workaround that stays allowed is quoting ("$WORKTREE"), and the quoted forms are among the candidates. A search of the repo's src, scripts, .github and docs found no unquoted git -C $…, --git-dir=$…, --work-tree=$… or -c …$… before a push.

[SCOPE-REVIEWED] a2086ad

@bolichen97
bolichen97 force-pushed the fix/18520-tighten-publish-check branch from 6ddac49 to ff5a2ac Compare November 6, 2026 00:02
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97]
self-added: yes

  • fixed span=678009f64995

fixed in ff5a2ac: the quoted form this finding names is allowed again, as it is on main, and a regression test pins it.
An unquoted expansion in the same place, including one glued after such a quote, is still refused.

@bolichen97
bolichen97 force-pushed the fix/18520-tighten-publish-check branch from ff5a2ac to 00a68e5 Compare November 6, 2026 03:14
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 6, 2026
Refuse one more git push spelling whose destination cannot be
determined before it runs, the case reported in the linked issue.
Quoting the value keeps the command allowed.

Closes #18520
@bolichen97
bolichen97 force-pushed the fix/18520-tighten-publish-check branch from 00a68e5 to a2086ad Compare November 6, 2026 06:06
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 6, 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.

Approved by Crew Captain for the on-call, who accepted the open items on this PR. Review lanes clean on this head.

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

🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:

APPROVE. This tightens the push check and loosens nothing.

What it does for users: an agent can no longer get a push to a protected branch past the publish check by putting an unquoted variable in a git option before the subcommand. With d='x push origin main', the command git -C $d push origin feature word-splits at run time into a push of main, and main read it as a feature-branch push. That spelling is now refused as unverifiable. The quoted form "$d", a $'...' or $"..." value, and ordinary non-push commands such as git -C $d status still run. Windows (PowerShell, which does not word-split a variable) is unchanged.

Evidence:

  • src/kiro_crew/security/argv_floor_git.py:425-436: the only change seeds the returned argument list with skipped words before the subcommand that hold an active (unquoted, unescaped) $ not followed by a quote. Nothing is removed from the existing scan; on Windows the list is empty, which is exactly main's behaviour.
  • The caller then ungates any returned word holding a $ (argv_floor_git.py:806-814), and deny_gate.py:695-711 refuses an ungated segment with no opt-out. Adding words to the front can only move a segment toward that ungated refusal; I found no path where an extra leading word turns a refusal into an allow.
  • The $'...' exemption matches the shared quote state machine (shell_normalizer_walk.py:501), so a literal ANSI-C path stays one word, while $'/x/'$d is still caught on its second $.
  • test/test_push_branch_gate.py: 104 passed on this head, run locally.
  • Mutations, one at a time, source restored and the tree clean after each:
    1. Pre-fix line (empty list instead of the seeded one): test_an_unquoted_expansion_before_the_subcommand_is_unverifiable and test_a_dollar_quote_before_the_subcommand_is_one_word go red.
    2. Dropping the $' / $" exemption: test_a_dollar_quote_before_the_subcommand_is_one_word goes red.
    3. Dropping the Windows exemption: test_powershell_keeps_a_variable_before_the_subcommand_one_word goes red.
  • Backwards compatibility: the PR body carries a Breaking: line with a writer sweep, which is the form docs/system-specs/common/take-away-changes.md asks for when the take-away is the purpose of the change. My own sweep of origin/main (outside test) found no skill, script, doc or workflow that puts an unquoted variable in -C, --git-dir or --work-tree ahead of a push.
  • Spec: the security.md paragraph matches the code, including the PowerShell carve-out.
  • CI: every check green except Sensitive Change Review (waiting for the template below) and the readiness signal that follows it. Design, First Principles, Security Scope, GPT 6.1 and Opus 5.5 lanes pass. Merge-tree against main is clean.

Source-only: I did not run the change against a real bash or PowerShell; the word-splitting and the PowerShell behaviour are read from the shell semantics and the tests, which monkeypatch the platform flag.

Follow-ups (non-blocking): none required for this scope.

Sensitive change review

  • Head commit: a2086ad
  • What rule changed: the git publish floor's push-argument reader now returns a word before the push subcommand that carries an unquoted $ expansion, so the existing $ check marks the push unverifiable.
  • Before -> after (what was allowed/blocked, now): before, git -C $d push origin feature (and git --git-dir=$d push origin feature) was allowed as a feature-branch push on Linux and macOS; now it is refused as git-publish-target-unverifiable. The quoted "$d", $'...' and $"..." forms, non-push commands, and every Windows spelling are unchanged.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a push that puts an unquoted variable in a git option before the subcommand is refused on Linux or macOS; quoting the variable is the working form. No secret exposure and no lock-out.
  • Evidence checked (which sandbox result proves it): the three new tests in test/test_push_branch_gate.py drive the real enforcement point; each guard part was mutated on its own and a named test went red (pre-fix line, the $' exemption, the Windows exemption).
  • No regression:
    • Tools still work (which tools/commands were run, result): the quoted form and git -C $d status are asserted allowed in the new tests; the full push-gate file passes, 104 tests.
    • Backward compatible (old config / old data / old callers still work, how checked): writer sweep of main found no shipped skill, script, doc or workflow writing the refused spelling; Windows reading unchanged by construction (empty list when IS_WINDOWS).
    • Existing tests (which suites passed on this head): test/test_push_branch_gate.py locally; all backend, Windows, sandbox and denial-differential CI jobs green on this head.
  • How to undo: revert the commit; the reader returns to its previous empty leading list.

@bolichen97
bolichen97 merged commit 4b5126a into main Nov 6, 2026
102 of 109 checks passed
@bolichen97
bolichen97 deleted the fix/18520-tighten-publish-check branch November 6, 2026 17:45
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 6, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor

@bolichen97 heads-up: after this merged, main's test_security_gate_liveness.py::test_the_package_stays_within_its_line_budget fails ('package grew to 34753 lines', budget 34733). This PR added a net 20 lines under src/kiro_crew/security/. #31625 (@buluoray) raises the budget by exactly those 20 lines, test-only, and I posted a VERDICT: APPROVE there. A maintainer approval on #31625 turns every PR's Backend shard 2 green again.

buluoray added a commit that referenced this pull request Nov 6, 2026
#31625)

#30774 added 20 lines to argv_floor_git without raising the package budget, so main is 34,753 lines against 34,733 and test_the_package_stays_within_its_line_budget fails on every PR. Raise the budget by those 20. No code change.
buluoray pushed a commit that referenced this pull request Nov 8, 2026
Refuse one more git push spelling whose destination cannot be
determined before it runs, the case reported in the linked issue.
Quoting the value keeps the command allowed.

Closes #18520

(cherry picked from commit 4b5126a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git-publish floor: -C value from an unquoted expansion is parsed as one fixed word

4 participants