Skip to main content
Inspiring
July 10, 2009
Question

htmleditformat & Database Field Lengths

  • July 10, 2009
  • 1 reply
  • 1989 views

I happened across an article about SQL injection, a topic I frequently look back into to see what new threats have been discovered, and this particular author was pushing for the use of htmleditformat on all form data being inserted into a database. Now I have coded and secured several different websites against SQL injection, each using simlar to slightly-varied techniques at blocking those pesky hackers, so my question is not how to prevent SQL injections, but instead my question is more about htmleditformat and database field lengths.

htmleditformat on user-inserted data is part of my SQL injection prevention scheme, but on rare occasion I have this problem:

Let's say I have a field in my database for the user's first name, with a generous length of 20 characters.

The user's name, just as an example, is 18 characters long. No problem, right?

But let's say that user's name has a symbol, or foreign language character, that then gets converted by htmleditformat behind the scenes? Suddenly that 18 characters balloons up to 23 characters, generating an error because my CFQUERYPARAM maxlength is 20, not to mention the field in the database.

So, for those who do scrub user data with htmleditformat, how do you handle this, if at all?

    This topic has been closed for replies.

    1 reply

    Participating Frequently
    July 14, 2009

    I don't apply htmleditformat to data before saving it to the database

    primarily because that data might be displayed in non-HTML contexts.

    In my opinion htmleditformat should be applied when outputting the

    data to html.

    Mack

    Inspiring
    July 14, 2009

    I agree with mack. HtmlEditFormat is intended for displaying strings, not making them safe.  You might try using the StripHtml or SafeText user defined functions from cflib.org to remove undesired HTML from your input.

    http://www.cflib.org/udf/stripHTML

    http://www.cflib.org/udf/SafeText