@@ -216,11 +216,18 @@ describe('HTML', function() {
216
216
expectHTML ( false ) . toBe ( 'false' ) ;
217
217
} ) ;
218
218
219
+
219
220
it ( 'should strip svg elements if not enabled via provider' , function ( ) {
220
221
expectHTML ( '<svg width="400px" height="150px" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red"></svg>' )
221
222
. toEqual ( '' ) ;
222
223
} ) ;
223
224
225
+ if ( / C h r o m e / . test ( window . navigator . userAgent ) ) {
226
+ it ( 'should prevent mXSS attacks' , function ( ) {
227
+ expectHTML ( '<a href=" javascript:alert(1)">CLICKME</a>' ) . toBe ( '<a>CLICKME</a>' ) ;
228
+ } ) ;
229
+ }
230
+
224
231
225
232
describe ( 'SVG support' , function ( ) {
226
233
@@ -238,38 +245,47 @@ describe('HTML', function() {
238
245
239
246
it ( 'should not ignore white-listed svg camelCased attributes' , function ( ) {
240
247
expectHTML ( '<svg preserveAspectRatio="true"></svg>' )
241
- . toEqual ( '<svg preserveAspectRatio="true"></svg>' ) ;
248
+ . toBeOneOf ( '<svg preserveAspectRatio="true"></svg>' ,
249
+ '<svg preserveAspectRatio="true" xmlns="http://www.w3.org/2000/svg"></svg>' ) ;
242
250
243
251
} ) ;
244
252
245
253
it ( 'should sanitize SVG xlink:href attribute values' , function ( ) {
246
254
expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:href="javascript:alert()"></a></svg>' )
247
255
. toBeOneOf ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ,
248
- '<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><a></a></svg>' ) ;
256
+ '<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><a></a></svg>' ,
257
+ '<svg xmlns="http://www.w3.org/2000/svg"><a xmlns:xlink="http://www.w3.org/1999/xlink"></a></svg>' ) ;
249
258
250
259
expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:href="https://example.com"></a></svg>' )
251
260
. toBeOneOf ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:href="https://example.com"></a></svg>' ,
252
- '<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><a xlink:href="https://example.com"></a></svg>' ) ;
261
+ '<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><a xlink:href="https://example.com"></a></svg>' ,
262
+ '<svg xmlns="http://www.w3.org/2000/svg"><a xlink:href="https://example.com" xmlns:xlink="http://www.w3.org/1999/xlink"></a></svg>' ,
263
+ '<svg xmlns="http://www.w3.org/2000/svg"><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://example.com"></a></svg>' ) ;
253
264
} ) ;
254
265
255
266
it ( 'should sanitize unknown namespaced SVG attributes' , function ( ) {
256
267
expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:foo="javascript:alert()"></a></svg>' )
257
268
. toBeOneOf ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ,
258
- '<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><a></a></svg>' ) ;
269
+ '<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><a></a></svg>' ,
270
+ '<svg xmlns="http://www.w3.org/2000/svg"><a></a></svg>' ) ;
259
271
260
272
expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:bar="https://example.com"></a></svg>' )
261
273
. toBeOneOf ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a></a></svg>' ,
262
- '<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><a></a></svg>' ) ;
274
+ '<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><a></a></svg>' ,
275
+ '<svg xmlns="http://www.w3.org/2000/svg"><a></a></svg>' ) ;
263
276
} ) ;
264
277
265
278
it ( 'should not accept SVG animation tags' , function ( ) {
266
279
expectHTML ( '<svg xmlns:xlink="http://www.w3.org/1999/xlink"><a><text y="1em">Click me</text><animate attributeName="xlink:href" values="javascript:alert(1)"/></a></svg>' )
267
- . toEqual ( '<svg xmlns:xlink="http://www.w3.org/1999/xlink"><a><text y="1em">Click me</text></a></svg>' ) ;
280
+ . toBeOneOf ( '<svg xmlns:xlink="http://www.w3.org/1999/xlink"><a><text y="1em">Click me</text></a></svg>' ,
281
+ '<svg xmlns="http://www.w3.org/2000/svg"><a><text y="1em">Click me</text></a></svg>' ) ;
268
282
269
283
expectHTML ( '<svg><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="?"><circle r="400"></circle>' +
270
284
'<animate attributeName="xlink:href" begin="0" from="javascript:alert(1)" to="&" /></a></svg>' )
271
285
. toBeOneOf ( '<svg><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="?"><circle r="400"></circle></a></svg>' ,
272
- '<svg><a xlink:href="?" xmlns:xlink="http://www.w3.org/1999/xlink"><circle r="400"></circle></a></svg>' ) ;
286
+ '<svg><a xlink:href="?" xmlns:xlink="http://www.w3.org/1999/xlink"><circle r="400"></circle></a></svg>' ,
287
+ '<svg xmlns="http://www.w3.org/2000/svg"><a xlink:href="?" xmlns:xlink="http://www.w3.org/1999/xlink"><circle r="400"></circle></a></svg>' ,
288
+ '<svg xmlns="http://www.w3.org/2000/svg"><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="?"><circle r="400"></circle></a></svg>' ) ;
273
289
} ) ;
274
290
} ) ;
275
291
0 commit comments