Skip to content

Commit 3381c8d

Browse files
security: skip preview generation for fork PRs
Fixes CodeQL alert #42: Checkout of untrusted code in privileged context. Fork PRs could inject malicious code that runs with write permissions.
1 parent b43a710 commit 3381c8d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

.github/workflows/gen-preview.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,17 @@ jobs:
2323
steps:
2424
- name: Check conditions
2525
id: check
26+
env:
27+
HEAD_REPO: ${{ github.event.workflow_run.head_repository.full_name }}
28+
BASE_REPO: ${{ github.repository }}
2629
run: |
30+
# Security: Skip if workflow run is from a fork (untrusted code)
31+
if [[ "$HEAD_REPO" != "$BASE_REPO" ]]; then
32+
echo "::notice::Skipping: Workflow run is from fork '$HEAD_REPO', not '$BASE_REPO'"
33+
echo "should_run=false" >> $GITHUB_OUTPUT
34+
exit 0
35+
fi
36+
2737
CONCLUSION="${{ github.event.workflow_run.conclusion }}"
2838
2939
if [[ "$CONCLUSION" != "success" ]]; then

0 commit comments

Comments
 (0)