Skip to content

Commit 9417e1d

Browse files
author
Alvaro Muñoz
committed
Classify checkout steps
1 parent addedd0 commit 9417e1d

File tree

5 files changed

+19
-52
lines changed

5 files changed

+19
-52
lines changed

ql/lib/codeql/actions/dataflow/FlowSources.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ private predicate branchEvent(string context) {
113113
"github\\.event\\.pull_request\\.head\\.repo\\.default_branch",
114114
"github\\.event\\.pull_request\\.head\\.ref", "github\\.head_ref",
115115
"github\\.event\\.workflow_run\\.head_branch",
116-
"github\\.event\\.workflow_run\\.head_branch",
117116
"github\\.event\\.workflow_run\\.pull_requests\\[[0-9]+\\]\\.head\\.ref",
117+
"github\\.event\\.merge_group\\.head_ref",
118118
]
119119
|
120120
Utils::normalizeExpr(context).regexpMatch(Utils::wrapRegexp(reg))
@@ -146,6 +146,7 @@ private predicate emailEvent(string context) {
146146
"github\\.event\\.head_commit\\.committer\\.email",
147147
"github\\.event\\.commits\\[[0-9]+\\]\\.author\\.email",
148148
"github\\.event\\.commits\\[[0-9]+\\]\\.committer\\.email",
149+
"github\\.event\\.merge_group\\.committer\\.email",
149150
"github\\.event\\.workflow_run\\.head_commit\\.author\\.email",
150151
"github\\.event\\.workflow_run\\.head_commit\\.committer\\.email",
151152
]
@@ -165,6 +166,7 @@ private predicate usernameEvent(string context) {
165166
"github\\.event\\.head_commit\\.committer\\.name",
166167
"github\\.event\\.commits\\[[0-9]+\\]\\.author\\.name",
167168
"github\\.event\\.commits\\[[0-9]+\\]\\.committer\\.name",
169+
"github\\.event\\.merge_group\\.committer\\.name",
168170
"github\\.event\\.workflow_run\\.head_commit\\.author\\.name",
169171
"github\\.event\\.workflow_run\\.head_commit\\.committer\\.name",
170172
]

ql/lib/codeql/actions/security/UntrustedCheckoutQuery.qll

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ predicate containsHeadSHA(string s) {
4040
"\\bgithub\\.event\\.check_run\\.check_suite\\.pull_requests\\[\\d+\\]\\.head\\.sha\\b",
4141
"\\bgithub\\.event\\.check_run\\.head_sha\\b",
4242
"\\bgithub\\.event\\.check_run\\.pull_requests\\[\\d+\\]\\.head\\.sha\\b",
43+
"\\bgithub\\.event\\.merge_group\\.head_sha\\b",
44+
"\\bgithub\\.event\\.merge_group\\.head_commit\\.id\\b",
4345
// heuristics
4446
"\\bhead\\.sha\\b", "\\bhead_sha\\b", "\\bpr_head_sha\\b"
4547
], _, _)
@@ -56,6 +58,7 @@ predicate containsHeadRef(string s) {
5658
"\\bgithub\\.event\\.check_suite\\.pull_requests\\[\\d+\\]\\.head\\.ref\\b",
5759
"\\bgithub\\.event\\.check_run\\.check_suite\\.pull_requests\\[\\d+\\]\\.head\\.ref\\b",
5860
"\\bgithub\\.event\\.check_run\\.pull_requests\\[\\d+\\]\\.head\\.ref\\b",
61+
"\\bgithub\\.event\\.merge_group\\.head_ref\\b",
5962
// heuristics
6063
"\\bhead\\.ref\\b", "\\bhead_ref\\b", "\\bpr_head_ref\\b",
6164
// env vars
@@ -64,11 +67,17 @@ predicate containsHeadRef(string s) {
6467
)
6568
}
6669

67-
/** Checkout of a Pull Request HEAD ref */
70+
/** Checkout of a Pull Request HEAD */
6871
abstract class PRHeadCheckoutStep extends Step { }
6972

73+
/** Checkout of a Pull Request HEAD ref */
74+
abstract class MutableRefCheckoutStep extends PRHeadCheckoutStep { }
75+
76+
/** Checkout of a Pull Request HEAD ref */
77+
abstract class SHACheckoutStep extends PRHeadCheckoutStep { }
78+
7079
/** Checkout of a Pull Request HEAD ref using actions/checkout action */
71-
class ActionsMutableRefCheckout extends PRHeadCheckoutStep instanceof UsesStep {
80+
class ActionsMutableRefCheckout extends MutableRefCheckoutStep instanceof UsesStep {
7281
ActionsMutableRefCheckout() {
7382
this.getCallee() = "actions/checkout" and
7483
(
@@ -102,7 +111,7 @@ class ActionsMutableRefCheckout extends PRHeadCheckoutStep instanceof UsesStep {
102111
}
103112

104113
/** Checkout of a Pull Request HEAD ref using actions/checkout action */
105-
class ActionsSHACheckout extends PRHeadCheckoutStep instanceof UsesStep {
114+
class ActionsSHACheckout extends SHACheckoutStep instanceof UsesStep {
106115
ActionsSHACheckout() {
107116
this.getCallee() = "actions/checkout" and
108117
(
@@ -132,7 +141,7 @@ class ActionsSHACheckout extends PRHeadCheckoutStep instanceof UsesStep {
132141
}
133142

134143
/** Checkout of a Pull Request HEAD ref using git within a Run step */
135-
class GitMutableRefCheckout extends PRHeadCheckoutStep instanceof Run {
144+
class GitMutableRefCheckout extends MutableRefCheckoutStep instanceof Run {
136145
GitMutableRefCheckout() {
137146
exists(string line |
138147
this.getScript().splitAt("\n") = line and
@@ -154,7 +163,7 @@ class GitMutableRefCheckout extends PRHeadCheckoutStep instanceof Run {
154163
}
155164

156165
/** Checkout of a Pull Request HEAD ref using git within a Run step */
157-
class GitSHACheckout extends PRHeadCheckoutStep instanceof Run {
166+
class GitSHACheckout extends SHACheckoutStep instanceof Run {
158167
GitSHACheckout() {
159168
exists(string line |
160169
this.getScript().splitAt("\n") = line and
@@ -173,7 +182,7 @@ class GitSHACheckout extends PRHeadCheckoutStep instanceof Run {
173182
}
174183

175184
/** Checkout of a Pull Request HEAD ref using gh within a Run step */
176-
class GhMutableRefCheckout extends PRHeadCheckoutStep instanceof Run {
185+
class GhMutableRefCheckout extends MutableRefCheckoutStep instanceof Run {
177186
GhMutableRefCheckout() {
178187
exists(string line |
179188
this.getScript().splitAt("\n") = line and
@@ -194,7 +203,7 @@ class GhMutableRefCheckout extends PRHeadCheckoutStep instanceof Run {
194203
}
195204

196205
/** Checkout of a Pull Request HEAD ref using gh within a Run step */
197-
class GhSHACheckout extends PRHeadCheckoutStep instanceof Run {
206+
class GhSHACheckout extends SHACheckoutStep instanceof Run {
198207
GhSHACheckout() {
199208
exists(string line |
200209
this.getScript().splitAt("\n") = line and

ql/src/Security/CWE-829/UnpinnedActionsTag.md

Lines changed: 0 additions & 44 deletions
This file was deleted.

ql/src/Security/CWE-829/UntrustedCheckoutError.md

Whitespace-only changes.

ql/src/Security/CWE-829/UntrustedCheckoutWarning.md

Whitespace-only changes.

0 commit comments

Comments
 (0)