http://www.perlmonks.org?node_id=975330


in reply to How to secure a perl script from attacks

I assume that you are using some form of database. In the DBI docs somewhere, it states that you should use placeholders for your data. For example:

# $dbh contains your database handle my $sth = $dbh->prepare( "SELECT * FROM foo WHERE id = ? AND bar = ?" +) or die( "Could not prepare statement: ".$dbh->errstr() ); #of cours +e you will have a more elegant error handling method than just die $sth->execute( $value_for_id, $value_for_bar ); #and then just fetch the data like you would normally.

Placeholders also have the added advantage of reusing your queries. For example:

#Take the same $sth from the previous example my @data_to_query = ( #You would probably get this from somewhere else { id => 763, bar => "baz" }, { id => 923, bar => "qux" }, #...and so forth ); foreach( @data_to_query ) { $sth->execute( $_->{id}, $_->{bar} ); #do something with that dataset }

The advantage of that is not only performance(only need to compile SQL statement once), but the placeholders are replaced with safe data that can be used in the database. Of course, I left out several things like error handling for incorrect or malformed queries, but it is implied that you should have that.


In terms of other security, make sure you use common sense. Hash your passwords and add a salt, ensure that nobody should see data they're not supposed to see, and all other typical web security tips.
Use common sense(and common::sense) and all will be well.

~Thomas~
confess( "I offer no guarantees on my code." );