Sanitizes unsafe HTML to protect against XSS attacks
sanitizeHtml(string [, policy ])
→ returns string
string.sanitizeHTML( policy )
BLOCKS
FORMATTING
IMAGES
LINKS
STYLES
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);
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.