Skip to content

Commit 3b11958

Browse files
committed
JS: Expand D3 model a bit
1 parent 773cf0d commit 3b11958

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

javascript/ql/src/semmle/javascript/frameworks/D3.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ module D3 {
99
API::Node d3() {
1010
result = API::moduleImport("d3")
1111
or
12+
// recognize copies of d3 in a scope
13+
result = API::moduleImport(any(string s | s.regexpMatch("@.*/d3(-\\w+)?")))
14+
or
1215
result = API::moduleImport("d3-node").getInstance().getMember("d3")
1316
}
1417

@@ -44,6 +47,10 @@ module D3 {
4447
or
4548
name = ["attr", "classed", "style", "property", "on"] and
4649
call.getNumArgument() > 1 // exclude 1-argument version, which returns the current value
50+
or
51+
// Setting multiple things at once
52+
name = ["attr", "classed", "style", "property", "on"] and
53+
call.getArgument(0).getALocalSource() instanceof DataFlow::ObjectLiteralNode
4754
)
4855
or
4956
result = d3Selection().getMember("call").getParameter(0).getParameter(0)

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,20 @@ module XssThroughDom {
6161
*/
6262
class D3TextSource extends Source {
6363
D3TextSource() {
64-
exists(DataFlow::MethodCallNode call, string methodName, string argValue |
64+
exists(DataFlow::MethodCallNode call, string methodName |
6565
this = call and
66-
call = D3::d3Selection().getMember(methodName).getACall() and
66+
call = D3::d3Selection().getMember(methodName).getACall()
67+
|
68+
methodName = "attr" and
6769
call.getNumArgument() = 1 and
68-
call.getArgument(0).mayHaveStringValue(argValue)
69-
|
70-
methodName = "attr" and argValue = unsafeAttributeName()
70+
call.getArgument(0).mayHaveStringValue(unsafeAttributeName())
71+
or
72+
methodName = "property" and
73+
call.getNumArgument() = 1 and
74+
call.getArgument(0).mayHaveStringValue(unsafeDomPropertyName())
7175
or
72-
methodName = "property" and argValue = unsafeDomPropertyName()
76+
methodName = "text" and
77+
call.getNumArgument() = 0
7378
)
7479
}
7580
}

0 commit comments

Comments
 (0)