@@ -21,14 +21,28 @@ class DomGlobalVariable extends GlobalVariable {
21
21
/** DEPRECATED: Alias for DomGlobalVariable */
22
22
deprecated class DOMGlobalVariable = DomGlobalVariable ;
23
23
24
- /** Holds if `e` could hold a value that comes from the DOM. */
25
- predicate isDomValue ( Expr e ) { DOM:: domValueRef ( ) .flowsToExpr ( e ) }
24
+ /**
25
+ * DEPRECATED: Use `isDomNode` instead.
26
+ * Holds if `e` could hold a value that comes from the DOM.
27
+ */
28
+ deprecated predicate isDomValue ( Expr e ) { isDomNode ( e .flow ( ) ) }
29
+
30
+ /**
31
+ * Holds if `e` could hold a value that comes from the DOM.
32
+ */
33
+ predicate isDomNode ( DataFlow:: Node e ) { DOM:: domValueRef ( ) .flowsTo ( e ) }
34
+
35
+ /**
36
+ * DEPRECATED: Use `isLocationNode` instead.
37
+ * Holds if `e` could refer to the `location` property of a DOM node.
38
+ */
39
+ deprecated predicate isLocation ( Expr e ) { isLocationNode ( e .flow ( ) ) }
26
40
27
41
/** Holds if `e` could refer to the `location` property of a DOM node. */
28
- predicate isLocation ( Expr e ) {
29
- e = DOM:: domValueRef ( ) .getAPropertyReference ( "location" ) . asExpr ( )
42
+ predicate isLocationNode ( DataFlow :: Node e ) {
43
+ e = DOM:: domValueRef ( ) .getAPropertyReference ( "location" )
30
44
or
31
- e . accessesGlobal ( "location" )
45
+ e = DataFlow :: globalVarRef ( "location" )
32
46
}
33
47
34
48
/**
@@ -53,15 +67,52 @@ deprecated predicate isDocumentUrl(Expr e) { e.flow() = DOM::locationSource() }
53
67
deprecated predicate isDocumentURL = isDocumentUrl / 1 ;
54
68
55
69
/**
70
+ * DEPRECATED. In most cases, a sanitizer based on this predicate can be removed, as
71
+ * taint tracking no longer step through the properties of the location object by default.
72
+ *
73
+ * Holds if `pacc` accesses a part of `document.location` that is
74
+ * not considered user-controlled, that is, anything except
75
+ * `href`, `hash` and `search`.
76
+ */
77
+ deprecated predicate isSafeLocationProperty ( PropAccess pacc ) {
78
+ exists ( string prop | pacc = DOM:: locationRef ( ) .getAPropertyRead ( prop ) .asExpr ( ) |
79
+ prop != "href" and prop != "hash" and prop != "search"
80
+ )
81
+ }
82
+
83
+ /**
84
+ * DEPRECATED: Use `DomMethodCallNode` instead.
56
85
* A call to a DOM method.
57
86
*/
58
- class DomMethodCallExpr extends MethodCallExpr {
59
- DomMethodCallExpr ( ) { isDomValue ( this .getReceiver ( ) ) }
87
+ deprecated class DomMethodCallExpr extends MethodCallExpr {
88
+ DomMethodCallNode node ;
89
+
90
+ DomMethodCallExpr ( ) { this .flow ( ) = node }
91
+
92
+ /** Holds if `arg` is an argument that is interpreted as HTML. */
93
+ deprecated predicate interpretsArgumentsAsHtml ( Expr arg ) {
94
+ node .interpretsArgumentsAsHtml ( arg .flow ( ) )
95
+ }
96
+
97
+ /** Holds if `arg` is an argument that is used as an URL. */
98
+ deprecated predicate interpretsArgumentsAsURL ( Expr arg ) {
99
+ node .interpretsArgumentsAsURL ( arg .flow ( ) )
100
+ }
101
+
102
+ /** DEPRECATED: Alias for interpretsArgumentsAsHtml */
103
+ deprecated predicate interpretsArgumentsAsHTML ( Expr arg ) { this .interpretsArgumentsAsHtml ( arg ) }
104
+ }
105
+
106
+ /**
107
+ * A call to a DOM method.
108
+ */
109
+ class DomMethodCallNode extends DataFlow:: MethodCallNode {
110
+ DomMethodCallNode ( ) { isDomNode ( this .getReceiver ( ) ) }
60
111
61
112
/**
62
113
* Holds if `arg` is an argument that is interpreted as HTML.
63
114
*/
64
- predicate interpretsArgumentsAsHtml ( Expr arg ) {
115
+ predicate interpretsArgumentsAsHtml ( DataFlow :: Node arg ) {
65
116
exists ( int argPos , string name |
66
117
arg = this .getArgument ( argPos ) and
67
118
name = this .getMethodName ( )
@@ -86,7 +137,7 @@ class DomMethodCallExpr extends MethodCallExpr {
86
137
/**
87
138
* Holds if `arg` is an argument that is used as an URL.
88
139
*/
89
- predicate interpretsArgumentsAsUrl ( Expr arg ) {
140
+ predicate interpretsArgumentsAsUrl ( DataFlow :: Node arg ) {
90
141
exists ( int argPos , string name |
91
142
arg = this .getArgument ( argPos ) and
92
143
name = this .getMethodName ( )
@@ -104,40 +155,60 @@ class DomMethodCallExpr extends MethodCallExpr {
104
155
}
105
156
106
157
/** DEPRECATED: Alias for interpretsArgumentsAsUrl */
107
- deprecated predicate interpretsArgumentsAsURL ( Expr arg ) { this .interpretsArgumentsAsUrl ( arg ) }
158
+ deprecated predicate interpretsArgumentsAsURL ( DataFlow :: Node arg ) { this .interpretsArgumentsAsUrl ( arg ) }
108
159
109
160
/** DEPRECATED: Alias for interpretsArgumentsAsHtml */
110
- deprecated predicate interpretsArgumentsAsHTML ( Expr arg ) { this .interpretsArgumentsAsHtml ( arg ) }
161
+ deprecated predicate interpretsArgumentsAsHTML ( DataFlow :: Node arg ) { this .interpretsArgumentsAsHtml ( arg ) }
111
162
}
112
163
113
164
/**
165
+ * DEPRECATED: Use `DomPropertyWrite` instead.
114
166
* An assignment to a property of a DOM object.
115
167
*/
116
- class DomPropWriteNode extends Assignment {
117
- PropAccess lhs ;
168
+ deprecated class DomPropWriteNode extends Assignment {
169
+ DomPropertyWrite node ;
118
170
119
- DomPropWriteNode ( ) {
120
- lhs = this .getLhs ( ) and
121
- isDomValue ( lhs .getBase ( ) )
122
- }
171
+ DomPropWriteNode ( ) { this .flow ( ) = node }
123
172
124
173
/**
125
174
* Holds if the assigned value is interpreted as HTML.
126
175
*/
127
- predicate interpretsValueAsHtml ( ) {
128
- lhs .getPropertyName ( ) = "innerHTML" or
129
- lhs .getPropertyName ( ) = "outerHTML"
130
- }
176
+ predicate interpretsValueAsHtml ( ) { node .interpretsValueAsHtml ( ) }
131
177
132
178
/** DEPRECATED: Alias for interpretsValueAsHtml */
133
179
deprecated predicate interpretsValueAsHTML ( ) { this .interpretsValueAsHtml ( ) }
134
180
181
+ /**
182
+ * Holds if the assigned value is interpreted as JavaScript via javascript: protocol.
183
+ */
184
+ predicate interpretsValueAsJavaScriptUrl ( ) { node .interpretsValueAsJavaScriptUrl ( ) }
185
+ }
186
+
187
+ /**
188
+ * An assignment to a property of a DOM object.
189
+ */
190
+ class DomPropertyWrite extends DataFlow:: Node instanceof DataFlow:: PropWrite {
191
+ DomPropertyWrite ( ) { isDomNode ( super .getBase ( ) ) }
192
+
193
+ /**
194
+ * Holds if the assigned value is interpreted as HTML.
195
+ */
196
+ predicate interpretsValueAsHtml ( ) {
197
+ super .getPropertyName ( ) = "innerHTML" or
198
+ super .getPropertyName ( ) = "outerHTML"
199
+ }
200
+
135
201
/**
136
202
* Holds if the assigned value is interpreted as JavaScript via javascript: protocol.
137
203
*/
138
204
predicate interpretsValueAsJavaScriptUrl ( ) {
139
- lhs .getPropertyName ( ) = DOM:: getAPropertyNameInterpretedAsJavaScriptUrl ( )
205
+ super .getPropertyName ( ) = DOM:: getAPropertyNameInterpretedAsJavaScriptUrl ( )
140
206
}
207
+
208
+ /**
209
+ * Gets the data flow node corresponding to the value being written,
210
+ */
211
+ DataFlow:: Node getRhs ( ) { result = super .getRhs ( ) }
141
212
}
142
213
143
214
/**
0 commit comments