Web Forms: Lifeblood of Your Site or College Roommate?
Posted by Scott Reno on June 15, 2009 | 1 Comment
Website forms are a lot like college roommates: they’re necessary but if you don’t lay down some ground rules things can quickly get out of hand. Whether you’re whipping your class-skipping roommate or your information-gathering forms into shape, the process involves the same basic steps.
Step One: Don’t Overload the Machine
Never let your roommate wash your laundry because he’ll mix the lights with the darks, not empty the pants pockets, and add too much detergent to the machine. Unless you want to wear an all pink wardrobe, teach him the rules to proper laundering.
Verifying form field lengths and data types are much the same. Your forms must only accept the right lengths and types of input or you’re opening the door to hackers and script kiddies, as well as allowing the dreaded Users Who Don’t Pay Attention to enter the wrong information.
Here’s a starting point for some common form fields:
- 25 characters for first and last name fields, alphabetic characters and the apostrophe only
- 12 characters for a phone number, numeric and dashes only
- 5 characters, numeric only for zip codes
- 10 characters, numeric and dashes only for zip plus 4 zip codes
- 500 characters for text areas
- ensure that no required fields are empty
Form verification must occur on the page through JavaScript validation and on the server once the data has been submitted. JavaScript validation allows the user to know that she has entered data incorrectly and Server Side validation prevents hackers and spammers from attacking your site.
While JavaScript validation is important, you can’t count on it to validate data because users can turn it off. Server Side validation ensures that your database and processing scripts remain free of invalid data.
Step Two: Lock Out Unwanted Visitors
Your roommate is fun (if you ignore the filthy pit he calls a bedroom) but you don’t like it when his friends stop by and take over the apartment. Be smart and lock the door so they can party somewhere else.
Creating “tokens” for your forms guarantees that only users with the “key” can enter. Tokens are randomly-generated character strings that are embedded in a hidden field on the form. Long character strings with numbers, upper and lower case letters and punctuation marks are recommended because they are difficult to guess. When these forms are submitted, scripts check to see if the token on the form matches the key on the web server. If they don’t match, then something nefarious is going on. Spam bots and hackers will often ignore hidden fields when submitting forms or just fill them with junk data.
Step Three: Let Your Friends In
Your friends are the polar opposite of your roommate’s: they aren’t loud and obnoxious, they clean up after themselves and they shower on a regular basis. When your roommate’s buddies aren’t looking, quickly let your friends in.
In the world of web forms, your “friends” are on a white list of allowable form fields. When the form is submitted, a script checks the form field name against the white list. If a form field name isn’t on the white list, there was a hacking or spamming attempt made on your form.
Step Four: Keepin’ It Clean
So you’ve been working hard to transform your roommate from a monkey into a suitable companion. He knows how to do laundry, doesn’t bring friends home, and allows you to hang out with your buddies but he’s still not perfect. Change that Dirty Dan into Tidy Tim!
Form data, like your roommate’s hygiene, is often “dirty.” NEVER trust data from a form because it can contain JavaScript, HTML and other programming tags along with the actual data. PHP features the strip_tags command that will remove some of the offending extra information. Additional “cleaning” might be necessary to remove SQL to avoid injection attacks. By cleaning data, you drastically reduce the security risks of receiving data from your forms.
So What Have We Learned Today?
Web forms (and roommates) are unavoidable but they must be whipped into shape or they will get out of hand. By following the four simple rules your forms will be safe against many attacks. Let’s review:
- Verify field lengths and data types through JavaScript and on the Server
- Match tokens on the form to the submission keys
- Create a form field white list
- Clean your data
Tags:forms, roommate, token, validation, whitelist
Filed Under: Marketing, Technology, Uncategorized
Gragg Advertising Twitter
Gragg Advertising Linkedin
Gragg Advertising Facebook














































