Skip to content

Commit a404a8c

Browse files
committed
use more set literals instead of big disjunctions
1 parent b488069 commit a404a8c

File tree

4 files changed

+67
-62
lines changed

4 files changed

+67
-62
lines changed

javascript/ql/lib/semmle/javascript/frameworks/ClosureLibrary.qll

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,40 @@ module ClosureLibrary {
1313
call = Closure::moduleImport("goog.string." + name).getACall() and succ = call
1414
|
1515
pred = call.getAnArgument() and
16-
(
17-
name = "canonicalizeNewlines" or
18-
name = "capitalize" or
19-
name = "collapseBreakingSpaces" or
20-
name = "collapseWhitespace" or
21-
name = "format" or
22-
name = "makeSafe" or // makeSafe just guards against null and undefined
23-
name = "newLineOrBr" or
24-
name = "normalizeSpaces" or
25-
name = "normalizeWhitespace" or
26-
name = "preserveSpaces" or
27-
name = "remove" or // removes first occurrence of a substring
28-
name = "repeat" or
29-
name = "splitLimit" or
30-
name = "stripNewlines" or
31-
name = "subs" or
32-
name = "toCamelCase" or
33-
name = "toSelectorCase" or
34-
name = "toTitleCase" or
35-
name = "trim" or
36-
name = "trimLeft" or
37-
name = "trimRight" or
38-
name = "unescapeEntities" or
39-
name = "whitespaceEscape"
40-
)
16+
name =
17+
[
18+
"canonicalizeNewlines", //
19+
"capitalize", //
20+
"collapseBreakingSpaces", //
21+
"collapseWhitespace", //
22+
"format", //
23+
"makeSafe", // makeSafe just guards against null and undefined
24+
"newLineOrBr", //
25+
"normalizeSpaces", //
26+
"normalizeWhitespace", //
27+
"preserveSpaces", //
28+
"remove", // removes first occurrence of a substring
29+
"repeat", //
30+
"splitLimit", //
31+
"stripNewlines", //
32+
"subs", //
33+
"toCamelCase", //
34+
"toSelectorCase", //
35+
"toTitleCase", //
36+
"trim", //
37+
"trimLeft", //
38+
"trimRight", //
39+
"unescapeEntities", //
40+
"whitespaceEscape"
41+
]
4142
or
4243
pred = call.getArgument(0) and
43-
(
44-
name = "truncate" or
45-
name = "truncateMiddle" or
46-
name = "unescapeEntitiesWithDocument"
47-
)
44+
name =
45+
[
46+
"truncate", //
47+
"truncateMiddle", //
48+
"unescapeEntitiesWithDocument", //
49+
]
4850
)
4951
}
5052
}

javascript/ql/lib/semmle/javascript/frameworks/UriLibraries.qll

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -362,29 +362,31 @@ private module ClosureLibraryUri {
362362
// static methods in goog.uri.utils
363363
arg = 0 and
364364
exists(string name | invoke = Closure::moduleImport("goog.uri.utils." + name).getACall() |
365-
name = "appendParam" or // preserve taint from the original URI, but not from the appended param
366-
name = "appendParams" or
367-
name = "appendParamsFromMap" or
368-
name = "appendPath" or
369-
name = "getParamValue" or
370-
name = "getParamValues" or
371-
name = "getPath" or
372-
name = "getPathAndAfter" or
373-
name = "getQueryData" or
374-
name = "parseQueryData" or
375-
name = "removeFragment" or
376-
name = "removeParam" or
377-
name = "setParam" or
378-
name = "setParamsFromMap" or
379-
name = "setPath" or
380-
name = "split"
365+
name =
366+
[
367+
"appendParam", // preserve taint from the original URI, but not from the appended param
368+
"appendParams", //
369+
"appendParamsFromMap", //
370+
"appendPath", //
371+
"getParamValue", //
372+
"getParamValues", //
373+
"getPath", //
374+
"getPathAndAfter", //
375+
"getQueryData", //
376+
"parseQueryData", //
377+
"removeFragment", //
378+
"removeParam", //
379+
"setParam", //
380+
"setParamsFromMap", //
381+
"setPath", //
382+
"split", //
383+
]
381384
)
382385
or
383386
// static methods in goog.string
384387
arg = 0 and
385388
exists(string name | invoke = Closure::moduleImport("goog.string." + name).getACall() |
386-
name = "urlDecode" or
387-
name = "urlEncode"
389+
name = ["urlDecode", "urlEncode"]
388390
)
389391
)
390392
}

javascript/ql/src/Expressions/StringInsteadOfRegex.ql

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ import javascript
1414
* Gets a regular expression pattern that matches the syntax of likely regular expressions.
1515
*/
1616
private string getALikelyRegExpPattern() {
17-
result = "/.*/[gimuy]{1,5}" or // pattern with at least one flag: /foo/i
18-
result = "/\\^.*/[gimuy]{0,5}" or // pattern with anchor: /^foo/
19-
result = "/.*\\$/[gimuy]{0,5}" or // pattern with anchor: /foo$/
20-
result = "\\^.*\\$" or // pattern body with anchors: ^foo$
21-
result = ".*(?<!\\\\)\\\\[dDwWsSB].*" or // contains a builtin character class: \s
22-
result = ".*(?<!\\\\)\\\\[\\[\\]()*+?{}|^$.].*" or // contains an escaped meta-character: \(
23-
result = ".*\\[\\^?[\\p{Alnum}\\p{Blank}_-]+\\][*+].*" // contains a quantified custom character class: [^a-zA-Z123]+
17+
result =
18+
[
19+
"/.*/[gimuy]{1,5}", // pattern with at least one flag: /foo/i
20+
"/\\^.*/[gimuy]{0,5}", // pattern with anchor: /^foo/
21+
"/.*\\$/[gimuy]{0,5}", // pattern with anchor: /foo$/
22+
"\\^.*\\$", // pattern body with anchors: ^foo$
23+
".*(?<!\\\\)\\\\[dDwWsSB].*", // contains a builtin character class: \s
24+
".*(?<!\\\\)\\\\[\\[\\]()*+?{}|^$.].*", // contains an escaped meta-character: \(
25+
".*\\[\\^?[\\p{Alnum}\\p{Blank}_-]+\\][*+].*" // contains a quantified custom character class: [^a-zA-Z123]+
26+
]
2427
}
2528

2629
/**

javascript/ql/src/experimental/Security/CWE-094/UntrustedCheckout.ql

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,11 @@ where
110110
ref.getWith().getStep() = step and
111111
step.getJob() = job and
112112
uses.getGitHubRepository() = "actions/checkout" and
113-
(
114-
ref.getValue().matches("%github.event.pull_request.head.ref%") or
115-
ref.getValue().matches("%github.event.pull_request.head.sha%") or
116-
ref.getValue().matches("%github.event.pull_request.number%") or
117-
ref.getValue().matches("%github.event.number%") or
118-
ref.getValue().matches("%github.head_ref%")
119-
) and
113+
ref.getValue()
114+
.matches([
115+
"%github.event.pull_request.head.ref%", "%github.event.pull_request.head.sha%",
116+
"%github.event.pull_request.number%", "%github.event.number%", "%github.head_ref%"
117+
]) and
120118
step instanceof ProbableStep and
121119
job instanceof ProbableJob
122120
select step, "Potential unsafe checkout of untrusted pull request on `pull_request_target`"

0 commit comments

Comments
 (0)