@@ -11,33 +11,24 @@ import {TestBed} from '@angular/core/testing';
1111
1212
1313describe ( 'comment node text escaping' , ( ) => {
14- // see: https://html.spec.whatwg.org/multipage/syntax.html#comments
15- [ '>' , // self closing
16- '-->' , // standard closing
17- '--!>' , // alternate closing
18- '<!-- -->' , // embedded comment.
19- ] . forEach ( ( xssValue ) => {
20- it ( 'should not be possible to do XSS through comment reflect data when writing: ' + xssValue ,
21- ( ) => {
22- @Component ( { template : `<div><span *ngIf="xssValue"></span><div>` } )
23- class XSSComp {
24- // ngIf serializes the `xssValue` into a comment for debugging purposes.
25- xssValue : string = xssValue + '<script>"evil"</script>' ;
26- }
14+ it ( 'should not be possible to do XSS through comment reflect data' , ( ) => {
15+ @Component ( { template : `<div><span *ngIf="xssValue"></span><div>` } )
16+ class XSSComp {
17+ xssValue : string = '--> --><script>"evil"</script>' ;
18+ }
2719
28- TestBed . configureTestingModule ( { declarations : [ XSSComp ] } ) ;
29- const fixture = TestBed . createComponent ( XSSComp ) ;
30- fixture . detectChanges ( ) ;
31- const div = fixture . nativeElement . querySelector ( 'div' ) as HTMLElement ;
32- // Serialize into a string to mimic SSR serialization.
33- const html = div . innerHTML ;
34- // This must be escaped or we have XSS.
35- expect ( html ) . not . toContain ( '--><script' ) ;
36- // Now parse it back into DOM (from string)
37- div . innerHTML = html ;
38- // Verify that we did not accidentally deserialize the `<script>`
39- const script = div . querySelector ( 'script' ) ;
40- expect ( script ) . toBeFalsy ( ) ;
41- } ) ;
20+ TestBed . configureTestingModule ( { declarations : [ XSSComp ] } ) ;
21+ const fixture = TestBed . createComponent ( XSSComp ) ;
22+ fixture . detectChanges ( ) ;
23+ const div = fixture . nativeElement . querySelector ( 'div' ) as HTMLElement ;
24+ // Serialize into a string to mimic SSR serialization.
25+ const html = div . innerHTML ;
26+ // This must be escaped or we have XSS.
27+ expect ( html ) . not . toContain ( '--><script' ) ;
28+ // Now parse it back into DOM (from string)
29+ div . innerHTML = html ;
30+ // Verify that we did not accidentally deserialize the `<script>`
31+ const script = div . querySelector ( 'script' ) ;
32+ expect ( script ) . toBeFalsy ( ) ;
4233 } ) ;
4334} ) ;
0 commit comments