Skip to content

Commit b094a27

Browse files
authored
fix: validation of PRs from forks (#31)
* fix: validation of PRs from forks * Checkout the right ref * Checkout the right ref
1 parent bcd4917 commit b094a27

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

.github/workflows/validate.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
name: Validate newly added JSON
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
types:
66
- opened
77
- synchronize
88

9+
permissions:
10+
contents: read
11+
912
jobs:
1013
validate-json:
1114
runs-on: ubuntu-latest
@@ -15,11 +18,19 @@ jobs:
1518
uses: actions/checkout@v4
1619
with:
1720
fetch-depth: 2
21+
ref: refs/pull/${{ github.event.pull_request.number }}/merge
22+
persist-credentials: false
1823

1924
# Must be done before setup-node.
2025
- name: Enable Corepack
2126
run: corepack enable
2227

28+
# We are using `pull_request_target`, meaning untrusted code could access the secrets.
29+
# For PRs from forks, we want to rollback to the trusted version of `actions/`. Other
30+
# directories do not contain any runnable code.
31+
- if: github.event.pull_request.head.repo.full_name != github.repository
32+
run: git checkout HEAD^ -- actions/
33+
2334
- name: Setup Node.js
2435
uses: actions/setup-node@v4
2536
with:

0 commit comments

Comments
 (0)