Skip to content

Commit a3e56de

Browse files
committed
JS: Factor out StringOps::substringMethodName
1 parent 1074d40 commit a3e56de

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

javascript/ql/src/semmle/javascript/StringOps.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,4 +802,11 @@ module StringOps {
802802
override boolean getPolarity() { result = polarity }
803803
}
804804
}
805+
806+
/**
807+
* Gets the name of a string method which performs substring extraction.
808+
*
809+
* These are `substring`, `substr`, and `slice`.
810+
*/
811+
string substringMethodName() { result = ["substring", "substr", "slice"] }
805812
}

javascript/ql/src/semmle/javascript/security/TaintedUrlSuffix.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module TaintedUrlSuffix {
6767
name = call.getMethodName()
6868
|
6969
// Substring that is not a prefix
70-
name = ["substring", "substr", "slice"] and
70+
name = StringOps::substringMethodName() and
7171
not call.getArgument(0).getIntValue() = 0
7272
or
7373
// Split around '#' or '?' and extract the suffix

javascript/ql/src/semmle/javascript/security/dataflow/ClientSideUrlRedirectCustomizations.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module ClientSideUrlRedirect {
6969
// exclude all splits where only the prefix is accessed, which is safe for url-redirects.
7070
not exists(PropAccess pacc | mce = pacc.getBase() | pacc.getPropertyName() = "0")
7171
or
72-
(methodName = "substring" or methodName = "substr" or methodName = "slice") and
72+
methodName = StringOps::substringMethodName() and
7373
// exclude `location.href.substring(0, ...)` and similar, which can
7474
// never refer to the query string
7575
not mce.getArgument(0).(NumberLiteral).getIntValue() = 0

javascript/ql/src/semmle/javascript/security/dataflow/TaintedPathCustomizations.qll

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -734,15 +734,9 @@ module TaintedPath {
734734
exists(DataFlow::MethodCallNode mcn, string name |
735735
srclabel = dstlabel and dst = mcn and mcn.calls(src, name)
736736
|
737-
exists(string substringMethodName |
738-
substringMethodName = "substr" or
739-
substringMethodName = "substring" or
740-
substringMethodName = "slice"
741-
|
742-
name = substringMethodName and
743-
// to avoid very dynamic transformations, require at least one fixed index
744-
exists(mcn.getAnArgument().asExpr().getIntValue())
745-
)
737+
name = StringOps::substringMethodName() and
738+
// to avoid very dynamic transformations, require at least one fixed index
739+
exists(mcn.getAnArgument().asExpr().getIntValue())
746740
or
747741
exists(string argumentlessMethodName |
748742
argumentlessMethodName = "toLocaleLowerCase" or

javascript/ql/src/semmle/javascript/security/performance/PolynomialReDoSCustomizations.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ module PolynomialReDoS {
100100
root instanceof RegExpCharacterClassEscape
101101
)
102102
or
103-
exists(string name | name = "slice" or name = "substring" or name = "substr" |
104-
this.(DataFlow::MethodCallNode).getMethodName() = name
105-
)
103+
this.(DataFlow::MethodCallNode).getMethodName() = StringOps::substringMethodName()
106104
}
107105
}
108106

0 commit comments

Comments
 (0)