CFPARAM for Simple String Validation
With the addition of a dozen new
type values for the
cfparam tag in ColdFusion 7, it has become a handy tool for validation.
I have a little trick for those of you who are using earlier versions of ColdFusion that don't support the new types for validation. One of the
type attribute values that has been supported for quite some time is the
This is handy for validating that a simple one word string has been been passed. According to the docs a
varaiblename starts with a letter, underscore (_), or Unicode currency symbol, and contains letters, numbers, underscores, periods, and Unicode currency symbols, only. This means that this type has safety from cross site scripting attacks, and sql injection attacks.
The code may look something like this:
<cfparam name="url.action" type="variablename" default="edit">
If you have ColdFusion 7 you can one up this and limit the values passed in with a simple regular expression:
<cfparam name="url.action" default="edit" type="regex" pattern="(new|edit|delete)">
The regex example only allows the string's
delete to be passed in. That's a solid way to validate our input strings.
Wouldn't it be nice however if you could do something like this:
<cfparam name="url.action" type="finite" list="new,edit,delete">
Like this? Follow me ↯Tweet Follow @pfreitag
CFPARAM for Simple String Validation was first published on May 29, 2007.
If you like reading about security, validation, cfparam, strings, xss, sql injection, or regex then you might also like:
- Announcing Web Application Firewall for ColdFusion
- Web Application Vulnerabilities trump Buffer Overflows
- CFParam for Integer or Empty String
- Firefox Aurora now Supports Content Security Policy 1.0
- HackMyCF Scanner Updated
- Using AntiSamy with ColdFusion
- How to Get a Green SSL Certificate
- Risks of FCKeditor Vulnerability in ColdFusion 8
The FuseGuard Web Application Firewall for ColdFusion & CFML is a high performance, customizable engine that blocks various attacks against your ColdFusion applications.