EasyCFM.COM ColdFusion Forums / Coding Help! / Input Form Security

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Input Form Security

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

JoeyMetro
05-23-2003 @ 9:11 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 3
Joined: Apr 2003

Hi everyone;

What basic steps should be taken when collecting a user's input?

For example I read somewhere to remove ' and replace them with '' a sql hack.

Can someone provide me with the code they use and why they use it.

Thank you;
Joe

This site is great!

Joey M.
Peace

CJ
05-23-2003 @ 10:37 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

the reason you've heard about replacing single quotes is that SQL uses single quotes to delimit a string.  So if you wanted to insert the string 'John O'Hara' (delimiting the string with the single quotes), you can see where it would fail, as it would see the apostrophe after O as terminating the string.

You don't really need to jump through hoops to insert/update data safely tho.  Just use <cfqueryparam> tags.  There's many reasons to use <cfqueryparam>, and none not to (that I can think of).  It will provide an extra level of security, it will bind the varibles to the database, making your queries significantly faster, and it will handle 'special' characters.

<cfset myName = "John O'Hara">

<cfquery name="insertRecord" datasource="myDSN">
     INSERT into mytable (firstName)
     VALUES (<cfqueryparam value="#myName#" cfsqltype="cf_sql_char">
</cfquery>

As you can see, no need to manually escape any special characters.



CJ
@ #coldfusion/DALNet
http://charlie.griefer.com

Sponsored By...
iOpenSoft, LLC is a Houston, Texas Advanced Technology Studio Specializing in Web Design, Web Development, iPhone App Development and Android App Development.