Skip to content

Commit 92acd32

Browse files
authored
Merge pull request #1218 from esben-semmle/js/whitelist-typeconfusion-lt1-checks
Approved by asger-semmle
2 parents f54366b + 52d8647 commit 92acd32

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

change-notes/1.21/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
| Incomplete string escaping or encoding | More results | This rule now considers the flow of regular expressions literals. |
3030
| Replacement of a substring with itself | More results | This rule now considers the flow of regular expressions literals. |
3131
| Server-side URL redirect | Fewer false-positive results | This rule now treats URLs as safe in more cases where the hostname cannot be tampered with. |
32+
| Type confusion through parameter tampering | Fewer false-positive results | This rule now recognizes additional emptiness checks. |
3233
| Useless assignment to property | Fewer false-positive results | This rule now ignore reads of additional getters. |
3334

3435
## Changes to QL libraries

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,25 @@ module TypeConfusionThroughParameterTampering {
8383
LengthAccess() {
8484
exists(DataFlow::PropRead read |
8585
read.accesses(this, "length") and
86-
// exclude truthiness checks on the length: an array/string confusion cannot control an emptiness check
86+
// an array/string confusion cannot control an emptiness check
8787
not (
88+
// `if (x.length) {...}`
8889
exists(ConditionGuardNode cond | read.asExpr() = cond.getTest())
8990
or
91+
// `x.length == 0`, `x.length > 0`
9092
exists(Comparison cmp, Expr zero |
9193
zero.getIntValue() = 0 and
9294
cmp.hasOperands(read.asExpr(), zero)
9395
)
9496
or
97+
// `x.length < 1`
98+
exists(RelationalComparison cmp |
99+
cmp.getLesserOperand() = read.asExpr() and
100+
cmp.getGreaterOperand().getIntValue() = 1 and
101+
not cmp.isInclusive()
102+
)
103+
or
104+
// `!x.length`
95105
exists(LogNotExpr neg | neg.getOperand() = read.asExpr())
96106
)
97107
)

javascript/ql/test/query-tests/Security/CWE-843/tst.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,6 @@ express().get('/some/path/:foo', function(req, res) {
6868
while (p.length) { // OK
6969
p = p.substr(1);
7070
}
71+
72+
p.length < 1; // OK
7173
});

0 commit comments

Comments
 (0)