Potential fix for code scanning alert no. 3: Code injection #593
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.
Potential fix for https://github.com/mlcommons/mlperf-automations/security/code-scanning/3
To fix the problem, assign the untrusted input—
${{ github.event.pull_request.head.ref }}
—to an intermediate environment variable, then reference that environment variable in the shell command using native shell syntax ($VAR
) instead of the${{ ... }}
workflow interpolation. This prevents shell injection because environment variables are treated as simple strings by the shell, making it much harder for malicious content in the variable to break out of the intended usage.Specifically:
run:
, replace all workflow interpolations ofgithub.event.pull_request.head.ref
(and similarly for head.repo.html_url if desired for defense in depth) with reference to an environment variable,env:
block for the step, with a new environment variable, e.g.HEAD_REF: ${{ github.event.pull_request.head.ref }}
,run:
script, reference this as$HEAD_REF
.No external libraries or dependencies are required for this change.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.