-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathStrictModeCallStackIntrospection.ql
37 lines (34 loc) · 1.37 KB
/
StrictModeCallStackIntrospection.ql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* @name Use of call stack introspection in strict mode
* @description Accessing properties 'arguments.caller', 'arguments.callee',
* 'Function.prototype.caller' or 'Function.prototype.arguments'
* in strict mode will cause a runtime error.
* @kind problem
* @problem.severity error
* @id js/strict-mode-call-stack-introspection
* @tags correctness
* language-features
* @precision high
*/
import javascript
/**
* Holds if it is illegal to access property `prop` on `baseVal` in strict-mode
* code; `baseDesc` is a description of `baseVal` used in the alert message.
*/
predicate illegalPropAccess(AbstractValue baseVal, string baseDesc, string prop) {
baseVal instanceof AbstractArguments and
baseDesc = "arguments" and
(prop = "caller" or prop = "callee")
or
baseVal instanceof AbstractFunction and
baseDesc = "Function.prototype" and
(prop = "caller" or prop = "arguments")
}
from PropAccess acc, DataFlow::AnalyzedNode baseNode, string base, string prop
where
acc.accesses(baseNode.asExpr(), prop) and
acc.getContainer().isStrict() and
illegalPropAccess(baseNode.getAValue(), base, prop) and
forex(AbstractValue av | av = baseNode.getAValue() | illegalPropAccess(av, _, prop)) and
not acc = any(ExprStmt stmt).getExpr() // reported by js/useless-expression
select acc, "Strict mode code cannot use " + base + "." + prop + "."