Fix CodeQL alerts: workflow permissions and shell command construction - #190
Merged
Conversation
Adds explicit least-privilege GITHUB_TOKEN permissions to the three reusable-workflow callers that had none (alerts #4, #2, #1), matching the job-level style already used in ci.yml and codeql.yml: - cd.yml -> contents: write. shared-config's cd.yml checks out with persisted credentials and runs discourse/publish-rubygems-action (rake release does a raw git push of the version tag) followed by gh release create, both of which need write access to contents. - stale.yml -> issues: write + pull-requests: write. shared-config's stale.yml runs actions/stale, which comments on and closes both stale issues and stale pull requests. - triage.yml -> issues: write. shared-config's triage.yml runs gh issue edit --add-label triage. Fixes the two rb/shell-command-constructed-from-input alerts (#5, #6) in Packs.check, where the caller-supplied file list was interpolated into a single string handed to Kernel#system and therefore to /bin/sh. A path containing a space, quote, semicolon or backtick would have been re-interpreted by the shell. Private.system_with now takes the argv array and splats it into system, so the command is exec'd directly and never goes through a shell. All six callers in lib/packs.rb and the two specs that stub the seam are updated. The sig is params(argv: T::Array[String]); T.unsafe is needed only because Sorbet cannot type-check a splat of statically unknown size. srb tc, rspec (119 examples) and rubocop all pass; actionlint is clean on the workflow files.
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.
Adds explicit least-privilege GITHUB_TOKEN permissions to the three
reusable-workflow callers that had none (alerts #4, #2, #1), matching the
job-level style already used in ci.yml and codeql.yml:
persisted credentials and runs discourse/publish-rubygems-action
(rake release does a raw git push of the version tag) followed by
gh release create, both of which need write access to contents.
stale.yml runs actions/stale, which comments on and closes both stale
issues and stale pull requests.
gh issue edit --add-label triage.
Fixes the two rb/shell-command-constructed-from-input alerts (#5, #6) in
Packs.check, where the caller-supplied file list was interpolated into a
single string handed to Kernel#system and therefore to /bin/sh. A path
containing a space, quote, semicolon or backtick would have been
re-interpreted by the shell.
Private.system_with now takes the argv array and splats it into system,
so the command is exec'd directly and never goes through a shell. All six
callers in lib/packs.rb and the two specs that stub the seam are updated.
The sig is params(argv: T::Array[String]); T.unsafe is needed only because
Sorbet cannot type-check a splat of statically unknown size.
srb tc, rspec (119 examples) and rubocop all pass; actionlint is clean on
the workflow files.
Alerts resolved
rb/shell-command-constructed-from-input(medium) —lib/packs.rb:56rb/shell-command-constructed-from-input(medium) —lib/packs.rb:54actions/missing-workflow-permissions(medium) —.github/workflows/cd.yml:11actions/missing-workflow-permissions(medium) —.github/workflows/stale.yml:8actions/missing-workflow-permissions(medium) —.github/workflows/triage.yml:9Verification
permissions:block (cross-checked by parsing the YAML against the alert list).actionlintoutput is byte-identical tomain— no new findings introduced.codeql.ymluntouched.