Skip to content

Commit c09a872

Browse files
authored
Fix vulnerability in the branch name check workflow (#7982)
Before, a crafted branch name could be used to exfiltrate the github token and wreak havoc 😅
1 parent f32727d commit c09a872

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

.github/workflows/enforce_branch_name.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@ on:
44
pull_request_target:
55
types: [opened, reopened, synchronize]
66

7+
permissions:
8+
issues: write
9+
710
jobs:
811
check-source-branch:
912
runs-on: ubuntu-latest
1013
timeout-minutes: 10
1114
steps:
1215
- name: Check PR source branch
16+
env:
17+
IS_FORK: ${{ github.event.pull_request.head.repo.fork }}
18+
HEAD_REF: ${{ github.event.pull_request.head.ref }}
1319
run: |
1420
# Check if PR is from a fork
15-
if [[ "${{ github.event.pull_request.head.repo.fork }}" == "true" ]]; then
21+
if [[ "$IS_FORK" == "true" ]]; then
1622
# Check if PR is from the master/main branch of a fork
17-
if [[ "${{ github.event.pull_request.head.ref }}" == "master" || "${{ github.event.pull_request.head.ref }}" == "main" ]]; then
23+
if [[ "$HEAD_REF" == "master" || "$HEAD_REF" == "main" ]]; then
1824
echo "ERROR: Pull requests from the master/main branch of forks are not allowed, because it prevents maintainers from contributing to your PR"
1925
echo "Please create a feature branch in your fork and submit the PR from that branch instead."
2026
exit 1

0 commit comments

Comments
 (0)