Sanitizes unsafe HTML to protect against XSS attacks
sanitizeHtml(string [, policy ])
returns string
string.sanitizeHTML( policy )
Name | Type | Required | Default | Description | Values | |
---|---|---|---|---|---|---|
string | string | Yes | The string to sanitize | |||
policy | string | No | Either a org.owasp.html.PolicyFactory or a list of built in policies which allow and sanitize the named element types (see list below). If omitted then all of the built-in policies are applied. | /Users/garethedwards/development/github/cfdocs/docs/functions/sanitizehtml.md | TABLES |
Sanitize a string using built-in policies
unsafe = '<p>a <strong>link</strong> <a href="https://www.example.com" onClick="doSomethingBad()">test</a></p>';
result = sanitizeHtml( unsafe );
dump(result);
Only allow sanitized link and block elements
unsafe = '<p>a <strong>link</strong> <a href="https://www.example.com" onClick="doSomethingBad()">test</a></p>';
result = sanitizeHtml( unsafe,"LINKS,BLOCKS" );
dump(result);
Only allow sanitized link and block elements
unsafe = '<p>a <strong>link</strong> <a href="https://www.example.com" onClick="doSomethingBad()">test</a></p>';
result = unsafe.sanitizeHtml( "LINKS,BLOCKS" );
dump(result);