Package io.jmix.ui.sanitizer
Class HtmlSanitizer
java.lang.Object
io.jmix.ui.sanitizer.HtmlSanitizer
Utility bean that sanitizes a sting of HTML according to the factory's policy to prevent Cross-site Scripting (XSS)
in HTML context.
The default policy factory contains special policies for the font element, because the RichTextArea component
supports the font element as value. Also default policy factory contains policies that are not contained in
standard Sanitizers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected static final Stringprotected static final Patternprotected static final StringHtml class regexp.protected static final com.google.common.collect.ImmutableSet<String>The additional css schema whitelist that was not included in the default whitelist inSanitizers.STYLES.protected static final Stringprotected static final Patternprotected static final StringFont color regexp.protected static final Stringprotected static final Patternprotected static final StringFont face regexp.protected static final Stringprotected static final Patternprotected static final StringFont size regexp.protected static final Stringprotected static final Stringprotected static final Stringprotected org.owasp.html.PolicyFactoryprotected static final Stringprotected static final com.google.common.collect.ImmutableSet<String> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected com.google.common.collect.ImmutableMap<String,org.owasp.html.CssSchema.Property> org.owasp.html.PolicyFactoryprotected voidInit default policy factory that is used to produce HTML sanitizer policies that sanitize a sting of HTML.Sanitizes a string of HTML according to the factory's policy.voidsetPolicyFactory(org.owasp.html.PolicyFactory policyFactory) Sets policy factory.
-
Field Details
-
FONT_SIZE_REGEXP
Font size regexp. Intended to match size attribute value of font element.Regexp explanation:
[0-7]- matches a number in the range 0 to 7|- acts like a boolean OR[+-]?(?:[0-9]+)- matches a relative font size value
Example:
<font size="7"/>- See Also:
-
FONT_SIZE_PATTERN
-
FONT_SIZE_ATTRIBUTE_NAME
- See Also:
-
FONT_FACE_REGEXP
Font face regexp. Intended to match face attribute value of font element.Regexp explanation:
[\w;, \-]+- matches font names separated by comma or semicolon
Example:
<font face="Verdana"/>- See Also:
-
FONT_FACE_PATTERN
-
FONT_FACE_ATTRIBUTE_NAME
- See Also:
-
FONT_COLOR_REGEXP
Font color regexp. Intended to match color attribute value that of font element.Regexp explanation:
(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})- matches hexademical color|- acts like a boolean OR(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[d\.]+%?\)- matches RGB, RGBA, HSL, HSLA colors"color_name"- matches color by name
Example:
<font color="#0000ff"/>- See Also:
-
FONT_COLOR_PATTERN
-
FONT_COLOR_ATTRIBUTE_NAME
- See Also:
-
CLASS_REGEXP
Html class regexp. Intended to match class attribute value.Regexp explanation:
a-zA-Z- matches a single character in the range: a-z, A-Z0-9- matches a single character in the range: 0-9,- matches a comma character\\s- matches any whitespace character\\-- matches a dash character_- matches an underscore character[]+- matches between one and unlimited times
Example:
<div class="v-app"/>- See Also:
-
CLASS_PATTERN
-
CLASS_ATTRIBUTE_NAME
- See Also:
-
A_ELEMENT_NAME
- See Also:
-
HREF_ATTRIBUTE_NAME
- See Also:
-
TARGET_ATTRIBUTE_NAME
- See Also:
-
TARGET_ATTRIBUTE_VALUES
-
NOOPENNER_REL_VALUE
- See Also:
-
NOREFERRER_REL_VALUE
- See Also:
-
DEFAULT_WHITELIST
The additional css schema whitelist that was not included in the default whitelist inSanitizers.STYLES. . -
policyFactory
protected org.owasp.html.PolicyFactory policyFactory
-
-
Constructor Details
-
HtmlSanitizer
public HtmlSanitizer()
-
-
Method Details
-
sanitize
Sanitizes a string of HTML according to the factory's policy.- Parameters:
html- the string of HTML to sanitize- Returns:
- a string of HTML that complies with the factory's policy
-
getPolicyFactory
public org.owasp.html.PolicyFactory getPolicyFactory()- Returns:
- a policy factory
-
setPolicyFactory
public void setPolicyFactory(org.owasp.html.PolicyFactory policyFactory) Sets policy factory.- Parameters:
policyFactory- a policy factory
-
initDefaultPolicyFactory
protected void initDefaultPolicyFactory()Init default policy factory that is used to produce HTML sanitizer policies that sanitize a sting of HTML. -
getAdditionalStylePolicies
protected com.google.common.collect.ImmutableMap<String,org.owasp.html.CssSchema.Property> getAdditionalStylePolicies()- Returns:
- additional style policies that were not included in
Sanitizers.STYLES.
-