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 |
|---|---|
java.lang.String |
encodeForCSSString(java.lang.String source)
Encodes a source string for writing to CSS string content.
|
java.lang.String |
encodeForHTML(java.lang.String source)
Encodes a source string for HTML element content.
|
java.lang.String |
encodeForHTMLAttr(java.lang.String source)
Encodes a source string for writing to an HTML attribute value.
|
java.lang.String |
encodeForJSString(java.lang.String source)
Encodes a source string for writing to JavaScript string content.
|
java.lang.String |
encodeForXML(java.lang.String source)
Encodes a source string for XML element content.
|
java.lang.String |
encodeForXMLAttr(java.lang.String source)
Encodes a source string for writing to an XML attribute value.
|
java.lang.String |
filterHTML(java.lang.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).
|
XSSAPI |
getRequestSpecificAPI(SlingHttpServletRequest request)
Deprecated.
|
XSSAPI |
getResourceResolverSpecificAPI(ResourceResolver resourceResolver)
Deprecated.
|
java.lang.String |
getValidCSSColor(java.lang.String color,
java.lang.String defaultColor)
Validate a CSS color value.
|
java.lang.String |
getValidDimension(java.lang.String dimension,
java.lang.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.
|
java.lang.Double |
getValidDouble(java.lang.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. |
java.lang.String |
getValidHref(java.lang.String url)
Sanitizes a URL for writing as an HTML href or src attribute value.
|
java.lang.Integer |
getValidInteger(java.lang.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. |
java.lang.String |
getValidJSON(java.lang.String json,
java.lang.String defaultJson)
Validate a JSON string
|
java.lang.String |
getValidJSToken(java.lang.String token,
java.lang.String defaultValue)
Validate a Javascript token.
|
java.lang.Long |
getValidLong(java.lang.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. |
java.lang.String |
getValidMultiLineComment(java.lang.String comment,
java.lang.String defaultComment)
Validate multi-line comment to be used inside a <script>...</script> or <style>...</style> block.
|
java.lang.String |
getValidStyleToken(java.lang.String token,
java.lang.String defaultValue)
Validate a style/CSS token.
|
java.lang.String |
getValidXML(java.lang.String xml,
java.lang.String defaultXml)
Validate an XML string
|
java.lang.Integer getValidInteger(java.lang.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 stringjava.lang.Long getValidLong(java.lang.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 stringjava.lang.Double getValidDouble(java.lang.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 stringjava.lang.String getValidDimension(java.lang.String dimension,
java.lang.String defaultValue)
dimension - the source dimensiondefaultValue - a default value if the source can't be used, is null or an empty stringjava.lang.String getValidHref(java.lang.String url)
url - the source URLjava.lang.String getValidJSToken(java.lang.String token,
java.lang.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.java.lang.String getValidStyleToken(java.lang.String token,
java.lang.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.java.lang.String getValidCSSColor(java.lang.String color,
java.lang.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.java.lang.String getValidMultiLineComment(java.lang.String comment,
java.lang.String defaultComment)
comment - the comment to be useddefaultComment - a default value to use if the comment is null or not valid.java.lang.String getValidJSON(java.lang.String json,
java.lang.String defaultJson)
json - the JSON string to validatedefaultJson - the default value to use if json is null or not validjava.lang.String getValidXML(java.lang.String xml,
java.lang.String defaultXml)
xml - the XML string to validatedefaultXml - the default value to use if xml is null or not validjava.lang.String encodeForHTML(java.lang.String source)
source - the input to encodejava.lang.String encodeForHTMLAttr(java.lang.String source)
source - the input to encodejava.lang.String encodeForXML(java.lang.String source)
source - the input to encodejava.lang.String encodeForXMLAttr(java.lang.String source)
source - the input to encodejava.lang.String encodeForJSString(java.lang.String source)
source - the input to encodejava.lang.String encodeForCSSString(java.lang.String source)
source - the input to encodejava.lang.String filterHTML(java.lang.String source)
source - a string containing the source HTMLsource is null or empty@Deprecated XSSAPI getRequestSpecificAPI(SlingHttpServletRequest request)
request - the request from which to obtain the XSSAPI@Deprecated XSSAPI getResourceResolverSpecificAPI(ResourceResolver resourceResolver)
resourceResolver - the resolver from which to obtain the XSSAPI"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"