Sanitization of raw HTML, attributes, and JSON.
\Nullai\Hygiene\SanitizeHtml
class offers methods for safely sanitizing HTML, attributes, and JSON data. These tools ensure that your application is protected against common injection vulnerabilities and XSS attacks.
\Nullai\Hygiene\SanitizeHtml::escHtml()
method escapes special characters in a string to ensure it is safe for rendering in an HTML context.
<
, >
, and &
, converting them into their respective HTML entities.
Output is safe to use within HTML tags or content.<
, >
, "
, '
, and &
, to ensure it is safe for use in HTML attributes.
Prevents injection vulnerabilities within attribute values.\Nullai\Hygiene\SanitizeHtml::escJson()
method sanitizes data and safely encodes it as JSON for embedding in JavaScript.
<
, >
, &
, '
, and "
using hexadecimal escape sequences, preventing JavaScript injection vulnerabilities.escJson()
method uses json_encode()
with the following flags: JSON_HEX_TAG
, JSON_HEX_APOS
, JSON_HEX_AMP
, and JSON_HEX_QUOT
:
<
as \u003C
>
as \u003E
&
as \u0026
'
as \u0027
"
as \u0022
escHtml()
and escAttr()
to ensure dynamic content is safely rendered in HTML.escJson()
before embedding in JavaScript.\Nullai\Hygiene\SanitizeHtml
help ensure your application maintains robust defenses against XSS and injection vulnerabilities while simplifying safe handling of dynamic content.