Skip to content

Commit 922a07d

Browse files
Napalysasgerf
andcommitted
Added underscore.string clearsContent.
Co-authored-by: Asgerf <[email protected]>
1 parent 8b431dc commit 922a07d

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

javascript/ql/lib/javascript.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,4 @@ import semmle.javascript.linters.ESLint
143143
import semmle.javascript.linters.JSLint
144144
import semmle.javascript.linters.Linting
145145
import semmle.javascript.security.dataflow.RemoteFlowSources
146+
import semmle.javascript.frameworks.UnderscoreDotString
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Provides classes for modeling data flow behavior of the Underscore.string library (https://www.npmjs.com/package/underscore.string).
3+
*/
4+
5+
private import javascript
6+
private import semmle.javascript.dataflow.internal.AdditionalFlowInternal
7+
8+
/**
9+
* Models data flow for the Underscore.string library.
10+
*/
11+
private class UnderscoreDotString extends AdditionalFlowInternal {
12+
/**
13+
* Holds if a call to an Underscore.string method clears array element content of the receiver.
14+
*/
15+
override predicate clearsContent(DataFlow::Node node, DataFlow::ContentSet contents) {
16+
exists(DataFlow::CallNode call |
17+
call =
18+
ModelOutput::getATypeNode(["'underscore.string'.Wrapper", "'underscore.string'"])
19+
.getAMember()
20+
.getACall() and
21+
node = call.getReceiver().getPostUpdateNode() and
22+
contents = DataFlow::ContentSet::arrayElement()
23+
)
24+
}
25+
}

javascript/ql/test/library-tests/TripleDot/underscore.string.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function strToStr() {
1111
sink(s.unescapeHTML(source("s8"))); // $ hasTaintFlow=s8
1212
sink(s.wrap(source("s9"), {})); // $ hasTaintFlow=s9
1313
sink(s.dedent(source("s10"), " ")); // $ hasTaintFlow=s10
14-
sink(s.reverse(source("s11"))); // $ hasTaintFlow=s11 SPURIOUS: hasTaintFlow=s8
14+
sink(s.reverse(source("s11"))); // $ hasTaintFlow=s11
1515
sink(s.pred(source("s12"))); // $ hasTaintFlow=s12
1616
sink(s.succ(source("s13"))); // $ hasTaintFlow=s13
1717
sink(s.titleize(source("s14"))); // $ hasTaintFlow=s14
@@ -60,7 +60,7 @@ function multiSource() {
6060
sink(s.join(",", source("s5"), "str")); // $ hasTaintFlow=s5
6161
sink(s.join(",", "str", source("s6"))); // $ hasTaintFlow=s6
6262

63-
sink(s.splice(source("s7"), 1, 2, "str")); // $ hasTaintFlow=s7 SPURIOUS: hasTaintFlow=s8
63+
sink(s.splice(source("s7"), 1, 2, "str")); // $ hasTaintFlow=s7
6464
sink(s.splice("str", 1, 2, source("s8"))); // $ hasTaintFlow=s8
6565

6666
sink(s.prune(source("s9"), 1, "additional")); // $ hasTaintFlow=s9

0 commit comments

Comments
 (0)