@ProviderType
public interface XSSAPI
Note: in general, validators are safer than encoders. Encoding only ensures that content within the encoded context cannot break out of said context. It requires that there be a context (for instance, a string context in Javascript), and that damage cannot be done from within the context (for instance, a javascript: URL within a href attribute.
When in doubt, use a validator.
| Modifier and Type | Method and Description |
|---|---|
String |
encodeForCSSString(String source)
Encodes a source string for writing to CSS string content.
|
String |
encodeForHTML(String source)
Encodes a source string for HTML element content.
|
String |
encodeForHTMLAttr(String source)
Encodes a source string for writing to an HTML attribute value.
|
String |
encodeForJSString(String source)
Encodes a source string for writing to JavaScript string content.
|
String |
encodeForXML(String source)
Encodes a source string for XML element content.
|
String |
encodeForXMLAttr(String source)
Encodes a source string for writing to an XML attribute value.
|
String |
filterHTML(String source)
Filters potentially user-contributed HTML to meet the AntiSamy policy rules currently in
effect for HTML output (see the XSSFilter service for details).
|
String |
getValidCSSColor(String color,
String defaultColor)
Validate a CSS color value.
|
String |
getValidDimension(String dimension,
String defaultValue)
Validate a string which should contain a dimension, returning a default value if the source is
empty, can't be parsed, or contains XSS risks.
|
Double |
getValidDouble(String source,
double defaultValue)
Validate a string which should contain an double, returning a default value if the source is
null, empty, can't be parsed, or contains XSS risks. |
String |
getValidHref(String url)
Sanitizes a URL for writing as an HTML href or src attribute value.
|
Integer |
getValidInteger(String integer,
int defaultValue)
Validate a string which should contain an integer, returning a default value if the source is
null, empty, can't be parsed, or contains XSS risks. |
String |
getValidJSON(String json,
String defaultJson)
Validate a JSON string
|
String |
getValidJSToken(String token,
String defaultValue)
Validate a Javascript token.
|
Long |
getValidLong(String source,
long defaultValue)
Validate a string which should contain a long, returning a default value if the source is
null, empty, can't be parsed, or contains XSS risks. |
String |
getValidMultiLineComment(String comment,
String defaultComment)
Validate multi-line comment to be used inside a <script>...</script> or <style>...</style> block.
|
String |
getValidStyleToken(String token,
String defaultValue)
Validate a style/CSS token.
|
String |
getValidXML(String xml,
String defaultXml)
Validate an XML string
|
@Nullable Integer getValidInteger(@Nullable String integer, int defaultValue)
null, empty, can't be parsed, or contains XSS risks.integer - the source integerdefaultValue - a default value if the source can't be used, is null or an empty string@Nullable Long getValidLong(@Nullable String source, long defaultValue)
null, empty, can't be parsed, or contains XSS risks.source - the source longdefaultValue - a default value if the source can't be used, is null or an empty string@Nullable Double getValidDouble(@Nullable String source, double defaultValue)
null, empty, can't be parsed, or contains XSS risks.source - the source doubledefaultValue - a default value if the source can't be used, is null or an empty string@Nullable String getValidDimension(@Nullable String dimension, @Nullable String defaultValue)
dimension - the source dimensiondefaultValue - a default value if the source can't be used, is null or an empty string@Nonnull String getValidHref(@Nullable String url)
url - the source URL@Nullable String getValidJSToken(@Nullable String token, @Nullable String defaultValue)
token - the source tokendefaultValue - a default value to use if the source is null, an empty string, or doesn't meet validity constraints.@Nullable String getValidStyleToken(@Nullable String token, @Nullable String defaultValue)
token - the source tokendefaultValue - a default value to use if the source is null, an empty string, or doesn't meet validity constraints.@Nullable String getValidCSSColor(@Nullable String color, @Nullable String defaultColor)
color - the color value to be used.defaultColor - a default value to use if the input color value is null, an empty string, doesn't meet validity constraints.String getValidMultiLineComment(@Nullable String comment, @Nullable String defaultComment)
comment - the comment to be useddefaultComment - a default value to use if the comment is null or not valid.String getValidJSON(@Nullable String json, @Nullable String defaultJson)
json - the JSON string to validatedefaultJson - the default value to use if json is null or not validString getValidXML(@Nullable String xml, @Nullable String defaultXml)
xml - the XML string to validatedefaultXml - the default value to use if xml is null or not valid@Nullable String encodeForHTML(@Nullable String source)
source - the input to encode@Nullable String encodeForHTMLAttr(@Nullable String source)
source - the input to encode@Nullable String encodeForXML(@Nullable String source)
source - the input to encode@Nullable String encodeForXMLAttr(@Nullable String source)
source - the input to encode@Nullable String encodeForJSString(@Nullable String source)
source - the input to encode@Nullable String encodeForCSSString(@Nullable String source)
source - the input to encode@Nonnull String filterHTML(@Nullable String source)
source - a string containing the source HTMLsource is null or emptyCopyright © 2017 The Apache Software Foundation. All rights reserved.