|
Generated by JDiff |
||||||||
| PREV PACKAGE NEXT PACKAGE FRAMES NO FRAMES | |||||||||
This file contains all the changes in documentation in the packagecom.itextpdf.styledxmlparser.jsoup.safetyas colored differences. Deletions are shownlike this, and additions are shown like this.
If no deletions or additions are shown in an entry, the HTML tags will be what has changed. The new HTML tags are shown in the differences. If no documentation existed, and then some was added in a later version, this change is noted in the appropriate class pages of differences, but the change is not shown on this page. Only changes in existing text are shown here. Similarly, documentation which was inherited from another class or interface is not shown here.
Note that an HTML error in the new documentation may cause the display of other documentation changes to be presented incorrectly. For instance, failure to close a tag will cause all subsequent paragraphs to be displayed differently.
The whitelist based HTML cleaner. Use to ensure that end-user provided HTML contains only the elements and attributes that you are expecting; no junk, and no cross-site scripting attacks!Class Cleaner, constructor Cleaner(Whitelist)The HTML cleaner parses the input as HTML and then runs it through a white-list, so the output HTML can only contain HTML that is allowed by the whitelist.
It is assumed that the input HTML is a body fragment; the clean methods only pull from the source's body, and the canned white-lists only allow body contained tags.
Rather than interacting directly with a Cleaner object, generally see the {@code clean} methods in Jsoup.
Create a new cleaner, that sanitizes documents using the supplied whitelist.Class Cleaner, Document clean(Document)@param whitelist white-list to clean with
Creates a new, clean document, from the original dirty document, containing only elements allowed by the whitelist.Class Cleaner, boolean isValid(Document)The original document is not modified. Only elements from the dirt document'sbodyare used.@param dirtyDocument Untrusted base document to clean.@return cleaned document.
Determines if the input document is valid, against the whitelist. It is considered valid if all the tags and attributesin the input HTML are allowed by the whitelist.
This method can be used as a validator for user input forms. An invalid document will still be cleaned successfullyusing the .clean(Document) document. If using as a validator, it is recommended to still clean the documentto ensure enforced attributes are set correctly, and that the output is tidied.@param dirtyDocument document to test@return true if no tags or attributes need to be removed; false if they do
Whitelists define what HTML (elements and attributes) to allow through the cleaner. Everything else is removed.Class Whitelist, constructor Whitelist()Start with one of the defaults:
If you need to allow more through (please be careful!), tweak a base whitelist with:You can remove any setting from an existing whitelist with:The cleaner and these whitelists assume that you want to clean abodyfragment of HTML (to add user supplied HTML into a templated page), and not to clean a full HTML document. If the latter is the case, either wrap the document HTML around the cleaned body HTML, or create a whitelist that allowshtmlandheadelements as appropriate.If you are going to extend a whitelist, please be very careful. Make sure you understand what attributes may lead to XSS attack vectors. URL attributes are particularly vulnerable and require careful validation.
SeeSee http://ha.ckers.org/xss.html for some XSS attack examples.@author Jonathan Hedley
Create a new, empty whitelist. Generally it will be better to start with a default prepared whitelist instead.Class Whitelist, Whitelist addAttributes(String, String[])@see #basic()@see #basicWithImages()@see #simpleText()@see #relaxed()
Add a list of allowed attributes to a tag. (If an attribute is not allowed on an element, it will be removed.)Class Whitelist, Whitelist addEnforcedAttribute(String, String, String)
E.g.:addAttributes("a", "href", "class")allowshrefandclassattributesonatags.
To make an attribute valid for all tags, use the pseudo tag:all, e.g.addAttributes(":all", "class").@param tag The tag the attributes are for. The tag will be added to the allowed tag list if necessary.@param keys List of valid attributes for the tag@return this (for chaining)
Add an enforced attribute to a tag. An enforced attribute will always be added to the element. If the elementClass Whitelist, Whitelist addProtocols(String, String, String[])already has the attribute set, it will be overridden.
E.g.:addEnforcedAttribute("a", "rel", "nofollow")will make allatags output as@param tag The tag the enforced attribute is for. The tag will be added to the allowed tag list if necessary.@param key The attribute key@param value The enforced attribute value@return this (for chaining)
Add allowed URL protocols for an element's URL attribute. This restricts the possible values of the attribute toClass Whitelist, Whitelist addTags(String[])URLs with the defined protocol.
E.g.:addProtocols("a", "href", "ftp", "http", "https")
To allow a link to an in-page URL anchor (i.e., add a#:
E.g.:addProtocols("a", "href", "#")@param tag Tag the URL protocol is for@param key Attribute key@param protocols List of valid protocols@return this, for chaining
Add a list of allowed elements to a whitelist. (If a tag is not allowed, it will be removed from the HTML.)Class Whitelist, Whitelist basic()@param tags tag names to allow@return this (for chaining)
Class Whitelist, Whitelist basicWithImages()This whitelist allows a fuller range of text nodes:a, b, blockquote, br, cite, code, dd, dl, dt, em, i, li,, and appropriate attributes.ol, p, pre, q, small, span, strike, strong, sub, sup, u, ul
Links (aelements) can point tohttp, https, ftp, mailto, and have an enforcedrel=nofollowattribute.
Does not allow images.@return whitelist
This whitelist allows the same text tags as .basic, and also allowsClass Whitelist, Whitelist none()imgtags, with appropriateattributes, withsrcpointing tohttporhttps.@return whitelist
This whitelist allows only text nodes: all HTML will be stripped.Class Whitelist, Whitelist preserveRelativeLinks(boolean)@return whitelist
Configure this Whitelist to preserve relative links in an element's URL attribute, or convert them to absolute links. By default, this is false: URLs will be made absolute (e.g. start with an allowed protocol, like e.g. {@code http://}.Class Whitelist, Whitelist relaxed()Note that when handling relative links, the input document must have an appropriate {@code base URI} set when parsing, so that the link's protocol can be confirmed. Regardless of the setting of the {@code preserve relative links} option, the link must be resolvable against the base URI to an allowed protocol; otherwise the attribute will be removed.
@param preserve {@code true} to allow relative links, {@code false} (default) to deny @return this Whitelist, for chaining. @see #addProtocols
This whitelist allows a full range of text and structural body HTML:Class Whitelist, Whitelist removeAttributes(String, String[])a, b, blockquote, br, caption, cite,code, col, colgroup, dd, div, dl, dt, em, h1, h2, h3, h4, h5, h6, i, img, li, ol, p, pre, q, small, span, strike, strong, sub,sup, table, tbody, td, tfoot, th, thead, tr, u, ul
Links do not have an enforcedrel=nofollowattribute, but you can add that if desired.@return whitelist
Remove a list of allowed attributes from a tag. (If an attribute is not allowed on an element, it will be removed.)Class Whitelist, Whitelist removeEnforcedAttribute(String, String)
E.g.:removeAttributes("a", "href", "class")disallowshrefandclassattributes onatags.
To make an attribute invalid for all tags, use the pseudo tag:all, e.g.removeAttributes(":all", "class").@param tag The tag the attributes are for.@param keys List of invalid attributes for the tag@return this (for chaining)
Remove a previously configured enforced attribute from a tag.Class Whitelist, Whitelist removeProtocols(String, String, String[])@param tag The tag the enforced attribute is for.@param key The attribute key@return this (for chaining)
Remove allowed URL protocols for an element's URL attribute.Class Whitelist, Whitelist removeTags(String[])
E.g.:removeProtocols("a", "href", "ftp")@param tag Tag the URL protocol is for@param key Attribute key@param protocols List of invalid protocols@return this, for chaining
Remove a list of allowed elements from a whitelist. (If a tag is not allowed, it will be removed from the HTML.)Class Whitelist, Whitelist simpleText()@param tags tag names to disallow@return this (for chaining)
This whitelist allows only simple text formatting:b, em, i, strong, u. All other HTML (tags andattributes) will be removed.@return whitelist