Skip to content

Commit 3c4749b

Browse files
authored
Merge pull request #2624 from asger-semmle/js-duplicate-alert-strict-mode
Approved by max-schaefer
2 parents 5a4be67 + 73e60a7 commit 3c4749b

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

change-notes/1.24/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
| Incomplete string escaping or encoding (`js/incomplete-sanitization`) | Fewer false positive results | This query now recognizes additional cases where a single replacement is likely to be intentional. |
3232
| Unbound event handler receiver (`js/unbound-event-handler-receiver`) | Fewer false positive results | This query now recognizes additional ways event handler receivers can be bound. |
3333
| Expression has no effect (`js/useless-expression`) | Fewer false positive results | The query now recognizes block-level flow type annotations. |
34+
| Use of call stack introspection in strict mode (`js/strict-mode-call-stack-introspection`) | Fewer false positive results | The query no longer flags expression statements. |
3435

3536
## Changes to libraries
3637

javascript/ql/src/LanguageFeatures/StrictModeCallStackIntrospection.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ where
3232
acc.accesses(baseNode.asExpr(), prop) and
3333
acc.getContainer().isStrict() and
3434
illegalPropAccess(baseNode.getAValue(), base, prop) and
35-
forex(AbstractValue av | av = baseNode.getAValue() | illegalPropAccess(av, _, prop))
35+
forex(AbstractValue av | av = baseNode.getAValue() | illegalPropAccess(av, _, prop)) and
36+
not acc = any(ExprStmt stmt).getExpr() // reported by js/useless-expression
3637
select acc, "Strict mode code cannot use " + base + "." + prop + "."
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
| tst.js:5:30:5:45 | arguments.callee | Strict mode code cannot use arguments.callee. |
22
| tst.js:7:21:7:36 | arguments.callee | Strict mode code cannot use arguments.callee. |
33
| tst.js:9:20:9:27 | f.caller | Strict mode code cannot use Function.prototype.caller. |
4-
| tst.js:11:8:11:18 | f.arguments | Strict mode code cannot use Function.prototype.arguments. |
5-
| tst.js:18:3:18:18 | arguments.callee | Strict mode code cannot use arguments.callee. |
6-
| tst.js:31:5:31:14 | foo.caller | Strict mode code cannot use Function.prototype.caller. |
7-
| tst.js:31:5:31:14 | foo.caller | Strict mode code cannot use arguments.caller. |
4+
| tst.js:11:17:11:27 | f.arguments | Strict mode code cannot use Function.prototype.arguments. |
5+
| tst.js:18:10:18:25 | arguments.callee | Strict mode code cannot use arguments.callee. |
6+
| tst.js:31:12:31:21 | foo.caller | Strict mode code cannot use Function.prototype.caller. |
7+
| tst.js:31:12:31:21 | foo.caller | Strict mode code cannot use arguments.caller. |

javascript/ql/test/query-tests/LanguageFeatures/StrictModeCallStackIntrospection/tst.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ var o = {
88
// BAD
99
console.log(f.caller);
1010
// BAD
11-
f.arguments;
11+
this.y = f.arguments;
1212
this.x = x;
1313
}
1414
};
1515

1616
var D = class extends function() {
1717
// BAD
18-
arguments.callee;
18+
return arguments.callee;
1919
} {};
2020

2121
function g() {
@@ -28,6 +28,11 @@ function g() {
2828
function h() {
2929
var foo = Math.random() > 0.5 ? h : arguments;
3030
// BAD
31-
foo.caller;
31+
return foo.caller;
3232
}
33-
})();
33+
})();
34+
35+
(function() {
36+
'use strict';
37+
arguments.caller; // OK - avoid duplicate alert from useless-expression
38+
})();

0 commit comments

Comments
 (0)