Skip to content

Commit 96b6f67

Browse files
committed
filter away paths that start with libary inputs and end with a fixed-property write
1 parent 7837189 commit 96b6f67

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,17 @@ class Configuration extends TaintTracking::Configuration {
7070
DataFlow::localFieldStep(pred, succ) and inlbl = outlbl
7171
}
7272

73-
// override to require that there is a path without unmatched return steps
7473
override predicate hasFlowPath(DataFlow::SourcePathNode source, DataFlow::SinkPathNode sink) {
7574
super.hasFlowPath(source, sink) and
76-
DataFlow::hasPathWithoutUnmatchedReturn(source, sink)
75+
// require that there is a path without unmatched return steps
76+
DataFlow::hasPathWithoutUnmatchedReturn(source, sink) and
77+
// filter away paths that start with library inputs and end with a write to a fixed property.
78+
not exists(ExternalInputSource src, Sink snk, DataFlow::PropWrite write |
79+
source.getNode() = src and sink.getNode() = snk
80+
|
81+
snk = write.getBase() and
82+
exists(write.getPropertyName())
83+
)
7784
}
7885

7986
override predicate isLabeledBarrier(DataFlow::Node node, DataFlow::FlowLabel lbl) {

javascript/ql/test/query-tests/Security/CWE-915/PrototypePollutingAssignment/PrototypePollutingAssignment.expected

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ nodes
7979
| lib.js:86:19:86:25 | path[0] |
8080
| lib.js:87:10:87:14 | proto |
8181
| lib.js:87:10:87:14 | proto |
82+
| lib.js:90:43:90:46 | path |
83+
| lib.js:90:43:90:46 | path |
84+
| lib.js:91:7:91:28 | maybeProto |
85+
| lib.js:91:20:91:28 | obj[path] |
86+
| lib.js:91:24:91:27 | path |
87+
| lib.js:92:3:92:12 | maybeProto |
88+
| lib.js:92:3:92:12 | maybeProto |
8289
| tst.js:5:9:5:38 | taint |
8390
| tst.js:5:17:5:38 | String( ... y.data) |
8491
| tst.js:5:24:5:37 | req.query.data |
@@ -192,6 +199,12 @@ edges
192199
| lib.js:86:15:86:26 | obj[path[0]] | lib.js:86:7:86:26 | proto |
193200
| lib.js:86:19:86:22 | path | lib.js:86:19:86:25 | path[0] |
194201
| lib.js:86:19:86:25 | path[0] | lib.js:86:15:86:26 | obj[path[0]] |
202+
| lib.js:90:43:90:46 | path | lib.js:91:24:91:27 | path |
203+
| lib.js:90:43:90:46 | path | lib.js:91:24:91:27 | path |
204+
| lib.js:91:7:91:28 | maybeProto | lib.js:92:3:92:12 | maybeProto |
205+
| lib.js:91:7:91:28 | maybeProto | lib.js:92:3:92:12 | maybeProto |
206+
| lib.js:91:20:91:28 | obj[path] | lib.js:91:7:91:28 | maybeProto |
207+
| lib.js:91:24:91:27 | path | lib.js:91:20:91:28 | obj[path] |
195208
| tst.js:5:9:5:38 | taint | tst.js:8:12:8:16 | taint |
196209
| tst.js:5:9:5:38 | taint | tst.js:9:12:9:16 | taint |
197210
| tst.js:5:9:5:38 | taint | tst.js:12:25:12:29 | taint |

javascript/ql/test/query-tests/Security/CWE-915/PrototypePollutingAssignment/lib.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,10 @@ module.exports.delete = function() {
8484
delete obj[path[0]]; // OK
8585
var prop = arguments[2];
8686
var proto = obj[path[0]];
87-
delete proto[prop]; // NOT
87+
delete proto[prop]; // NOT OK
8888
}
89+
90+
module.exports.fixedProp = function (obj, path, value) {
91+
var maybeProto = obj[path];
92+
maybeProto.foo = value; // OK - fixed properties from library inputs are OK.
93+
}

0 commit comments

Comments
 (0)