Attention, Web 2: with infinite power comes infinite liability.
If you don’t properly untaint your CGI variables, I can launch an XSS attack on you really easily. I just input <script language=”javascript” /> for one of your fields, and I can run JS via your website. In fact, I can completely change your website’s appearance and functionality (or get your cookies), thanks to DOM manipulation.
Setting character limits on forms isn’t much of a help, because I can GET or POST whatever the heck I want. You have to trust the client’s HTTP headers, which don’t have to be what the browser would normally serve. In fact, with Perl’s LWP, I can send you arbitrary headers. (Firefox even has a built-in hidden feature to change the User-Agent string.)
Basically, you should escape any suspicious characters. < and > are definite no-gos, and & and “ might be suspicious as well. Run some regexps to convert them into HTML entities. Be sure to turn on taint checking (#!/usr/bin/perl -T) so it’s actually enforced.
It’s even worse when you run SQL statements. SQL injection is awful because I can DROP your table from the database instantly, instead of the innocuous INSERT you wanted. – and ‘ are prime culprits. Better yet, just use the quoting feature built into Perl’s DBI. Pass inputs in execute() rather than concatenating them in your prepare() statement.
Above all, I hope you never concatenate user input to the console! (rm -r *) Of course, some major websites forget to protect against SQL injection. Occasionally I find a URL ending in ?id=5 that returns a database error if you delete the 5. (Yes, this is REALLY BAD NEWS.)
Until next time, may you never SELECT * FROM table WHERE id=’$querystring’.