getSafeHTML() sanitizes the given input string based on the the rules specified in an antisamy policy file. This can be used to prevent unwanted user supplied HTML being used in an application.


Returns the sanitized input. If throwOnError is set to true, it returns an error. Otherwise, it returns an empty string.


GetSafeHTML(string [,policyFile, throwOnError])


ColdFusion 11: Added this function

See Also






Required. The string to be encoded.


Optional. File path for antisamy policy file which specifies HTML rules. In case if not specified, there is a provision to set this at application level. Else the default policy file shipped with ColdFusion will be used.


Optional. If set to true, exception is thrown.


The following example illustrates a sample Antisamy component:

<cfset = "antisamy.xml">

The following example illustrates isSafeHTML and getSafeHTML validation.

In the example, the input HTML file is a GIF image. On processing it through the functions (isSafeHTML, getSafeHTML), checks if the given input string violates the rules specified in antiSamy policy file and returns true if the input does not violate the allowed HTML rules.

<cfset isSafe = isSafeHTML(inputHTML)>
<cfset SafeHTML = getSafeHTML(inputHTML, "", true)>
<cfoutput> is Safe : #isSafe# Safe HTML : #SafeHTML# </cfoutput>


maxInputsize directive of antisamy specifies the maximum size of user input before it gets validated. antisamy-basic.xml, which was shipped by ColdFusion 11, restricts the input to 5000 characters. If the input supplied to this function is greater than 5000, you get an error. However, you can change this limit according to your requirement. Removing this directive from the antisamy-basic.xml sets the default limit to 100,000.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy