fix(security): shell-escape repo arg in buildGithubMergeCommand (sibling to #403)#407
Merged
bakeb7j0 merged 1 commit intokahuna/390-bug-drainfrom May 6, 2026
Conversation
Sibling fix to PR #403. The original critical finding noted both repoFlag in enqueuePullRequestViaGraphQL AND the repo arg in buildGithubMergeCommand. PR #403 fixed only the former (via runArgv); this PR closes the buildGithubMergeCommand path with shellEscape() — matching the existing pattern for squashMessage and tempFile two lines above. Adds a regression test that injects 'sec/repo'\''; echo PWNED; #' as the repo arg and verifies the dangerous chars only appear inside single-quoted argv tokens (or inside the '\\'' escape sequence). Updates two existing tests that asserted the unquoted form to use unquote() / .replace(/'/g, '').
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Sibling fix to PR #403. The original code-reviewer finding flagged BOTH
repoFlaginenqueuePullRequestViaGraphQLAND therepoarg inbuildGithubMergeCommandas shell-injection surfaces. PR #403 fixed only the former (viarunArgv); this PR closes thebuildGithubMergeCommandpath withshellEscape()— matching the existing pattern used forsquashMessageandtempFiletwo lines above.Surfaced by re-running the trust-score gate code-reviewer pass after PR #403 merged.
Changes
lib/adapters/pr-merge-github.ts:161— wraprepoinshellEscape()to matchsquashMessage/tempFilepatternlib/adapters/pr-merge-github.test.ts— adds regression test injectingsec/repo'; echo PWNED; #tests/pr_merge.test.ts— updates two assertions that expected unquoted formTests
pr-merge-github.test.ts./scripts/ci/validate.shgreen (76/76 tools)Defence-in-depth note
The schema layer (
repoOptionalSchema) already rejects shell metacharacters at the handler boundary, so this is not exploitable in practice. But every otherparts.push()in this function shell-escapes; the inconsistency was a regression risk for any future code that bypasses the schema (e.g. internal callers, refactors).Closes #390 (gate hotfix sibling)