@@ -216,11 +216,18 @@ describe('HTML', function() {
216216 expectHTML ( false ) . toBe ( 'false' ) ;
217217 } ) ;
218218
219+
219220 it ( 'should strip svg elements if not enabled via provider' , function ( ) {
220221 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>' )
221222 . toEqual ( '' ) ;
222223 } ) ;
223224
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+
224231
225232 describe ( 'SVG support' , function ( ) {
226233
@@ -238,38 +245,47 @@ describe('HTML', function() {
238245
239246 it ( 'should not ignore white-listed svg camelCased attributes' , function ( ) {
240247 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>' ) ;
242250
243251 } ) ;
244252
245253 it ( 'should sanitize SVG xlink:href attribute values' , function ( ) {
246254 expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:href="javascript:alert()"></a></svg>' )
247255 . 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>' ) ;
249258
250259 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>' )
251260 . 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>' ) ;
253264 } ) ;
254265
255266 it ( 'should sanitize unknown namespaced SVG attributes' , function ( ) {
256267 expectHTML ( '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><a xlink:foo="javascript:alert()"></a></svg>' )
257268 . 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>' ) ;
259271
260272 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>' )
261273 . 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>' ) ;
263276 } ) ;
264277
265278 it ( 'should not accept SVG animation tags' , function ( ) {
266279 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>' ) ;
268282
269283 expectHTML ( '<svg><a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="?"><circle r="400"></circle>' +
270284 '<animate attributeName="xlink:href" begin="0" from="javascript:alert(1)" to="&" /></a></svg>' )
271285 . 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>' ) ;
273289 } ) ;
274290 } ) ;
275291
0 commit comments