Skip to content

Commit d7ad625

Browse files
committed
JS: restrict type tracking to strings of interest.
1 parent da5cd25 commit d7ad625

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

javascript/ql/src/LanguageFeatures/TemplateSyntaxInStringLiteral.ql

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,26 @@ VarDecl getDeclIn(Variable v, Scope scope, string name, CandidateTopLevel tl) {
9797
/**
9898
* Tracks data flow from a string literal that may flow to a replace operation.
9999
*/
100-
DataFlow::SourceNode trackString(CandidateStringLiteral lit, DataFlow::TypeTracker t) {
101-
t.start() and result = lit.flow()
100+
DataFlow::SourceNode trackStringWithTemplateSyntax(
101+
CandidateStringLiteral lit, DataFlow::TypeTracker t
102+
) {
103+
t.start() and result = lit.flow() and exists(lit.getAReferencedVariable())
102104
or
103-
exists(DataFlow::TypeTracker t2 | result = trackString(lit, t2).track(t2, t))
105+
exists(DataFlow::TypeTracker t2 | result = trackStringWithTemplateSyntax(lit, t2).track(t2, t))
104106
}
105107

106108
/**
107109
* Gets a string literal that flows to a replace operation.
108110
*/
109-
DataFlow::SourceNode trackString(CandidateStringLiteral lit) {
110-
result = trackString(lit, DataFlow::TypeTracker::end())
111+
DataFlow::SourceNode trackStringWithTemplateSyntax(CandidateStringLiteral lit) {
112+
result = trackStringWithTemplateSyntax(lit, DataFlow::TypeTracker::end())
111113
}
112114

113115
/**
114116
* Holds if the string literal flows to a replace method call.
115117
*/
116118
predicate hasReplaceMethodCall(CandidateStringLiteral lit) {
117-
trackString(lit).getAMethodCall() instanceof StringReplaceCall
119+
trackStringWithTemplateSyntax(lit).getAMethodCall() instanceof StringReplaceCall
118120
}
119121

120122
from CandidateStringLiteral lit, Variable v, Scope s, string name, VarDecl decl

0 commit comments

Comments
 (0)