Skip to content

Commit 66138df

Browse files
author
Alvaro Muñoz
authored
Merge pull request #37 from github/toctou_refinements
Reduce FP for actor/association checks that cannot be bypassed this way
2 parents 0456dcd + dfeefe0 commit 66138df

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

ql/src/Security/CWE-367/UntrustedCheckoutTOCTOUCritical.ql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ where
2020
// the mutable checkout step is protected by an access check
2121
check = [checkout.getIf(), checkout.getEnclosingJob().getIf()] and
2222
// the checked-out code may lead to arbitrary code execution
23-
checkout.getAFollowingStep() instanceof PoisonableStep
23+
checkout.getAFollowingStep() instanceof PoisonableStep and
24+
(
25+
// label gates do not depend on the triggering event
26+
check instanceof LabelControlCheck
27+
or
28+
// actor or Association gates apply to IssueOps only
29+
(check instanceof AssociationControlCheck or check instanceof ActorControlCheck) and
30+
check.getEnclosingJob().getATriggerEvent().getName().matches("%_comment")
31+
)
2432
select checkout, "The checked-out code can be changed after the authorization check o step $@.",
2533
check, check.toString()

ql/src/Security/CWE-367/UntrustedCheckoutTOCTOUHigh.ql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ where
2020
// the mutable checkout step is protected by an access check
2121
check = [checkout.getIf(), checkout.getEnclosingJob().getIf()] and
2222
// there are no evidences that the checked-out code can lead to arbitrary code execution
23-
not checkout.getAFollowingStep() instanceof PoisonableStep
23+
not checkout.getAFollowingStep() instanceof PoisonableStep and
24+
(
25+
// label gates do not depend on the triggering event
26+
check instanceof LabelControlCheck
27+
or
28+
// actor or Association gates apply to IssueOps only
29+
(check instanceof AssociationControlCheck or check instanceof ActorControlCheck) and
30+
check.getEnclosingJob().getATriggerEvent().getName().matches("%_comment")
31+
)
2432
select checkout, "The checked-out code can be changed after the authorization check o step $@.",
2533
check, check.toString()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Making Label gates the only ones bypassable with TOCTOU races since actor or association ones should not be bypassable
2+
name: Label Trigger Test
3+
on:
4+
pull_request_target:
5+
types: [labeled]
6+
branches: [main]
7+
8+
jobs:
9+
integration-tests:
10+
runs-on: ubuntu-latest
11+
if: github.repository_owner == 'npm' && github.actor == 'dependabot[bot]'
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
ref: ${{ github.event.pull_request.head.ref }}
16+
repository: ${{ github.event.pull_request.head.repo.full_name }}
17+
- run: bash label_example/tests.sh

0 commit comments

Comments
 (0)