Skip to content

Commit c197e75

Browse files
caaladormanolo
andauthored
fix: Replace pull_request_target with secure alternatives (#22952) (#22957)
Address GitHub's December 2025 security changes to pull_request_target: - Workflows now always run from default branch (not PR branch) - Environment protection rules evaluate against execution branch See: https://bybowu.com/article/dec-8-fix-github-actions-pull-request-target-now Changes: - validation.yml: Use pull_request with protected environment for forks Co-authored-by: Manuel Carrasco Moñino <manolo@vaadin.com>
1 parent 9a0a725 commit c197e75

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

.github/workflows/validation.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ on:
33
push:
44
branches: [main, '24.9', '24.8', '24.7']
55
workflow_dispatch:
6-
pull_request_target:
7-
types: [opened, synchronize, reopened, edited]
6+
pull_request:
7+
types: [opened, synchronize, reopened]
88
permissions:
99
contents: read
1010
concurrency:
11-
group: ${{ github.head_ref }} || ${{ github.ref_name }}
11+
group: ${{ github.head_ref || github.ref_name }}
1212
cancel-in-progress: true
1313
env:
1414
HEAD_REF: ${{ github.head_ref }}
@@ -20,6 +20,8 @@ jobs:
2020
build:
2121
timeout-minutes: 30
2222
runs-on: ubuntu-24.04
23+
# Environment requires approval for PRs from forks (configure in repo settings)
24+
environment: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork && 'pr-tests' || '' }}
2325
outputs:
2426
matrix-unit: ${{ steps.set-matrix.outputs.matrix-unit }}
2527
matrix-it: ${{ steps.set-matrix.outputs.matrix-it }}
@@ -44,8 +46,6 @@ jobs:
4446
&& echo "🚫 **TB_LICENSE** is not defined, check that **${{github.repository}}** repo has a valid secret" \
4547
| tee -a $GITHUB_STEP_SUMMARY && exit 1 || exit 0
4648
- uses: actions/checkout@v4
47-
with:
48-
ref: ${{env.HEAD_SHA}}
4949
- uses: actions/setup-node@v4
5050
with:
5151
node-version: '22.14.0'
@@ -90,6 +90,7 @@ jobs:
9090
fail-fast: false
9191
matrix: ${{fromJson(needs.build.outputs.matrix-unit)}}
9292
runs-on: ubuntu-24.04
93+
environment: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork && 'pr-tests' || '' }}
9394
steps:
9495
- uses: actions/checkout@v4
9596
with:
@@ -156,10 +157,9 @@ jobs:
156157
fail-fast: false
157158
matrix: ${{fromJson(needs.build.outputs.matrix-it)}}
158159
runs-on: ubuntu-24.04
160+
environment: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork && 'pr-tests' || '' }}
159161
steps:
160162
- uses: actions/checkout@v4
161-
with:
162-
ref: ${{env.HEAD_SHA}}
163163
- uses: actions/setup-node@v4
164164
with:
165165
node-version: '22.14.0'
@@ -248,8 +248,6 @@ jobs:
248248
name: tests-output
249249
pattern: tests-output-*
250250
- uses: actions/checkout@v4
251-
with:
252-
ref: ${{env.HEAD_SHA}}
253251
- uses: actions/download-artifact@v4
254252
with:
255253
name: tests-output
@@ -273,7 +271,7 @@ jobs:
273271
echo "🚫 THERE ARE TEST MODULES WITH FAILURES or BEEN CANCELLED" | tee -a $GITHUB_STEP_SUMMARY
274272
exit 1
275273
api-diff-labeling:
276-
if: github.event_name == 'pull_request_target'
274+
if: github.event_name == 'pull_request'
277275
timeout-minutes: 10
278276
runs-on: ubuntu-24.04
279277
permissions:
@@ -282,8 +280,6 @@ jobs:
282280
pull-requests: write
283281
steps:
284282
- uses: actions/checkout@v4
285-
with:
286-
ref: ${{env.HEAD_SHA}}
287283
- name: Set up JDK
288284
uses: actions/setup-java@v4
289285
with:

0 commit comments

Comments
 (0)