Skip to content

Commit 4f6e5c9

Browse files
committed
filter out writes to number indexes
1 parent 96b6f67 commit 4f6e5c9

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,15 @@ class Configuration extends TaintTracking::Configuration {
7979
source.getNode() = src and sink.getNode() = snk
8080
|
8181
snk = write.getBase() and
82-
exists(write.getPropertyName())
82+
(
83+
// fixed property name
84+
exists(write.getPropertyName())
85+
or
86+
// non-string property name (likely number)
87+
exists(Expr prop | prop = write.getPropertyNameExpr() |
88+
not prop.analyze().getAType() = TTString()
89+
)
90+
)
8391
)
8492
}
8593

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ nodes
8686
| lib.js:91:24:91:27 | path |
8787
| lib.js:92:3:92:12 | maybeProto |
8888
| lib.js:92:3:92:12 | maybeProto |
89+
| lib.js:95:3:95:12 | maybeProto |
90+
| lib.js:95:3:95:12 | maybeProto |
8991
| tst.js:5:9:5:38 | taint |
9092
| tst.js:5:17:5:38 | String( ... y.data) |
9193
| tst.js:5:24:5:37 | req.query.data |
@@ -203,6 +205,8 @@ edges
203205
| lib.js:90:43:90:46 | path | lib.js:91:24:91:27 | path |
204206
| lib.js:91:7:91:28 | maybeProto | lib.js:92:3:92:12 | maybeProto |
205207
| lib.js:91:7:91:28 | maybeProto | lib.js:92:3:92:12 | maybeProto |
208+
| lib.js:91:7:91:28 | maybeProto | lib.js:95:3:95:12 | maybeProto |
209+
| lib.js:91:7:91:28 | maybeProto | lib.js:95:3:95:12 | maybeProto |
206210
| lib.js:91:20:91:28 | obj[path] | lib.js:91:7:91:28 | maybeProto |
207211
| lib.js:91:24:91:27 | path | lib.js:91:20:91:28 | obj[path] |
208212
| tst.js:5:9:5:38 | taint | tst.js:8:12:8:16 | taint |

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,7 @@ module.exports.delete = function() {
9090
module.exports.fixedProp = function (obj, path, value) {
9191
var maybeProto = obj[path];
9292
maybeProto.foo = value; // OK - fixed properties from library inputs are OK.
93+
94+
var i = 0;
95+
maybeProto[i + 2] = value; // OK - number properties are OK.
9396
}

0 commit comments

Comments
 (0)