It takes quite a bit, but once you've mastered a technique or two, it becomes simple habit. Essentially, you should be checking every bit of data that comes in and making sure it contains only what should be allowed. This includes checking lengths of fields (never rely on HTML's 'maxlength' attribute to limit input length) and making sure that any hidden fields contain what you think they do.
The second you find yourself stuffing data into hidden fields, you're most likely wanting to implement a system that maintains user sessions. This way any important information is placed on your server (in some sort of database) where the user can't modify it manually.
You should try restricting the characters used in fields as much as possible (for example, if you are accepting phone numbers, you might try restricting the field to only allow digits, spaces, hyphens and parentheses). And then come checkboxes, radio buttons, select fields. You need to check that the values coming in through these are valid. You might only put 'Chocolate' and 'Vanilla' as options to a select field, but someone can copy the html over and insert their own 'Strawberry' flavour if they'd like.
It's hard to give a full-blown tutorial without writing a book on the subject. Validating data is trivial but at the same time can be a lot of work in some situations. One final note: if you're ever going to use javascript to validate form fields (which is Evil in itself), you still need to validate data on the server side of things. Relying on javascript validation is even worse than relying on the 'maxlength' attribute, because even legit users who are not trying to hack your script apart will be able to submit invalid data if they don't have javascript enabled.
So long post made short: you need to check all incoming data to make sure it is exactly what you are expecting. It's that simple :)
In reply to Re: CGI form data validation
by Anonymous Monk
in thread CGI form data validation
by kiat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |