HTML_Sanitizer
in package
Sanitize HTML body content
Remove dangerous tags and attributes that can lead to security issues like XSS or HTTP response splitting
Table of Contents
Properties
- $allowDOMEvents : bool
- $additionalTags : string
- $allowedTags : string
- $allowJavascriptInUrls : bool
- $allowObjects : bool
- $allowScript : bool
- $allowStyle : bool
Methods
- __construct() : mixed
- Constructor
- allowAllJavascript() : void
- Helper to allow all javascript related tags and attributes
- allowDOMEvents() : void
- Allow DOM event on DOM elements
- allowJavascriptInUrls() : void
- Allow the use of javascript: in urls
- allowObjects() : void
- Allow object, embed, applet and param tags in html
- allowScript() : void
- Allow script tags
- allowStyle() : void
- Allow style tags and attributes
- filterHTTPResponseSplitting() : string
- Filter URLs to avoid HTTP response splitting attacks
- removeDOMEvents() : string
- Remove DOM events attributes from html tags
- removeDOMEventsCallback() : string
- Callback for PCRE
- removeJavascriptURL() : string
- Remove potential javascript in urls
- removeStyle() : string
- Remove style attributes from html tags
- removeStyleCallback() : string
- Callback for PCRE
- resetAll() : void
- (re)set all options to default value
- sanitize() : string
- Sanitize HTML remove dangerous tags and attributes clean urls
- sanitizeSrcCallback() : string
- Callback for PCRE
- sanitizeURL() : string
- Remove potential flaws in urls
- sanitizeURLCallback() : string
- Callback for PCRE
- removeEvilAttributes() : string
- Remove dangerous attributes from html tags
- removeEvilTags() : string
- Remove dangerous HTML tags
- sanitizeHref() : string
- Remove potential flaws in href attributes
- sanitizeSrc() : string
- Remove potential flaws in href attributes
Properties
$allowDOMEvents
public
bool
$allowDOMEvents
$additionalTags
private
string
$additionalTags
$allowedTags
private
string
$allowedTags
$allowJavascriptInUrls
private
bool
$allowJavascriptInUrls
$allowObjects
private
bool
$allowObjects
$allowScript
private
bool
$allowScript
$allowStyle
private
bool
$allowStyle
Methods
__construct()
Constructor
public
__construct() : mixed
allowAllJavascript()
Helper to allow all javascript related tags and attributes
public
allowAllJavascript() : void
Tags
allowDOMEvents()
Allow DOM event on DOM elements
public
allowDOMEvents() : void
Tags
allowJavascriptInUrls()
Allow the use of javascript: in urls
public
allowJavascriptInUrls() : void
Tags
allowObjects()
Allow object, embed, applet and param tags in html
public
allowObjects() : void
Tags
allowScript()
Allow script tags
public
allowScript() : void
Tags
allowStyle()
Allow style tags and attributes
public
allowStyle() : void
Tags
filterHTTPResponseSplitting()
Filter URLs to avoid HTTP response splitting attacks
public
filterHTTPResponseSplitting(string $url) : string
Parameters
- $url : string
-
url
Tags
Return values
string —filtered url
removeDOMEvents()
Remove DOM events attributes from html tags
public
removeDOMEvents(string $str) : string
Parameters
- $str : string
-
html tag
Tags
Return values
string —filtered html tag
removeDOMEventsCallback()
Callback for PCRE
public
removeDOMEventsCallback(array<string|int, mixed> $matches) : string
Parameters
- $matches : array<string|int, mixed>
Tags
Return values
stringremoveJavascriptURL()
Remove potential javascript in urls
public
removeJavascriptURL(string $str) : string
Parameters
- $str : string
-
url
Tags
Return values
string —filtered url
removeStyle()
Remove style attributes from html tags
public
removeStyle(string $str) : string
Parameters
- $str : string
-
html tag
Tags
Return values
string —filtered html tag
removeStyleCallback()
Callback for PCRE
public
removeStyleCallback(array<string|int, mixed> $matches) : string
Parameters
- $matches : array<string|int, mixed>
Tags
Return values
stringresetAll()
(re)set all options to default value
public
resetAll() : void
sanitize()
Sanitize HTML remove dangerous tags and attributes clean urls
public
sanitize(string $html) : string
Parameters
- $html : string
-
html code
Tags
Return values
string —sanitized html code
sanitizeSrcCallback()
Callback for PCRE
public
sanitizeSrcCallback(array<string|int, mixed> $matches) : string
Parameters
- $matches : array<string|int, mixed>
Tags
Return values
stringsanitizeURL()
Remove potential flaws in urls
public
sanitizeURL(string $url) : string
Parameters
- $url : string
-
url
Tags
Return values
string —filtered url
sanitizeURLCallback()
Callback for PCRE
public
sanitizeURLCallback(array<string|int, mixed> $matches) : string
Parameters
- $matches : array<string|int, mixed>
Tags
Return values
stringremoveEvilAttributes()
Remove dangerous attributes from html tags
protected
removeEvilAttributes(string $str) : string
Parameters
- $str : string
-
html tag
Tags
Return values
string —filtered html tag
removeEvilTags()
Remove dangerous HTML tags
protected
removeEvilTags(string $str) : string
Parameters
- $str : string
-
html code
Tags
Return values
string —filtered url
sanitizeHref()
Remove potential flaws in href attributes
protected
sanitizeHref(string $str) : string
Parameters
- $str : string
-
html tag
Tags
Return values
string —filtered html tag
sanitizeSrc()
Remove potential flaws in href attributes
protected
sanitizeSrc(string $str) : string
Parameters
- $str : string
-
html tag
Tags
Return values
string —filtered html tag