Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: How to secure a perl script from attacks

by thomas895 (Chaplain)
on Jun 09, 2012 at 19:40 UTC ( #975330=note: print w/replies, xml ) Need Help??

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.

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://975330]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2018-06-24 03:37 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.