@@ -206,6 +206,53 @@ var attrToPropMap: {[name: string]: string} = <any>{
206
206
'tabindex' : 'tabIndex'
207
207
} ;
208
208
209
+ function registerContext ( map : { [ k : string ] : SecurityContext } , ctx : SecurityContext , specs : string [ ] ) {
210
+ for ( let spec of specs ) map [ spec ] = ctx ;
211
+ }
212
+
213
+ /** Map from tagName|propertyName SecurityContext. Properties applying to all tags use '*'. */
214
+ const SECURITY_SCHEMA : { [ k : string ] : SecurityContext } = { } ;
215
+
216
+ registerContext ( SECURITY_SCHEMA , SecurityContext . HTML , [
217
+ 'iframe|srcdoc' ,
218
+ '*|innerHTML' ,
219
+ '*|outerHTML' ,
220
+ ] ) ;
221
+ registerContext ( SECURITY_SCHEMA , SecurityContext . STYLE , [ '*|style' ] ) ;
222
+ // NB: no SCRIPT contexts here, they are never allowed.
223
+ registerContext ( SECURITY_SCHEMA , SecurityContext . URL , [
224
+ 'area|href' ,
225
+ 'area|ping' ,
226
+ 'audio|src' ,
227
+ 'a|href' ,
228
+ 'a|ping' ,
229
+ 'blockquote|cite' ,
230
+ 'body|background' ,
231
+ 'button|formaction' ,
232
+ 'del|cite' ,
233
+ 'form|action' ,
234
+ 'img|src' ,
235
+ 'input|formaction' ,
236
+ 'input|src' ,
237
+ 'ins|cite' ,
238
+ 'q|cite' ,
239
+ 'source|src' ,
240
+ 'video|poster' ,
241
+ 'video|src' ,
242
+ ] ) ;
243
+ registerContext ( SECURITY_SCHEMA , SecurityContext . RESOURCE_URL , [
244
+ 'applet|code' ,
245
+ 'applet|codebase' ,
246
+ 'base|href' ,
247
+ 'frame|src' ,
248
+ 'head|profile' ,
249
+ 'html|manifest' ,
250
+ 'iframe|src' ,
251
+ 'object|codebase' ,
252
+ 'object|data' ,
253
+ 'script|src' ,
254
+ 'track|src' ,
255
+ ] ) ;
209
256
210
257
@Injectable ( )
211
258
export class DomElementSchemaRegistry extends ElementSchemaRegistry {
@@ -267,11 +314,10 @@ export class DomElementSchemaRegistry extends ElementSchemaRegistry {
267
314
* attack vectors are assigned their appropriate context.
268
315
*/
269
316
securityContext ( tagName : string , propName : string ) : SecurityContext {
270
- // TODO(martinprobst): Fill in missing properties.
271
- if ( propName === 'style' ) return SecurityContext . STYLE ;
272
- if ( tagName === 'a' && propName === 'href' ) return SecurityContext . URL ;
273
- if ( propName === 'innerHTML' ) return SecurityContext . HTML ;
274
- return SecurityContext . NONE ;
317
+ let ctx = SECURITY_SCHEMA [ tagName + '|' + propName ] ;
318
+ if ( ctx !== undefined ) return ctx ;
319
+ ctx = SECURITY_SCHEMA [ '*|' + propName ] ;
320
+ return ctx !== undefined ? ctx : SecurityContext . NONE ;
275
321
}
276
322
277
323
getMappedPropName ( propName : string ) : string {
0 commit comments