Skip to content

Commit c7fc1ef

Browse files
committed
split localFieldStep into a load/store step for the DataFlow step
1 parent 5339f21 commit c7fc1ef

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

javascript/ql/lib/semmle/javascript/dataflow/DataFlow.qll

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,20 +1591,41 @@ module DataFlow {
15911591
*/
15921592
predicate localFieldStep(DataFlow::Node pred, DataFlow::Node succ) {
15931593
exists(ClassNode cls, string prop |
1594+
localFieldStoreStep(cls, pred, _, prop) and
1595+
localFieldLoadStep(cls, _, succ, prop)
1596+
)
1597+
}
1598+
1599+
private predicate localFieldStoreStep(
1600+
ClassNode cls, DataFlow::Node pred, DataFlow::Node succ, string prop
1601+
) {
1602+
(
15941603
pred = cls.getADirectSuperClass*().getAReceiverNode().getAPropertyWrite(prop).getRhs()
15951604
or
15961605
// add support for writes on nested properties
15971606
pred = cls.getADirectSuperClass*().getAReceiverNode().getAPropertyRead(prop) and
15981607
pred = any(DataFlow::PropRef ref).getBase()
15991608
or
16001609
pred = cls.getInstanceMethod(prop)
1601-
|
1602-
succ = cls.getAReceiverNode().getAPropertyRead(prop)
1603-
)
1610+
) and
1611+
succ = cls.getConstructor().getReceiver()
1612+
}
1613+
1614+
private predicate localFieldLoadStep(
1615+
ClassNode cls, DataFlow::Node pred, DataFlow::Node succ, string prop
1616+
) {
1617+
pred = cls.getConstructor().getReceiver() and
1618+
succ = cls.getAReceiverNode().getAPropertyRead(prop)
16041619
}
16051620

16061621
private class LocalFieldStep extends DataFlow::SharedFlowStep {
1607-
override predicate step(DataFlow::Node pred, DataFlow::Node succ) { localFieldStep(pred, succ) }
1622+
override predicate loadStep(DataFlow::Node pred, DataFlow::Node succ, string prop) {
1623+
localFieldLoadStep(_, pred, succ, prop)
1624+
}
1625+
1626+
override predicate storeStep(DataFlow::Node pred, DataFlow::SourceNode succ, string prop) {
1627+
localFieldStoreStep(_, pred, succ, prop)
1628+
}
16081629
}
16091630

16101631
predicate argumentPassingStep = FlowSteps::argumentPassing/4;

javascript/ql/lib/semmle/javascript/security/dataflow/UnsafeHtmlConstructionQuery.qll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,4 @@ class Configration extends TaintTracking::Configuration {
3535
super.hasFlowPath(source, sink) and
3636
DataFlow::hasPathWithoutUnmatchedReturn(source, sink)
3737
}
38-
39-
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
40-
DataFlow::localFieldStep(pred, succ)
41-
}
4238
}

javascript/ql/lib/semmle/javascript/security/dataflow/UnsafeJQueryPluginQuery.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ class Configuration extends TaintTracking::Configuration {
2626
}
2727

2828
override predicate isAdditionalTaintStep(DataFlow::Node src, DataFlow::Node sink) {
29-
// jQuery plugins tend to be implemented as classes that store data in fields initialized by the constructor.
30-
DataFlow::localFieldStep(src, sink) or
3129
aliasPropertyPresenceStep(src, sink)
3230
}
3331

javascript/ql/lib/semmle/javascript/security/dataflow/UnsafeShellCommandConstructionQuery.qll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,4 @@ class Configuration extends TaintTracking::Configuration {
3232
super.hasFlowPath(source, sink) and
3333
DataFlow::hasPathWithoutUnmatchedReturn(source, sink)
3434
}
35-
36-
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
37-
DataFlow::localFieldStep(pred, succ)
38-
}
3935
}

javascript/ql/src/Security/CWE-094/CodeInjection.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import javascript
1717
import semmle.javascript.security.dataflow.CodeInjectionQuery
1818
import DataFlow::PathGraph
19+
import semmle.javascript.heuristics.AdditionalSources
1920

2021
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
2122
where cfg.hasFlowPath(source, sink)

0 commit comments

Comments
 (0)