Skip to content

Commit 08573f6

Browse files
Fix: Resolve code injection vulnerability in ASH PR comment workflow (#171)
* feat: add automated ASH security scanning workflow for PRs * fix: resolve code injection vulnerability in ASH PR comment workflow
1 parent 3464fb8 commit 08573f6

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

.github/workflows/ash-pr-comment.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ jobs:
4444
- name: Post comment on PR
4545
if: steps.pr-info.outputs.pr_number
4646
uses: actions/github-script@v7
47+
env:
48+
PR_NUMBER: ${{ steps.pr-info.outputs.pr_number }}
49+
PR_SHA: ${{ steps.pr-info.outputs.pr_sha }}
4750
with:
4851
github-token: ${{ secrets.GITHUB_TOKEN }}
4952
script: |
@@ -56,8 +59,8 @@ jobs:
5659
}
5760
5861
const commentBody = fs.readFileSync(commentPath, 'utf8');
59-
const prNumber = parseInt('${{ steps.pr-info.outputs.pr_number }}');
60-
const prSha = '${{ steps.pr-info.outputs.pr_sha }}';
62+
const prNumber = parseInt(process.env.PR_NUMBER);
63+
const prSha = process.env.PR_SHA;
6164
6265
if (!prNumber) {
6366
console.log('Invalid PR number');

.github/workflows/ash-pr-security-scan.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ on:
1010

1111
permissions:
1212
contents: read
13-
pull-requests: write
1413

1514
concurrency:
1615
group: ash-${{ github.workflow }}-${{ github.ref }}
@@ -60,32 +59,34 @@ jobs:
6059
6160
- name: Get PR changed files
6261
if: always()
63-
id: get-files
64-
run: |
65-
echo "Getting changed files for PR..."
66-
git fetch origin ${{ github.base_ref }}
67-
git diff --name-only origin/${{ github.base_ref }}...HEAD > changed-files.txt
68-
echo "Changed files:"
69-
cat changed-files.txt
62+
id: changed-files
63+
uses: tj-actions/changed-files@v46
7064

7165
- name: Create PR files directory for scanning
7266
if: always()
7367
run: |
7468
mkdir -p pr-scan-dir
7569
76-
# Copy only changed files to scan directory
77-
if [ -s changed-files.txt ]; then
78-
while IFS= read -r file; do
70+
# Save changed files list for Python script
71+
changed_files="${{ steps.changed-files.outputs.all_changed_files }}"
72+
if [ -n "$changed_files" ]; then
73+
echo "$changed_files" | tr ' ' '\n' > changed-files.txt
74+
echo "Changed files:"
75+
cat changed-files.txt
76+
77+
# Copy only changed files to scan directory
78+
for file in $changed_files; do
7979
if [ -f "$file" ]; then
8080
# Create directory structure
8181
mkdir -p "pr-scan-dir/$(dirname "$file")"
8282
# Copy the file
8383
cp "$file" "pr-scan-dir/$file"
8484
echo "Copied: $file"
8585
fi
86-
done < changed-files.txt
86+
done
8787
else
8888
echo "No files changed in this PR"
89+
touch changed-files.txt
8990
fi
9091
9192
echo "Files to scan:"

0 commit comments

Comments
 (0)