Skip to content

Commit b2d9c58

Browse files
committed
Actions: improve improper access control query
Closes: #20706
1 parent daead03 commit b2d9c58

File tree

6 files changed

+32
-4
lines changed

6 files changed

+32
-4
lines changed

actions/ql/src/Security/CWE-285/ImproperAccessControl.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import codeql.actions.security.UntrustedCheckoutQuery
1515
import codeql.actions.security.ControlChecks
1616

17-
from LocalJob job, LabelCheck check, MutableRefCheckoutStep checkout, Event event
17+
from LocalJob job, LabelCheck check, PRHeadCheckoutStep checkout, Event event
1818
where
1919
job.isPrivileged() and
2020
job.getAStep() = checkout and
@@ -25,6 +25,8 @@ where
2525
event.getAnActivityType() = "synchronize"
2626
or
2727
not exists(job.getATriggerEvent())
28+
or
29+
checkout instanceof MutableRefCheckoutStep
2830
)
2931
select checkout, "The checked-out code can be modified after the authorization check $@.", check,
3032
check.toString()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `actions/improper-access-control` query has been improved to correctly detect cases where either the check
5+
triggers or the checkout reference are unsafe, rather than only when both applied as was done previously.

actions/ql/test/query-tests/Security/CWE-285/.github/workflows/test2.yml renamed to actions/ql/test/query-tests/Security/CWE-285/.github/workflows/bad_checkout.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ jobs:
1616
uses: actions/checkout@v3
1717
if: contains(github.event.pull_request.labels.*.name, 'safe to test')
1818
with:
19-
ref: ${{ github.event.pull_request.head.ref }}
19+
ref: ${{ github.event.pull_request.head.ref }} # BAD (mutable ref)
2020
- run: ./cmd

actions/ql/test/query-tests/Security/CWE-285/.github/workflows/test1.yml renamed to actions/ql/test/query-tests/Security/CWE-285/.github/workflows/bad_triggers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ jobs:
1616
uses: actions/checkout@v3
1717
if: contains(github.event.pull_request.labels.*.name, 'safe to test')
1818
with:
19-
ref: ${{ github.event.pull_request.head.ref }}
19+
ref: ${{ github.event.pull_request.head.sha }} # BAD (bad trigger)
2020
- run: ./cmd
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Pull request feedback
2+
3+
on:
4+
pull_request_target:
5+
types: [ labeled ]
6+
7+
permissions: {}
8+
jobs:
9+
test:
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repo for OWNER TEST
16+
uses: actions/checkout@v3
17+
if: contains(github.event.pull_request.labels.*.name, 'safe to test')
18+
with:
19+
ref: ${{ github.event.pull_request.head.sha }} # GOOD (labeled event + immutable ref)
20+
- run: ./cmd
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
| .github/workflows/test1.yml:15:7:20:4 | Uses Step | The checked-out code can be modified after the authorization check $@. | .github/workflows/test1.yml:17:11:17:75 | contain ... test') | contain ... test') |
1+
| .github/workflows/bad_checkout.yml:15:7:20:4 | Uses Step | The checked-out code can be modified after the authorization check $@. | .github/workflows/bad_checkout.yml:17:11:17:75 | contain ... test') | contain ... test') |
2+
| .github/workflows/bad_triggers.yml:15:7:20:4 | Uses Step | The checked-out code can be modified after the authorization check $@. | .github/workflows/bad_triggers.yml:17:11:17:75 | contain ... test') | contain ... test') |

0 commit comments

Comments
 (0)