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 SummaryFieldsModifier 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 SummaryConstructors
- 
Method SummaryModifier 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_REGEXPFont 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_REGEXPFont 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_REGEXPFont 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_REGEXPHtml class regexp. Intended to match class attribute value.Regexp explanation: - a-zA-Z- matches a single character in the range: a-z, A-Z
- 0-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_WHITELISTThe additional css schema whitelist that was not included in the default whitelist inSanitizers.STYLES. .
- 
policyFactoryprotected org.owasp.html.PolicyFactory policyFactory
 
- 
- 
Constructor Details- 
HtmlSanitizerpublic HtmlSanitizer()
 
- 
- 
Method Details- 
sanitizeSanitizes 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
 
- 
getPolicyFactorypublic org.owasp.html.PolicyFactory getPolicyFactory()- Returns:
- a policy factory
 
- 
setPolicyFactorypublic void setPolicyFactory(org.owasp.html.PolicyFactory policyFactory) Sets policy factory.- Parameters:
- policyFactory- a policy factory
 
- 
initDefaultPolicyFactoryprotected void initDefaultPolicyFactory()Init default policy factory that is used to produce HTML sanitizer policies that sanitize a sting of HTML.
- 
getAdditionalStylePoliciesprotected com.google.common.collect.ImmutableMap<String,org.owasp.html.CssSchema.Property> getAdditionalStylePolicies()- Returns:
- additional style policies that were not included in Sanitizers.STYLES.
 
 
-