Xss
class Xss (View source)
Provides helper to filter for cross-site scripting.
Properties
| static protected array | $adminTags | The list of HTML tags allowed by filterAdmin(). |
|
| static protected array | $htmlTags | The default list of HTML tags allowed by filter(). |
Methods
Filters HTML to prevent cross-site-scripting (XSS) vulnerabilities.
Applies a very permissive XSS/HTML filter for admin-only use.
Processes an HTML tag.
Processes a string of HTML attributes.
Whether this element needs to be removed altogether.
Gets the list of HTML tags allowed by Xss::filterAdmin().
Gets the standard list of HTML tags allowed by Xss::filter().
Details
static string
filter($string, array $html_tags = NULL)
Filters HTML to prevent cross-site-scripting (XSS) vulnerabilities.
Based on kses by Ulf Harnhammar, see http://sourceforge.net/projects/kses. For examples of various XSS attacks, see: http://ha.ckers.org/xss.html.
This code does four things:
- Removes characters and constructs that can trick browsers.
- Makes sure all HTML entities are well-formed.
- Makes sure all HTML tags and attributes are well-formed.
- Makes sure no HTML tags contain URLs with a disallowed protocol (e.g. javascript:).
static string
filterAdmin(string $string)
Applies a very permissive XSS/HTML filter for admin-only use.
Use only for fields where it is impractical to use the whole filter system, but where some (mainly inline) mark-up is desired (so \Drupal\Component\Utility\Html::escape() is not acceptable).
Allows all tags that can be used inside an HTML body, save for scripts and styles.
static protected string
split(string $string, array $html_tags, string $class)
Processes an HTML tag.
static protected string
attributes(string $attributes)
Processes a string of HTML attributes.
static protected bool
needsRemoval($html_tags, $elem)
Whether this element needs to be removed altogether.
static array
getAdminTagList()
Gets the list of HTML tags allowed by Xss::filterAdmin().
static array
getHtmlTagList()
Gets the standard list of HTML tags allowed by Xss::filter().