Skip to content

Commit 9326a7c

Browse files
committed
fix: move remaining ${{ }} expressions from shell run: to env: blocks
P1 fixes: - copyright-check.yml: move github.event.pull_request.base.ref to env: (branch names can contain shell metacharacters - injection risk) - trufflehog-scan.yml: add persist-credentials: false to checkout - trufflehog-scan.yml: move vars.TRUFFLEHOG_EXCLUDES to env: P2 fixes (defense-in-depth): - trufflehog-scan.yml: move step output counts to env: in Process step - copyright-check.yml: move step outputs (config-file, status) to env: - copyright-check.yml: move base.sha, head.sha, base.ref to env: in Get changed files step
1 parent e7f554c commit 9326a7c

2 files changed

Lines changed: 26 additions & 12 deletions

File tree

.github/workflows/copyright-check.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ jobs:
3030

3131
- name: Setup config
3232
id: setup-config
33+
env:
34+
BASE_REF: ${{ github.event.pull_request.base.ref }}
35+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
GH_REPO: ${{ github.repository }}
3337
run: |
3438
cfg="target-repo/.copyrightconfig"
3539
if [ ! -f "$cfg" ]; then
36-
git clone --depth 1 --branch ${{ github.event.pull_request.base.ref }} \
37-
https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git base-repo
40+
git clone --depth 1 --branch "$BASE_REF" \
41+
https://x-access-token:${GH_TOKEN}@github.com/${GH_REPO}.git base-repo
3842
[ -f base-repo/.copyrightconfig ] && cfg="base-repo/.copyrightconfig"
3943
fi
4044
[ -f "$cfg" ] || { echo "missing config"; exit 1; }
@@ -49,12 +53,14 @@ jobs:
4953

5054
- name: Get changed files
5155
id: changed-files
56+
env:
57+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
58+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
59+
BASE_REF: ${{ github.event.pull_request.base.ref }}
5260
run: |
5361
cd target-repo
54-
base_sha="${{ github.event.pull_request.base.sha }}"
55-
head_sha="${{ github.event.pull_request.head.sha }}"
56-
git fetch origin ${{ github.event.pull_request.base.ref }}
57-
git diff --name-only --diff-filter=AMR "$base_sha" "$head_sha" | while read f; do [ -f "$f" ] && echo "$f"; done > ../files_to_check.txt
62+
git fetch origin "$BASE_REF"
63+
git diff --name-only --diff-filter=AMR "$BASE_SHA" "$HEAD_SHA" | while read f; do [ -f "$f" ] && echo "$f"; done > ../files_to_check.txt
5864
count=$(wc -l < ../files_to_check.txt | tr -d ' ')
5965
if [ "$count" -eq 0 ]; then echo "skip-validation=true" >> $GITHUB_OUTPUT; else echo "skip-validation=false" >> $GITHUB_OUTPUT; fi
6066
echo "files-count=$count" >> $GITHUB_OUTPUT
@@ -65,9 +71,10 @@ jobs:
6571
continue-on-error: true
6672
env:
6773
COPYRIGHT_CHECK_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
74+
CONFIG_FILE: ${{ steps.setup-config.outputs.config-file }}
6875
run: |
6976
script="pr-workflows/scripts/copyrightcheck.py"
70-
cfg="${{ steps.setup-config.outputs.config-file }}"
77+
cfg="$CONFIG_FILE"
7178
[ -f "$script" ] || { echo "script missing"; exit 1; }
7279
chmod +x "$script"
7380
files=$(tr '\n' ' ' < files_to_check.txt)
@@ -125,8 +132,9 @@ jobs:
125132
if: always() && steps.changed-files.outputs.skip-validation != 'true'
126133
env:
127134
COMMENT_ACTION: ${{ steps.pr-comment.outputs.comment_action }}
135+
VALIDATION_STATUS: ${{ steps.validate.outputs.status }}
128136
run: |
129-
if [ "${{ steps.validate.outputs.status }}" != "success" ]; then
137+
if [ "$VALIDATION_STATUS" != "success" ]; then
130138
if [ "$COMMENT_ACTION" = "updated" ] || [ "$COMMENT_ACTION" = "created" ]; then
131139
echo "::error title=Copyright Validation Failed::See the $COMMENT_ACTION PR comment for detailed results.";
132140
else

.github/workflows/trufflehog-scan.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
uses: actions/checkout@v4
4141
with:
4242
fetch-depth: 0
43+
persist-credentials: false
4344

4445
- name: Fetch PR head commits
4546
if: github.event_name != 'workflow_dispatch'
@@ -50,6 +51,8 @@ jobs:
5051
5152
- name: Setup exclude config
5253
id: config
54+
env:
55+
TRUFFLEHOG_EXCLUDES: ${{ vars.TRUFFLEHOG_EXCLUDES }}
5356
run: |
5457
# Always include default exclusions
5558
echo "Adding default exclusions"
@@ -58,10 +61,10 @@ jobs:
5861
EOF
5962
6063
# Append repo/org-level custom exclusions if defined
61-
if [ -n "${{ vars.TRUFFLEHOG_EXCLUDES }}" ]; then
64+
if [ -n "$TRUFFLEHOG_EXCLUDES" ]; then
6265
echo "Adding repo/org-level TRUFFLEHOG_EXCLUDES patterns"
6366
# Support both comma-separated and newline-separated patterns
64-
echo "${{ vars.TRUFFLEHOG_EXCLUDES }}" | tr ',' '\n' | sed '/^$/d' >> .trufflehog-ignore
67+
echo "$TRUFFLEHOG_EXCLUDES" | tr ',' '\n' | sed '/^$/d' >> .trufflehog-ignore
6568
fi
6669
6770
echo "Exclusion patterns:"
@@ -156,9 +159,12 @@ jobs:
156159
- name: Process scan results
157160
id: process
158161
if: github.event_name != 'workflow_dispatch'
162+
env:
163+
VERIFIED_COUNT: ${{ steps.parse.outputs.verified_count }}
164+
UNVERIFIED_COUNT: ${{ steps.parse.outputs.unverified_count }}
159165
run: |
160-
VERIFIED=${{ steps.parse.outputs.verified_count || 0 }}
161-
UNVERIFIED=${{ steps.parse.outputs.unverified_count || 0 }}
166+
VERIFIED=${VERIFIED_COUNT:-0}
167+
UNVERIFIED=${UNVERIFIED_COUNT:-0}
162168
163169
if [ "$VERIFIED" -gt 0 ]; then
164170
# Verified secrets found - must fail

0 commit comments

Comments
 (0)