Class Policy
- Direct Known Subclasses:
InternalPolicy
## Schema validation behavior change starting with AntiSamy 1.6.0 ##
Prior to v1.6.0 AntiSamy was not actually enforcing it's defined XSD. For all of v1.6.x, by default AntiSamy enforced the schema, and wouldn't continue if the AntiSamy policy was invalid. However, we recognized that it might not be possible for developers to fix their AntiSamy policies right away so we provided two ways to (temporarily!) disable schema validation. Via a direct method call and via a System property.
## Starting with AntiSamy 1.7.0, schema validation is Mandatory.
Logging: The logging introduced in 1.6+ uses slf4j. But AntiSamy doesn't actually include an slf4j implementation library. AntiSamy users must import and properly configure an slf4j logging library if they want to see the very few log messages generated by AntiSamy.
- Author:
- Arshan Dabirsiaghi
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Patternstatic final StringDeprecated.Remote styles import feature to be removed and along with this error message.static final intstatic final intDeprecated.Remote styles import feature to be removed and along with this error message.protected static final Stringstatic final Stringstatic final StringDeprecated.Remote styles import feature to be removed and along with this error message.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected static final org.slf4j.Loggerstatic final Stringstatic final StringDeprecated.Remote styles import feature to be removed and along with this error message.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncloneWithDirective(String name, String value) Creates a copy of this policy with an added/changed directive.Return all the allowed empty tags configured in the Policy.getDirective(String name) Return a directive value based on a lookup name.A method for returning one of the dynamic <global-attribute> entries by name.A simple method for returning on of the <global-attribute> entries by name.static PolicyConstruct a Policy using the default policy file location ("antisamy.xml").static PolicygetInstance(File file) Construct a Policy from the File object passed in.static PolicygetInstance(InputStream inputStream) Construct a Policy from the InputStream object passed in.static PolicygetInstance(String filename) Construct a Policy based on the file whose name is passed in.static PolicygetInstance(URL url) Construct a Policy from the target of the URL passed in.protected static Policy.ParseContextgetParseContext(Element topLevelElement, URL baseUrl) getPropertyByName(String propertyName) Retrieves a CSS Property from the Policy.Return all the tags that are required to be closed with an end tag, even if they have no child content.protected static Policy.ParseContextgetSimpleParseContext(Element topLevelElement) protected static InputSourcegetSourceFromUrl(URL baseUrl) getTagByLowercaseName(String tagName) Get the Tag specified by the provided tag name.protected static ElementgetTopLevelElement(URL baseUrl) protected static ElementgetTopLevelElement(InputSource source, Callable<InputSource> getResetSource) static InputSourceresolveEntity(String systemId, URL baseUrl) Resolves public and system IDs to files stored within the JAR.
-
Field Details
-
logger
protected static final org.slf4j.Logger logger -
ANYTHING_REGEXP
-
DEFAULT_POLICY_URI
- See Also:
-
DEFAULT_MAX_INPUT_SIZE
public static final int DEFAULT_MAX_INPUT_SIZE- See Also:
-
OMIT_XML_DECLARATION
- See Also:
-
OMIT_DOCTYPE_DECLARATION
- See Also:
-
FORMAT_OUTPUT
- See Also:
-
ANCHORS_NOFOLLOW
- See Also:
-
ANCHORS_NOOPENER_NOREFERRER
- See Also:
-
VALIDATE_PARAM_AS_EMBED
- See Also:
-
PRESERVE_SPACE
- See Also:
-
PRESERVE_COMMENTS
- See Also:
-
ENTITY_ENCODE_INTL_CHARS
- See Also:
-
ALLOW_DYNAMIC_ATTRIBUTES
- See Also:
-
MAX_INPUT_SIZE
- See Also:
-
DEFAULT_MAX_STYLESHEET_IMPORTS
Deprecated.Remote styles import feature to be removed and along with this error message.- See Also:
-
EMBED_STYLESHEETS
Deprecated.Remote styles import feature to be removed and along with this error message.- See Also:
-
CONNECTION_TIMEOUT
Deprecated.Remote styles import feature to be removed and along with this error message.- See Also:
-
MAX_STYLESHEET_IMPORTS
Deprecated.Remote styles import feature to be removed and along with this error message.- See Also:
-
EXTERNAL_GENERAL_ENTITIES
- See Also:
-
EXTERNAL_PARAM_ENTITIES
- See Also:
-
DISALLOW_DOCTYPE_DECL
- See Also:
-
LOAD_EXTERNAL_DTD
- See Also:
-
ACTION_VALIDATE
- See Also:
-
ACTION_FILTER
- See Also:
-
ACTION_TRUNCATE
- See Also:
-
ACTION_ENCODE
- See Also:
-
tagRules
-
cssRules
-
directives
-
-
Constructor Details
-
Policy
-
Policy
-
-
Method Details
-
getTagByLowercaseName
-
getPropertyByName
-
getInstance
Construct a Policy using the default policy file location ("antisamy.xml").- Returns:
- A populated Policy object based on the XML policy file located in the default location.
- Throws:
PolicyException- If the file is not found or there is a problem parsing the file.
-
getInstance
Construct a Policy based on the file whose name is passed in.- Parameters:
filename- The path to the XML policy file.- Returns:
- A populated Policy object based on the XML policy file located in the location passed in.
- Throws:
PolicyException- If the file is not found or there is a problem parsing the file.
-
getInstance
Construct a Policy from the InputStream object passed in.- Parameters:
inputStream- An InputStream which contains the XML policy information.- Returns:
- A populated Policy object based on the XML policy file pointed to by the inputStream parameter.
- Throws:
PolicyException- If there is a problem parsing the input stream.
-
getInstance
Construct a Policy from the File object passed in.- Parameters:
file- A File object which contains the XML policy information.- Returns:
- A populated Policy object based on the XML policy file pointed to by the File parameter.
- Throws:
PolicyException- If the file is not found or there is a problem parsing the file.
-
getInstance
Construct a Policy from the target of the URL passed in.
NOTE: This is the only factory method that will work with <include> tags in AntiSamy policy files.
For security reasons, the provided URL must point to a local file. Currently only 'file:' and 'jar:' URL prefixes are allowed. If you want to use a different URL format, and are confident that the URL points to a safe source, you can open the target of the URL with URL.openStream(), and use the getInstance(InputStream) constructor instead. For example, Spring has classpath: and Wildfly/Jboss supports vfs: for accessing local files. Just be aware that this alternate constructor doesn't support the use of <include> tags, per the NOTE above.- Parameters:
url- A URL object which contains the XML policy information.- Returns:
- A populated Policy object based on the XML policy file pointed to by the File parameter.
- Throws:
PolicyException- If the file is not found or there is a problem parsing the file.
-
getSimpleParseContext
protected static Policy.ParseContext getSimpleParseContext(Element topLevelElement) throws PolicyException - Throws:
PolicyException
-
getParseContext
protected static Policy.ParseContext getParseContext(Element topLevelElement, URL baseUrl) throws PolicyException - Throws:
PolicyException
-
getTopLevelElement
- Throws:
PolicyException
-
getSourceFromUrl
- Throws:
PolicyException
-
getTopLevelElement
protected static Element getTopLevelElement(InputSource source, Callable<InputSource> getResetSource) throws PolicyException - Throws:
PolicyException
-
cloneWithDirective
-
getGlobalAttributeByName
-
getDynamicAttributeByName
A method for returning one of the dynamic <global-attribute> entries by name.- Parameters:
name- The name of the dynamic global-attribute we want to look up.- Returns:
- An Attribute associated with the global-attribute lookup name specified, or null if not found.
-
getAllowedEmptyTags
Return all the allowed empty tags configured in the Policy.- Returns:
- A String array of all the he allowed empty tags configured in the Policy.
-
getRequiresClosingTags
Return all the tags that are required to be closed with an end tag, even if they have no child content.- Returns:
- A String array of all the tags that are required to be closed with an end tag, even if they have no child content.
-
getDirective
-
resolveEntity
public static InputSource resolveEntity(String systemId, URL baseUrl) throws IOException, SAXException Resolves public and system IDs to files stored within the JAR.- Parameters:
systemId- The name of the entity we want to look up.baseUrl- The base location of the entity.- Returns:
- A String object containing the directive associated with the lookup name, or null if none is found.
- Throws:
IOException- if the specified URL can't be opened.SAXException- This exception can't actually be thrown, but left in the method signature for API compatibility reasons.
-
getCommonRegularExpressions
-