File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed
src/semmle/javascript/frameworks
test/library-tests/TaintTracking Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -194,6 +194,38 @@ module XML {
194
194
}
195
195
}
196
196
197
+ /**
198
+ * An invocation of `sax`.
199
+ */
200
+ private class SaxInvocation extends XML:: ParserInvocation {
201
+ js:: DataFlow:: InvokeNode parser ;
202
+
203
+ SaxInvocation ( ) {
204
+ exists ( js:: API:: Node imp | imp = js:: API:: moduleImport ( "sax" ) |
205
+ parser = imp .getMember ( "parser" ) .getACall ( )
206
+ or
207
+ parser = imp .getMember ( "SAXParser" ) .getAnInstantiation ( )
208
+ ) and
209
+ this = parser .getAMemberCall ( "write" ) .asExpr ( )
210
+ }
211
+
212
+ override js:: Expr getSourceArgument ( ) { result = getArgument ( 0 ) }
213
+
214
+ override predicate resolvesEntities ( XML:: EntityKind kind ) {
215
+ // sax-js does not expand entities.
216
+ none ( )
217
+ }
218
+
219
+ override js:: DataFlow:: Node getAResult ( ) {
220
+ result =
221
+ parser
222
+ .getAPropertyWrite ( any ( string s | s .matches ( "on%" ) ) )
223
+ .getRhs ( )
224
+ .getAFunctionValue ( )
225
+ .getAParameter ( )
226
+ }
227
+ }
228
+
197
229
private class XMLParserTaintStep extends js:: TaintTracking:: AdditionalTaintStep {
198
230
XML:: ParserInvocation parser ;
199
231
Original file line number Diff line number Diff line change @@ -147,3 +147,4 @@ typeInferenceMismatch
147
147
| tst.js:2:13:2:20 | source() | tst.js:48:10:48:22 | new Buffer(x) |
148
148
| xml.js:5:18:5:25 | source() | xml.js:8:14:8:17 | text |
149
149
| xml.js:12:17:12:24 | source() | xml.js:13:14:13:19 | result |
150
+ | xml.js:23:18:23:25 | source() | xml.js:20:14:20:17 | attr |
Original file line number Diff line number Diff line change 12
12
parseString ( source ( ) , function ( err , result ) {
13
13
sink ( result ) ; // NOT OK
14
14
} ) ;
15
+
16
+ var sax = require ( "sax" ) ;
17
+ var parser = sax . parser ( strict ) ;
18
+
19
+ parser . onattribute = function ( attr ) {
20
+ sink ( attr ) ; // NOT OK
21
+ } ;
22
+
23
+ parser . write ( source ( ) ) . close ( ) ;
24
+
15
25
} ) ( ) ;
You can’t perform that action at this time.
0 commit comments