Skip to content

Fix shell-injection in LicenseHeaderStep SET_FROM_GIT mode#2931

Open
nedtwigg wants to merge 1 commit into
mainfrom
fix-license-header-shell-injection
Open

Fix shell-injection in LicenseHeaderStep SET_FROM_GIT mode#2931
nedtwigg wants to merge 1 commit into
mainfrom
fix-license-header-shell-injection

Conversation

@nedtwigg
Copy link
Copy Markdown
Member

@nedtwigg nedtwigg commented May 15, 2026

Summary

  • LicenseHeaderStep.parseYear() was concatenating file.getAbsolutePath() into a shell string and running it via bash -c / cmd /c. A file in a processed repository whose name contained shell metacharacters (e.g. foo`whoami`.java, foo;rm -rf ~.java, Windows foo&calc.exe.java) could execute arbitrary commands as the user running Spotless — a real risk on dev workstations and CI workers that run spotlessApply / spotless:apply against untrusted repos in SET_FROM_GIT year mode.
  • Fix: invoke git directly via ProcessBuilder with an explicit argument list. No shell, no concatenation, no per-OS branch. The -- separator is preserved so paths starting with - aren't interpreted as flags.
  • Side benefit: paths with spaces — which were silently broken under the old bash -c form because the shell would word-split them — now work correctly.

Test plan

  • ./gradlew :lib:compileJava (verified locally)
  • ./gradlew :testlib:test --tests '*LicenseHeader*' passes
  • Manual: run spotlessApply against a repo containing a file with shell metacharacters in its name and confirm no command execution

parseYear() concatenated file.getAbsolutePath() into a string and ran
it through bash -c / cmd /c, so a file in a processed repository whose
name contained shell metacharacters could execute arbitrary commands
under the user running Spotless. Invoke git directly via ProcessBuilder
with an explicit argument list so no shell parses the path.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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