chore: prevent code injection in visual snapshot step #2058
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/vmware-clarity/ng-clarity/security/code-scanning/22
To fix the vulnerability, the untrusted value (
steps.get-pr-event.outputs.sourceHeadBranch) should not be interpolated directly into the shell command. Instead, it should be passed into an environment variable using the workflow'senv:syntax, and then referenced within the shell as"$SOURCE_HEAD_BRANCH". This ensures correct quoting and prevents code injection, as the shell will not interpret embedded metacharacters in the variable.Specifically:
SOURCE_HEAD_BRANCH) set from${{steps.get-pr-event.outputs.sourceHeadBranch}}before the step that runs the problematic shell command (git commit).run:block (line 74), replace${{steps.get-pr-event.outputs.sourceHeadBranch}}with"$SOURCE_HEAD_BRANCH".${{ }}interpolation inside the shell script for untrusted inputs; use the shell variable.No additional imports or external dependencies are required. The change should be made strictly in the workflow YAML, in the step specifying the
git commit --message.Suggested fixes powered by Copilot Autofix. Review carefully before merging.