Skip to content

Commit a0b5aa5

Browse files
committed
more precise heuristic to identify allowed call targets
1 parent 15d74b7 commit a0b5aa5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

javascript/ql/src/semmle/javascript/Regexp.qll

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,16 @@ class RegExpParseError extends Error, @regexp_parse_error {
798798
override string toString() { result = getMessage() }
799799
}
800800

801+
/**
802+
* Holds if `func` is a method defined on `String.prototype` with name `name`.
803+
*/
804+
private predicate isNativeStringMethod(Function func, string name) {
805+
exists(ExternalInstanceMemberDecl decl |
806+
decl.hasQualifiedName("String", name) and
807+
func = decl.getInit()
808+
)
809+
}
810+
801811
/**
802812
* Holds if `source` may be interpreted as a regular expression.
803813
*/
@@ -811,7 +821,11 @@ predicate isInterpretedAsRegExp(DataFlow::Node source) {
811821
exists(MethodCallExpr mce, string methodName |
812822
mce.getReceiver().analyze().getAType() = TTString() and
813823
mce.getMethodName() = methodName and
814-
not exists(DataFlow::FunctionNode func | func = DataFlow::valueNode(mce.getCallee()).getAFunctionValue() | not func.getFunction().inExternsFile())
824+
not exists(Function func |
825+
func = any(DataFlow::MethodCallNode call | call.getEnclosingExpr() = mce).getACallee()
826+
|
827+
not isNativeStringMethod(func, methodName)
828+
)
815829
|
816830
methodName = "match" and source.asExpr() = mce.getArgument(0) and mce.getNumArgument() = 1
817831
or

0 commit comments

Comments
 (0)