Creates and configures $sanitize
instance.
enableSvg([flag]);
Enables a subset of svg to be supported by the sanitizer.
By enabling this setting without taking other precautions, you might expose your application to click-hijacking attacks. In these attacks, sanitized svg elements could be positioned outside of the containing element and be rendered over other elements on the page (e.g. a login link). Such behavior can then result in phishing incidents.
To protect against these, explicitly setup overflow: hidden
css rule for all potential svg
tags within the sanitized content:
.rootOfTheIncludedContent svg {
overflow: hidden !important;
}
Param | Type | Details |
---|---|---|
flag
(optional)
|
boolean |
Enable or disable SVG support in the sanitizer. |
boolean$sanitizeProvider | Returns the currently configured value if called without an argument or self for chaining otherwise. |
addValidElements(elements);
Extends the built-in lists of valid HTML/SVG elements, i.e. elements that are considered safe and are not stripped off during sanitization. You can extend the following lists of elements:
htmlElements
: A list of elements (tag names) to extend the current list of safe HTML
elements. HTML elements considered safe will not be removed during sanitization. All other
elements will be stripped off.
htmlVoidElements
: This is similar to htmlElements
, but marks the elements as
"void elements" (similar to HTML
void elements). These
elements have no end tag and cannot have content.
svgElements
: This is similar to htmlElements
, but for SVG elements. This list is only
taken into account if SVG is enabled for
$sanitize
.
$sanitize
service has been instantiated, this method has no effect.
Param | Type | Details |
---|---|---|
elements | Array.<String>Object |
A list of valid HTML elements or an object with one or more of the following properties:
Passing an array ( |
$sanitizeProvider | Returns self for chaining. |
addValidAttrs(attrs);
Extends the built-in list of valid attributes, i.e. attributes that are considered safe and are not stripped off during sanitization.
Note:
The new attributes will not be treated as URI attributes, which means their values will not be
sanitized as URIs using $compileProvider
's
aHrefSanitizationWhitelist and
imgSrcSanitizationWhitelist.
$sanitize
service has been instantiated, this method has no effect.
Param | Type | Details |
---|---|---|
attrs | Array<String> |
A list of valid attributes. |
$sanitizeProvider | Returns self for chaining. |