Enhancing ngSanitize whitelists #5900
Description
There needs to be a way to extend the ngSanitize whitelists of elements and attributes. In our project, we need to add additional valid HTML5 elements to the list of valid elements (like video
and audio
). We also need to add some of our custom elements to the list.
I am willing to do the work and submit a PR. However, I want to make sure I do it the right way.
I was thinking of adding something similar to $compileProvider
's aHrefSanitizationWhitelist
and imgSrcSanitizationWhitelist
that manages the voidElements
, optionalEndTagBlockElements
, optionalEndTagInlineElements
, blockElements
, inlineElements
, specialElements
, uriAttrs
, and validAttrs
lists within the $sanitize implementation.
I would probably make them as methods that take an array of additional whitelisted elements or attributes. These would then be used to extend the current whitelists. This could be implemented on $compileProvider
or on a new provider inside the $sanitize
module.
Another option would be to make the new methods take the entire whitelist. This would allow the caller to remove some elements or attributes that are already in the existing whitelists. However, the current whitelists would then have to be documented. The caller would also have to pass in the entire existing whitelist with their additions if all they wanted to do was add and element or attribute.