-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathUntrustedCheckoutHigh.ql
More file actions
46 lines (44 loc) · 1.78 KB
/
UntrustedCheckoutHigh.ql
File metadata and controls
46 lines (44 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* @name Checkout of untrusted code in privileged context without privileged context use
* @description Privileged workflows have read/write access to the base repository and access to secrets.
* By explicitly checking out and running the build script from a fork the untrusted code is running in an environment
* that is able to push to the base repository and to access secrets.
* @kind problem
* @problem.severity error
* @precision high
* @security-severity 7.5
* @id actions/untrusted-checkout/high
* @tags actions
* security
* external/cwe/cwe-829
*/
import actions
import codeql.actions.security.UntrustedCheckoutQuery
import codeql.actions.security.PoisonableSteps
import codeql.actions.security.ControlChecks
from PRHeadCheckoutStep checkout, Event event
where
// the checkout is NOT followed by a known poisonable step
not checkout.getAFollowingStep() instanceof PoisonableStep and
// the checkout occurs in a privileged context
inPrivilegedContext(checkout, event) and
event.getName() = checkoutTriggers() and
(
// issue_comment: check for date comparison checks and actor/access control checks
event.getName() = "issue_comment" and
not exists(ControlCheck check, CommentVsHeadDateCheck date_check |
(
check instanceof ActorCheck or
check instanceof AssociationCheck or
check instanceof PermissionCheck
) and
check.dominates(checkout) and
date_check.dominates(checkout)
)
or
// not issue_comment triggered workflows
not event.getName() = "issue_comment" and
not exists(ControlCheck check | check.protects(checkout, event, "untrusted-checkout"))
)
select checkout, "Potential execution of untrusted code on a privileged workflow ($@)", event,
event.getName()