Skip to content

Commit d9e589c

Browse files
author
Alvaro Muñoz
committed
Remove unnecessary boundary anchors
1 parent 6cb15f0 commit d9e589c

File tree

2 files changed

+34
-36
lines changed

2 files changed

+34
-36
lines changed

ql/lib/codeql/actions/Ast.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ module Utils {
1212

1313
bindingset[regex]
1414
string wrapRegexp(string regex) {
15-
result = ["\\b" + regex + "\\b", "fromJSON\\(" + regex + "\\)", "toJSON\\(" + regex + "\\)"]
15+
result =
16+
[
17+
"\\b" + regex + "\\b", "fromJSON\\(\\s*" + regex + "\\s*\\)",
18+
"toJSON\\(\\s*" + regex + "\\s*\\)"
19+
]
1620
}
1721
}
1822

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

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ abstract class RemoteFlowSource extends SourceNode {
2525

2626
bindingset[context]
2727
private predicate isExternalUserControlledIssue(string context) {
28-
exists(string reg |
29-
reg = ["\\bgithub\\.event\\.issue\\.title\\b", "\\bgithub\\.event\\.issue\\.body\\b"]
30-
|
28+
exists(string reg | reg = ["github\\.event\\.issue\\.title", "github\\.event\\.issue\\.body"] |
3129
Utils::normalizeExpr(context).regexpMatch(Utils::wrapRegexp(reg))
3230
)
3331
}
@@ -37,12 +35,12 @@ private predicate isExternalUserControlledPullRequest(string context) {
3735
exists(string reg |
3836
reg =
3937
[
40-
"\\bgithub\\.event\\.pull_request\\.title\\b", "\\bgithub\\.event\\.pull_request\\.body\\b",
41-
"\\bgithub\\.event\\.pull_request\\.head\\.label\\b",
42-
"\\bgithub\\.event\\.pull_request\\.head\\.repo\\.default_branch\\b",
43-
"\\bgithub\\.event\\.pull_request\\.head\\.repo\\.description\\b",
44-
"\\bgithub\\.event\\.pull_request\\.head\\.repo\\.homepage\\b",
45-
"\\bgithub\\.event\\.pull_request\\.head\\.ref\\b", "\\bgithub\\.head_ref\\b"
38+
"github\\.event\\.pull_request\\.title", "github\\.event\\.pull_request\\.body",
39+
"github\\.event\\.pull_request\\.head\\.label",
40+
"github\\.event\\.pull_request\\.head\\.repo\\.default_branch",
41+
"github\\.event\\.pull_request\\.head\\.repo\\.description",
42+
"github\\.event\\.pull_request\\.head\\.repo\\.homepage",
43+
"github\\.event\\.pull_request\\.head\\.ref", "github\\.head_ref"
4644
]
4745
|
4846
Utils::normalizeExpr(context).regexpMatch(Utils::wrapRegexp(reg))
@@ -51,23 +49,21 @@ private predicate isExternalUserControlledPullRequest(string context) {
5149

5250
bindingset[context]
5351
private predicate isExternalUserControlledReview(string context) {
54-
Utils::normalizeExpr(context)
55-
.regexpMatch(Utils::wrapRegexp("\\bgithub\\.event\\.review\\.body\\b"))
52+
Utils::normalizeExpr(context).regexpMatch(Utils::wrapRegexp("github\\.event\\.review\\.body"))
5653
}
5754

5855
bindingset[context]
5956
private predicate isExternalUserControlledComment(string context) {
60-
Utils::normalizeExpr(context)
61-
.regexpMatch(Utils::wrapRegexp("\\bgithub\\.event\\.comment\\.body\\b"))
57+
Utils::normalizeExpr(context).regexpMatch(Utils::wrapRegexp("github\\.event\\.comment\\.body"))
6258
}
6359

6460
bindingset[context]
6561
private predicate isExternalUserControlledGollum(string context) {
6662
exists(string reg |
6763
reg =
6864
[
69-
"\\bgithub\\.event\\.pages\\[[0-9]+\\]\\.page_name\\b",
70-
"\\bgithub\\.event\\.pages\\[[0-9]+\\]\\.title\\b"
65+
"github\\.event\\.pages\\[[0-9]+\\]\\.page_name",
66+
"github\\.event\\.pages\\[[0-9]+\\]\\.title"
7167
]
7268
|
7369
Utils::normalizeExpr(context).regexpMatch(Utils::wrapRegexp(reg))
@@ -79,16 +75,15 @@ private predicate isExternalUserControlledCommit(string context) {
7975
exists(string reg |
8076
reg =
8177
[
82-
"\\bgithub\\.event\\.commits\\[[0-9]+\\]\\.message\\b",
83-
"\\bgithub\\.event\\.head_commit\\.message\\b",
84-
"\\bgithub\\.event\\.head_commit\\.author\\.email\\b",
85-
"\\bgithub\\.event\\.head_commit\\.author\\.name\\b",
86-
"\\bgithub\\.event\\.head_commit\\.committer\\.email\\b",
87-
"\\bgithub\\.event\\.head_commit\\.committer\\.name\\b",
88-
"\\bgithub\\.event\\.commits\\[[0-9]+\\]\\.author\\.email\\b",
89-
"\\bgithub\\.event\\.commits\\[[0-9]+\\]\\.author\\.name\\b",
90-
"\\bgithub\\.event\\.commits\\[[0-9]+\\]\\.committer\\.email\\b",
91-
"\\bgithub\\.event\\.commits\\[[0-9]+\\]\\.committer\\.name\\b",
78+
"github\\.event\\.commits\\[[0-9]+\\]\\.message", "github\\.event\\.head_commit\\.message",
79+
"github\\.event\\.head_commit\\.author\\.email",
80+
"github\\.event\\.head_commit\\.author\\.name",
81+
"github\\.event\\.head_commit\\.committer\\.email",
82+
"github\\.event\\.head_commit\\.committer\\.name",
83+
"github\\.event\\.commits\\[[0-9]+\\]\\.author\\.email",
84+
"github\\.event\\.commits\\[[0-9]+\\]\\.author\\.name",
85+
"github\\.event\\.commits\\[[0-9]+\\]\\.committer\\.email",
86+
"github\\.event\\.commits\\[[0-9]+\\]\\.committer\\.name",
9287
]
9388
|
9489
Utils::normalizeExpr(context).regexpMatch(Utils::wrapRegexp(reg))
@@ -98,7 +93,7 @@ private predicate isExternalUserControlledCommit(string context) {
9893
bindingset[context]
9994
private predicate isExternalUserControlledDiscussion(string context) {
10095
exists(string reg |
101-
reg = ["\\bgithub\\.event\\.discussion\\.title\\b", "\\bgithub\\.event\\.discussion\\.body\\b"]
96+
reg = ["github\\.event\\.discussion\\.title", "github\\.event\\.discussion\\.body"]
10297
|
10398
Utils::normalizeExpr(context).regexpMatch(Utils::wrapRegexp(reg))
10499
)
@@ -109,15 +104,14 @@ private predicate isExternalUserControlledWorkflowRun(string context) {
109104
exists(string reg |
110105
reg =
111106
[
112-
"\\bgithub\\.event\\.workflow\\.path\\b",
113-
"\\bgithub\\.event\\.workflow_run\\.head_branch\\b",
114-
"\\bgithub\\.event\\.workflow_run\\.display_title\\b",
115-
"\\bgithub\\.event\\.workflow_run\\.head_repository\\.description\\b",
116-
"\\bgithub\\.event\\.workflow_run\\.head_commit\\.message\\b",
117-
"\\bgithub\\.event\\.workflow_run\\.head_commit\\.author\\.email\\b",
118-
"\\bgithub\\.event\\.workflow_run\\.head_commit\\.author\\.name\\b",
119-
"\\bgithub\\.event\\.workflow_run\\.head_commit\\.committer\\.email\\b",
120-
"\\bgithub\\.event\\.workflow_run\\.head_commit\\.committer\\.name\\b",
107+
"github\\.event\\.workflow\\.path", "github\\.event\\.workflow_run\\.head_branch",
108+
"github\\.event\\.workflow_run\\.display_title",
109+
"github\\.event\\.workflow_run\\.head_repository\\.description",
110+
"github\\.event\\.workflow_run\\.head_commit\\.message",
111+
"github\\.event\\.workflow_run\\.head_commit\\.author\\.email",
112+
"github\\.event\\.workflow_run\\.head_commit\\.author\\.name",
113+
"github\\.event\\.workflow_run\\.head_commit\\.committer\\.email",
114+
"github\\.event\\.workflow_run\\.head_commit\\.committer\\.name",
121115
]
122116
|
123117
Utils::normalizeExpr(context).regexpMatch(Utils::wrapRegexp(reg))

0 commit comments

Comments
 (0)