Skip to content

Commit d2f332a

Browse files
Fix for code scanning alert no. 1035: Environment variable built from user-controlled sources
The concern is that the file in the artifact might be created by an attacker to inject values into the env var being set. To address this vulnerability, we should strictly control the value of PR_NUMBER before it is written to $GITHUB_ENV. This means ensuring that: - Only valid, single-line numeric data is used (since PR numbers are always positive integers). - All potential for newlines, extra characters, or injection attacks is removed. - explicitly validate that the value is non-empty and matches expectations = Also, wrap the assignment in double quotes to further protect against expansion. Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 9573558 commit d2f332a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

.github/workflows/publish-test-results.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ jobs:
3535
3636
- name: Extract PR Number
3737
run: |
38-
eventjson=`cat 'artifacts/Event File/event.json'`
39-
prnumber=`echo $(jq -r '.pull_request.number' <<< "$eventjson")`
40-
echo "PR_NUMBER=$(echo $prnumber | tr -cd '0-9')" >> $GITHUB_ENV
41-
38+
prnumber=$(jq -r '.pull_request.number' < 'artifacts/Event File/event.json')
39+
sanitized_prnumber=$(echo "$prnumber" | grep -E '^[0-9]+$' || echo "")
40+
if [ -n "$sanitized_prnumber" ]; then
41+
echo "PR_NUMBER=$sanitized_prnumber" >> "$GITHUB_ENV"
42+
else
43+
echo "PR_NUMBER=" >> "$GITHUB_ENV"
44+
fi
4245
- name: Publish Unit Test Results
4346
uses: EnricoMi/publish-unit-test-result-action@v2
4447
with:

0 commit comments

Comments
 (0)