Skip to content

Commit a1efc78

Browse files
author
Alvaro Muñoz
committed
Refactor regexps
1 parent 9ee9314 commit a1efc78

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import actions
22
import codeql.actions.dataflow.ExternalFlow
33

4-
string selfHostedRunnerRegexp() {
5-
// source: https://github.com/boostsecurityio/poutine/blob/main/opa/rego/poutine/utils.rego#L49C3-L49C136
6-
result =
7-
"(?i)^((ubuntu-(([0-9]{2})\\.04|latest)|macos-([0-9]{2}|latest)(-x?large)?|windows-(20[0-9]{2}|latest)|(buildjet|warp)-[a-z0-9-]+))$"
4+
bindingset[runner]
5+
predicate isGithubHostedRunner(string runner) {
6+
// list of github hosted repos: https://github.com/actions/runner-images/blob/main/README.md#available-images
7+
runner
8+
.toLowerCase()
9+
.regexpMatch("^(ubuntu-([0-9.]+|latest)|macos-([0-9]+|latest)(-x?large)?|windows-([0-9.]+|latest)|(buildjet|warp)-[a-z0-9-]+)$")
10+
}
11+
12+
bindingset[runner]
13+
predicate is3rdPartyHostedRunner(string runner) {
14+
runner.toLowerCase().regexpMatch("^(buildjet|warp)-[a-z0-9-]+$")
815
}
916

1017
/**
@@ -15,9 +22,13 @@ string selfHostedRunnerRegexp() {
1522
predicate staticallyIdentifiedSelfHostedRunner(Job job) {
1623
exists(string label |
1724
job.getATriggerEvent().getName() =
18-
["pull_request", "pull_request_review", "pull_request_review_comment", "pull_request_target"] and
25+
[
26+
"issue_comment", "pull_request", "pull_request_review", "pull_request_review_comment",
27+
"pull_request_target", "workflow_run"
28+
] and
1929
label = job.getARunsOnLabel() and
20-
not label.regexpMatch(selfHostedRunnerRegexp())
30+
not isGithubHostedRunner(label) and
31+
not is3rdPartyHostedRunner(label)
2132
)
2233
}
2334

0 commit comments

Comments
 (0)