Whatever message this page gives is out now! Go check it out!

HTML input sanitization for ColdFusion AJAX widgets

Last update:
Sep 6, 2026
Learn when dynamic HTML passed into ColdFusion AJAX widget tags and attributes must be sanitized, and how to use GetSafeHTML() and AntiSamy policy files to do it

When is sanitization required

Hardcoded HTML: no sanitization is needed
If the HTML you're passing into one of these attributes is a literal string you typed in your .cfm file, ship it as-is. You already control it, same as writing <cfoutput>Hi <b>there</b></cfoutput> yourself.
Dynamic HTML: sanitize with GetSafeHTML() before it reaches the tag
If the HTML is built from anything outside your source code, a database column, a query result, a bound URL/CFC response, a form field, a session/cookie value, another user's input, an external API, you must sanitize it first. These widgets render it as real markup; a <script> or onerror= payload in that data executes exactly like it would in <cfoutput>#rawValue#</cfoutput>
HTML rendered by these widgets is interpreted as markup. Untrusted values can therefore introduce active content in the same way as untrusted HTML rendered through cfoutput.

Tags and attributes that render HTML

Here are some examples of sanitizing HTML input. Sanitize dynamic values before passing them to the following tags and attributes.
Tags/attributes that render HTML and when to sanitize
TagAttribute / FieldDynamic contentSanitization
<cfgrid> (via <cfgridcolumn>)Grid cell dataQuery column orbound data sourceRequired
<cfgrid>Group headerSame bound data as cell renderingRequired
<cflayout>Tab titleUsually static, but treat any dynamically-built title as untrustedRequired, if dynamic
<cflayout>Tab tabTipSameRequired, if dynamic
<cflayout>Accordion titleSameRequired, if dynamic
<cfwindow>titleDocs explicitly allow HTML hereRequired, if dynamic
<cfmap>markerWindowContentBound via markerBind — DATA, almost always dynamic in practiceRequired
<cftooltip>Tooltip contentResponse from sourceforTooltip (an AJAX call) — DATARequired
<cfrichtexteditor>Editor contentStored rich text (e.g., previously saved user content) — DATARequired
cfdiv / cfajaxproxy bind sinksAJAX responseText rendered into the pageAJAX responseText rendered into the pageRequired when the bound page contains untrusted data

Sanitize GetSafeHTML() or IsSafeHTML()

Use GetSafeHTML and isSafeHTML for every dynamic value. The following example shows the distinction between the original value, the sanitized value, and a safety check.
<cfoutput>
<cfset dirty = '<a href="https://example.com">link</a><script>alert(1)</script>'>
<cfset clean = GetSafeHTML(dirty)>
<p>Dirty: #EncodeForHTML(dirty)#</p>
<p>Clean: #EncodeForHTML(clean)#</p>
<p>Rendered: #clean#</p>
<p>Is safe? #IsSafeHTML(dirty)#</p>
<p>Is safe? #IsSafeHTML(clean)#</p>
</cfoutput>
IsSafeHTML(value)
Returns true/false; use it to check/flag content, e.g., before saving.
GetSafeHTML(value [, policyFile, throwOnError])
Sanitizes the markup according to an AntiSamy policy and returns the cleaned string. Use this cleaned value for fields that render HTML.

Resolve AntiSamy policy file

GetSafeHTML() / IsSafeHTML() , when run against an AntiSamy policy XML file, gets resolved in this order:
  1. Use explicit policyFile argument. For example, GetSafeHTML(dirty, "path/to/mypolicy.xml")
  2. Set the flag this.security.antisamypolicy = "path/to/mypolicy.xml"; in Application.cfc.
  3. Set default server settings in cfusion/lib/antisamy-basic.xml. Copy cfusion/lib/antisamy-basic.xml as your starting template and edit its <tag>/<attribute> rules for what your app actually needs. For example, antisamy-basic.xml has no <tag name="img"> rule at all, so <img> is stripped by default. If a field genuinely needs images (e.g., cfmap markerWindowContent, or cflayout tabTip, both confirmed used for <img>), add one, following the same pattern as the existing <tag name="a"> rule.
Important: Restart the server after editing a policy file on disk for the change to take effect.

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page