Skip to content

Commit 14e12e1

Browse files
author
Jonathan Visser
committed
Install lint dependencies from the base branch under pull_request_target
pull_request_target runs are not gated by the fork approval policy and carry a write token, so installing requirements from the pull request head let any fork execute arbitrary code in a privileged context. Check out the base branch for pip install first; the head is only checked out afterwards and processed as data by mdformat.
1 parent cb79a7a commit 14e12e1

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

.github/workflows/lint.yaml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
name: Run linting and suggest changes
22

3+
# `pull_request_target` because posting review suggestions requires a write
4+
# token, which `pull_request` withholds from fork pull requests. Note that the
5+
# fork approval policy does NOT gate `pull_request_target` runs, so nothing
6+
# from the pull request head may ever be executed here: dependencies are
7+
# installed from the trusted base branch BEFORE the head is checked out, and
8+
# the head is only processed as data by mdformat.
39
on:
410
pull_request_target:
511

@@ -12,20 +18,22 @@ jobs:
1218
permissions:
1319
contents: read
1420
pull-requests: write
15-
strategy:
16-
matrix:
17-
python-version: ['3.12']
1821

1922
steps:
20-
- uses: actions/checkout@v4
23+
- name: Check out trusted dependency manifests from the base branch
24+
uses: actions/checkout@v4
2125
with:
22-
ref: ${{ github.event.pull_request.head.sha }}
26+
ref: ${{ github.event.pull_request.base.sha }}
2327
- uses: actions/setup-python@v5
2428
with:
25-
python-version: ${{ matrix.python-version }}
26-
- name: Install dependencies
29+
python-version: '3.12'
30+
- name: Install dependencies from the base branch
2731
run: |
2832
pip install -r requirements/base.txt
33+
- name: Check out the pull request head
34+
uses: actions/checkout@v4
35+
with:
36+
ref: ${{ github.event.pull_request.head.sha }}
2937
- name: Check markdown format
3038
run: mdformat docs/
3139
- uses: parkerbxyz/suggest-changes@e24c62a5a3235e6090721c7b0355b825a3a4ba9a # v3.1.2

0 commit comments

Comments
 (0)