String sanitation in coldfusion and any other language is very important and depends on what you want to do with the string. most mitigations for
- storing content in a database (e.g.
<cfqueryparam ...> ) - using the content to display on the next page (for example, put the url parameter in the link or show the url parameter in the text)
- saving files and using files and contents of uploaded files
There is always a risk if you follow the idea of preventing and cutting the string, resolving basically everything in the first step, and then remove the malicious code “away” by deleting or replacing the characters (black list). The best solution is to replace the rereplace(...) lines with regular expressions, which explicitly allow you to use only the characters needed for the script, which you use as a simple solution when possible. cases of entering numbers, lists, email addresses, URLs, names, zip codes, cities, etc. are used.
For example, if you want to specify an email address, you can use
<cfif reFindNoCase("^[A-Z0-9._%+-] +@ [A-Z0-9.-]+\.(?:[AZ]{5})$", stringtosanitize)>...ok, clean...<cfelse>...not ok...</cfif>
(or your own regular expression). For HTML-Imput or CSS-Imput, I would also recommend the OWASP Java HTML Sanitizer Project .
source share