@@ -89,6 +89,26 @@ describe('Meta service', () => {
8989 expect ( actual ! . getAttribute ( 'content' ) ) . toEqual ( '4321' ) ;
9090 } ) ;
9191
92+ it ( 'should reject event handler attributes targeting a body meta tag' , ( ) => {
93+ doc . body . appendChild ( defaultMeta ) ;
94+
95+ const evil = 'alert(1)' ;
96+
97+ expect ( metaService . getTag ( 'property="fb:app_id"' ) ) . toBe ( defaultMeta ) ;
98+ expect ( ( ) =>
99+ metaService . updateTag ( {
100+ property : 'fb:app_id' ,
101+ style : 'content-visibility:auto' ,
102+ oncontentvisibilityautostatechange : evil ,
103+ } ) ,
104+ ) . toThrowError (
105+ / N G 0 5 2 0 3 : T h e M e t a s e r v i c e d o e s n o t a l l o w s e t t i n g e v e n t h a n d l e r a t t r i b u t e ' o n c o n t e n t v i s i b i l i t y a u t o s t a t e c h a n g e ' / ,
106+ ) ;
107+
108+ expect ( defaultMeta . getAttribute ( 'style' ) ) . toBeNull ( ) ;
109+ expect ( defaultMeta . getAttribute ( 'oncontentvisibilityautostatechange' ) ) . toBeNull ( ) ;
110+ } ) ;
111+
92112 it ( 'should not allow a custom selector to match off target elements like the body tag' , ( ) => {
93113 // This payload attempts to break out of the `meta[name="..."]` constraint entirely
94114 // and inject a comma to target arbitrary DOM elements like the `body` tag via the
@@ -143,6 +163,42 @@ describe('Meta service', () => {
143163 metaService . removeTagElement ( actual ) ;
144164 } ) ;
145165
166+ it ( 'should reject event handler attributes without adding a tag' , ( ) => {
167+ const selector = 'name="og:title"' ;
168+ const evil = 'alert(1)' ;
169+
170+ expect ( ( ) =>
171+ metaService . addTag ( {
172+ name : 'og:title' ,
173+ style : 'content-visibility:auto' ,
174+ oncontentvisibilityautostatechange : evil ,
175+ } ) ,
176+ ) . toThrowError (
177+ / N G 0 5 2 0 3 : T h e M e t a s e r v i c e d o e s n o t a l l o w s e t t i n g e v e n t h a n d l e r a t t r i b u t e ' o n c o n t e n t v i s i b i l i t y a u t o s t a t e c h a n g e ' / ,
178+ ) ;
179+
180+ expect ( metaService . getTag ( selector ) ) . toBeNull ( ) ;
181+ } ) ;
182+
183+ it ( 'should reject event handler attributes in addTags without adding tags' , ( ) => {
184+ const selector = 'name="og:title"' ;
185+ const evil = 'alert(1)' ;
186+
187+ expect ( ( ) =>
188+ metaService . addTags ( [
189+ {
190+ name : 'og:title' ,
191+ style : 'content-visibility:auto' ,
192+ oncontentvisibilityautostatechange : evil ,
193+ } ,
194+ ] ) ,
195+ ) . toThrowError (
196+ / N G 0 5 2 0 3 : T h e M e t a s e r v i c e d o e s n o t a l l o w s e t t i n g e v e n t h a n d l e r a t t r i b u t e ' o n c o n t e n t v i s i b i l i t y a u t o s t a t e c h a n g e ' / ,
197+ ) ;
198+
199+ expect ( metaService . getTag ( selector ) ) . toBeNull ( ) ;
200+ } ) ;
201+
146202 it ( 'should add httpEquiv meta tag as http-equiv' , ( ) => {
147203 metaService . addTag ( { httpEquiv : 'refresh' , content : '3;url=http://test' } ) ;
148204
@@ -155,6 +211,22 @@ describe('Meta service', () => {
155211 metaService . removeTagElement ( actual ) ;
156212 } ) ;
157213
214+ it ( 'should add attributes whose names match Object prototype keys' , ( ) => {
215+ const meta = metaService . addTag ( {
216+ name : 'prototype-keys' ,
217+ constructor : 'constructor' ,
218+ toString : 'toString' ,
219+ [ '__proto__' ] : '__proto__' ,
220+ } ) ! ;
221+
222+ expect ( meta . getAttribute ( 'constructor' ) ) . toEqual ( 'constructor' ) ;
223+ expect ( meta . getAttribute ( 'toString' ) ) . toEqual ( 'toString' ) ;
224+ expect ( meta . getAttribute ( '__proto__' ) ) . toEqual ( '__proto__' ) ;
225+
226+ // clean up
227+ metaService . removeTagElement ( meta ) ;
228+ } ) ;
229+
158230 it ( 'should escape selector values when deriving the match selector' , ( ) => {
159231 // This payload attempts to prematurely close the attribute selector
160232 // and match another attribute.
0 commit comments