Skip to content

Commit 888d392

Browse files
authored
Merge pull request #21636 from jketema/actions-perm
Actions: Correctly check reusable workflow permissions in `actions/missing-workflow-permissions`
2 parents b9226a3 + 87f9b95 commit 888d392

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

actions/ql/src/Security/CWE-275/MissingActionsPermissions.ql

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,23 @@ string permissionsForJob(Job job) {
2626
"{" + concat(string permission | permission = jobNeedsPermission(job) | permission, ", ") + "}"
2727
}
2828

29+
predicate jobHasPermissions(Job job) {
30+
exists(job.getPermissions())
31+
or
32+
exists(job.getEnclosingWorkflow().getPermissions())
33+
or
34+
// The workflow is reusable and cannot be triggered in any other way; check callers
35+
exists(ReusableWorkflow r | r = job.getEnclosingWorkflow() |
36+
not exists(Event e | e = r.getOn().getAnEvent() | e.getName() != "workflow_call") and
37+
forall(Job caller | caller = job.getEnclosingWorkflow().(ReusableWorkflow).getACaller() |
38+
jobHasPermissions(caller)
39+
)
40+
)
41+
}
42+
2943
from Job job, string permissions
3044
where
31-
not exists(job.getPermissions()) and
32-
not exists(job.getEnclosingWorkflow().getPermissions()) and
45+
not jobHasPermissions(job) and
3346
// exists a trigger event that is not a workflow_call
3447
exists(Event e |
3548
e = job.getATriggerEvent() and
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The query `actions/missing-workflow-permissions` no longer produces false positive results on reusable workflows where all callers set permissions.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
on:
2+
workflow_call:
3+
4+
jobs:
5+
build:
6+
name: Build and test
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/deploy-pages
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
on:
2+
workflow_dispatch:
3+
4+
permissions:
5+
contents: read
6+
id-token: write
7+
pages: write
8+
9+
jobs:
10+
call-workflow:
11+
uses: ./.github/workflows/perms11.yml

0 commit comments

Comments
 (0)