Skip to content

Commit 498d3f3

Browse files
authored
Merge pull request from GHSA-ghm2-rq8q-wrhc
* feat: add `safe_output` input enabled by default * fix: migrate README to safe uses of interpolation * fix: also sanitize `)` * fix: remove sanitization of `'` * fix: also sanitize `|` * fix: also sanitize `&` * fix: also sanitize `;`
1 parent 08975f0 commit 498d3f3

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Verify that certain files or directories did or did not change during the workfl
6060
uses: tj-actions/verify-changed-files@v16
6161
id: verify-changed-files
6262
with:
63+
safe_output: false # true by default, set to false because we are using an environment variable to store the output and avoid command injection.
6364
files: |
6465
*.txt
6566
test_directory
@@ -69,8 +70,11 @@ Verify that certain files or directories did or did not change during the workfl
6970
7071
- name: Run step only when any of the above files change.
7172
if: steps.verify-changed-files.outputs.files_changed == 'true'
73+
env:
74+
FILES_CHANGED: |-
75+
${{ steps.verify-changed-files.outputs.changed_files }}
7276
run: |
73-
echo "Changed files: ${{ steps.verify-changed-files.outputs.changed_files }}"
77+
echo "Changed files: $FILES_CHANGED"
7478
# Outputs: "Changed files: new.txt test_directory/new.txt"
7579
```
7680

@@ -82,6 +86,7 @@ Verify that certain files or directories did or did not change during the workfl
8286
uses: tj-actions/verify-changed-files@v16
8387
id: verify-changed-files
8488
with:
89+
safe_output: false
8590
files: |
8691
new.txt
8792
test_directory
@@ -99,10 +104,15 @@ Verify that certain files or directories did or did not change during the workfl
99104
- name: Verify Changed files
100105
uses: tj-actions/verify-changed-files@v16
101106
id: verify-changed-files
107+
with:
108+
safe_output: false
102109

103110
- name: List all changed files tracked and untracked files
111+
env:
112+
FILES_CHANGED: |-
113+
${{ steps.verify-changed-files.outputs.changed_files }}
104114
run: |
105-
echo "Changed files: ${{ steps.verify-changed-files.outputs.changed_files }}"
115+
echo "Changed files: $FILES_CHANGED"
106116
```
107117
108118
If you feel generous and want to show some extra appreciation:

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ inputs:
2525
description: 'Message to display when files have changed and the `fail-if-changed` input is set to `true`.'
2626
default: "Files have changed."
2727
required: false
28+
safe_output:
29+
description: "Apply sanitization to output filenames before being set as output."
30+
required: false
31+
default: "true"
2832

2933
outputs:
3034
files_changed:
@@ -61,6 +65,7 @@ runs:
6165
INPUT_MATCH_GITIGNORE_FILES: ${{ inputs.match-gitignore-files }}
6266
INPUT_FAIL_IF_CHANGED: ${{ inputs.fail-if-changed }}
6367
INPUT_FAIL_MSG: ${{ inputs.fail-message }}
68+
INPUT_SAFE_OUTPUT: ${{ inputs.safe_output }}
6469
6570
branding:
6671
icon: file-text

entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ if [[ -n "$CHANGED_FILES" ]]; then
6666

6767
CHANGED_FILES=$(echo "$CHANGED_FILES" | awk '{gsub(/\|/,"\n"); print $0;}' | awk -v d="$INPUT_SEPARATOR" '{s=(NR==1?s:s d)$0}END{print s}')
6868

69+
if [[ "$INPUT_SAFE_OUTPUT" == "true" ]]; then
70+
CHANGED_FILES=${CHANGED_FILES//$/\\$} # Replace $ with \$
71+
CHANGED_FILES=${CHANGED_FILES//\(/\\\(}} # Replace ( with \(
72+
CHANGED_FILES=${CHANGED_FILES//\)/\\\)}} # Replace ) with \)
73+
CHANGED_FILES=${CHANGED_FILES//\`/\\\`} # Replace ` with \`
74+
CHANGED_FILES=${CHANGED_FILES//|/\\|} # Replace | with \|
75+
CHANGED_FILES=${CHANGED_FILES//&/\\&} # Replace & with \&
76+
CHANGED_FILES=${CHANGED_FILES//;/\\;} # Replace ; with \;
77+
fi
78+
6979
echo "files_changed=true" >> "$GITHUB_OUTPUT"
7080
echo "changed_files=$CHANGED_FILES" >> "$GITHUB_OUTPUT"
7181

0 commit comments

Comments
 (0)