Repository navigation
fix(scripts): call git without a shell, so CodeQL alert 4 goes with it - #415
Open
IanoNjuguna wants to merge 1 commit into
Open
IanoNjuguna wants to merge 1 commit into
IanoNjuguna wants to merge 1 commit into
Conversation
changelog-dates.js built a git command as a template string and handed it to
execSync, which runs it through a shell. The dates are validated first, so
nothing could actually be injected: isValidDate enforces /^\d{4}-\d{2}-\d{2}$/
and is called on both arguments before getCommits builds the string. The
alert was right about the shape and wrong about the reachability.
Rather than dismiss it, this removes the shape. execFileSync takes the
program and an argument vector and never spawns a shell, so an argument
cannot become syntax even if the validation ever loosens.
Verified:
node scripts/changelog-dates.js --from 2026-11-01 --to 2026-11-22
before and after produce identical output (62 lines, diff empty)
--from '2026-01-01"; touch /tmp/pwned; echo "'
rejected by validation, no file created
Closes the js/indirect-command-line-injection alert on this file once the
analysis re-runs.
Refs IntersectMBO#341
3 tasks
This branch has not been deployed
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
scripts/changelog-dates.jsbuilt a git command as a template string and handed it toexecSync, which runs it through a shell. That is the shape CodeQL reports asjs/indirect-command-line-injection(alert 4 in this repo).Nothing could actually be injected:
isValidDateenforces/^\d{4}-\d{2}-\d{2}$/and is called on both arguments beforegetCommitsbuilds the string, so only digits and dashes ever reached the shell. The alert was right about the shape and wrong about the reachability.Rather than dismiss it, this removes the shape.
execFileSynctakes the program and an argument vector, and never spawns a shell, so an argument cannot become syntax even if the validation loosens later.Refs #341, which is the CodeQL issue and the place the remaining three alerts are being triaged.
Type of Change
Testing
Checklist
Verification
Output is unchanged, which is the whole test for a refactor like this:
And the argument path still rejects malformed input rather than passing it anywhere:
node --check scripts/changelog-dates.jsis clean.Notes
scripts/**is outside the PR build's path filter, and CodeQL re-runs on push tomain, so the alert will not close on this PR. It closes when the analysis runs after merge.js/http-to-file-accessand twojs/file-system-race) are all in build scripts and are being recommended for dismissal with recorded reasons on Extend CodeQL to the actions language and settle the query suite #341, not silenced here.