PDA

Click to See Complete Forum and Search --> : Data validation, how much is enough?


Juridian
February 14th, 2002, 08:08 PM
How much data validation is enough for your web applications? Do you trust client side code to do it? Do you validate at every level?

Personally I think client side is ok for some simple validation and formatting, but trust nothing sent from the client. It's far too easy to write code that changes the form, data sent from the form, etc.

I like to validate everything sent from the client in my asp/jsp/whatever stripping out the bogus characters for the expected data type, trimming it down to the appropriate number of characters or bouncing the user with an error message if necessary, and doing an explicit conversion to the data type I need. I strip out all code delimiting characters and make the appropriate conversions to keep my sql or other code from blowing up. Also I use constants to limit the size of the text boxes and then validate the amount of data sent from the client against those constants and take appropriate action if too much is sent.

Then the data is validated in the com component or other code that talks to the asp/jsp/whatever before sending it off to the database. Same kind of thing, check it's size, type, validity (positive, negative, numerical, etc).

I usually have a nice utils include that holds validation functions of every variety such as validateemail(), validatelong(), etc. for both the web and something similar for the compiled code.

What do you do?

zigar
February 16th, 2002, 12:21 AM
client side is fine...if you only want to make sure someone entered an email address with a @ or similar...other than that...if you don't scour and filter yer gonna get burned...

i use coldfusion so i've got a nice file called application.cfm which every file "passes thru"

in this application.cfm is a cf custom tag which filters sql strings, html, cfml and profanity so every form submission gets filtered.

also setting form field widths is important...undefined lengths...people can submit whatever they want...possibly causing a buffer overflow or who knows what

i also always add user validation feedback to all my form fields...

<SCRIPT>
<cfoutput>alert("#client.error#");</cfoutput>
</SCRIPT>

to let em know why ...


all of this happens with session vars and then when i'm happy... and only then does the form input get to touch my backend...

redgore
February 19th, 2002, 01:22 PM
I cant really comment as i usually allow third parties to do the user interaction parts. I stick to the main frontend

krang
February 19th, 2002, 06:18 PM
I agree Juridian, check everything otherwise there is some element of trust involved. We all know about trust......

Krang

4ChecK
February 20th, 2002, 02:41 PM
ditto -

i validate on the client side, (ASP/JSP), and in the database layer. the more validation the better.l

:zap: