Skip to content

fix(scripts): call git without a shell, so CodeQL alert 4 goes with it - #415

Open
IanoNjuguna wants to merge 1 commit into
IntersectMBO:mainfrom
IanoNjuguna:fix/changelog-exec-file
Open

IanoNjuguna wants to merge 1 commit into
IntersectMBO:mainfrom
IanoNjuguna:fix/changelog-exec-file

Conversation

@IanoNjuguna

Copy link
Copy Markdown
Contributor

Description

scripts/changelog-dates.js built a git command as a template string and handed it to execSync, which runs it through a shell. That is the shape CodeQL reports as js/indirect-command-line-injection (alert 4 in this repo).

Nothing could actually be injected: isValidDate enforces /^\d{4}-\d{2}-\d{2}$/ and is called on both arguments before getCommits builds 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. execFileSync takes the program and an argument vector, and never spawns a shell, so an argument cannot become syntax even if the validation loosens later.

const output = execFileSync(
  'git',
  ['log', `--since=${since}`, `--until=${until}`, '--pretty=format:%h|%s|%an|%ad', '--date=short'],
  { encoding: 'utf-8' }
);

Refs #341, which is the CodeQL issue and the place the remaining three alerts are being triaged.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Testing

  • I have tested these changes locally
  • I have checked for broken links
  • Code examples have been tested

Checklist

  • My code follows the style guidelines
  • I have performed a self-review
  • I have made corresponding changes to documentation
  • My changes generate no new warnings

Verification

Output is unchanged, which is the whole test for a refactor like this:

node scripts/changelog-dates.js --from 2026-11-01 --to 2026-11-22

before   62 lines, exit 0
after    62 lines, exit 0
diff     empty

And the argument path still rejects malformed input rather than passing it anywhere:

--from '2026-01-01"; touch /tmp/pwned; echo "'
Invalid date format for --from: 2026-01-01"; touch /tmp/pwned; echo "
Expected format: YYYY-MM-DD (e.g., 2025-01-01)
no side effect created

node --check scripts/changelog-dates.js is clean.

Notes

  • scripts/** is outside the PR build's path filter, and CodeQL re-runs on push to main, so the alert will not close on this PR. It closes when the analysis runs after merge.
  • The other three open alerts (js/http-to-file-access and two js/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.

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continuous integration and GitHub Actions Security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant