forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomValues.ql
More file actions
68 lines (49 loc) · 2.06 KB
/
customValues.ql
File metadata and controls
68 lines (49 loc) · 2.06 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import javascript
private import semmle.javascript.dataflow.InferredTypes
/**
* A custom abstract value representing the DOM object `document`.
*/
class Document extends CustomAbstractValueTag {
Document() { this = "document" }
override boolean getBooleanValue() { result = true }
override InferredType getType() { result = TTObject() }
override predicate isCoercibleToNumber() { none() }
override PrimitiveAbstractValue toPrimitive() { result.getType() = TTString() }
override string describe() { result = "document" }
}
/**
* A custom abstract value representing the DOM object `document.all`,
* which is falsy.
*
* Note that `getType()` isn't quite right, since `typeof document.all === 'undefined'`,
* but that's fine for the purposes of this test.
*/
class DocumentAll extends CustomAbstractValueTag {
DocumentAll() { this = "document.all" }
override boolean getBooleanValue() { result = false }
override InferredType getType() { result = TTObject() }
override predicate isCoercibleToNumber() { none() }
override PrimitiveAbstractValue toPrimitive() { result.getType() = TTString() }
override string describe() { result = "document.all" }
}
class DocumentRef extends DataFlow::AnalyzedNode, DataFlow::ValueNode {
override GlobalVarAccess astNode;
DocumentRef() { astNode.getName() = "document" }
override AbstractValue getALocalValue() {
result = DataFlow::AnalyzedNode.super.getALocalValue() or
result.(CustomAbstractValue).getTag() instanceof Document
}
}
class DocumentAllRef extends DataFlow::AnalyzedNode, DataFlow::ValueNode {
override PropAccess astNode;
DocumentAllRef() { astNode.getPropertyName() = "all" }
override AbstractValue getAValue() {
result = DataFlow::AnalyzedNode.super.getAValue()
or
astNode.getBase().analyze().getALocalValue().(CustomAbstractValue).getTag() instanceof Document and
result.(CustomAbstractValue).getTag() instanceof DocumentAll
}
}
from VariableDeclarator vd, DataFlow::AnalyzedNode init
where init = vd.getInit().analyze()
select vd.getBindingPattern(), init, init.getAValue()