Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

How to secure a perl script from attacks

by romy_mathew (Beadle)
on Jun 09, 2012 at 18:44 UTC ( #975326=perlquestion: print w/replies, xml ) Need Help??

romy_mathew has asked for the wisdom of the Perl Monks concerning the following question:

I created a E-commerce site. I have maintained basic rules like 1. Never trust a user information, 2. Taint checking.

Apart from this how do I make sure my perl scripts are secure and prevent database injection attacks etc...

Is there any books that I can be used to refer for adding security

  • Comment on How to secure a perl script from attacks

Replies are listed 'Best First'.
Re: How to secure a perl script from attacks
by thomas895 (Deacon) on Jun 09, 2012 at 19:40 UTC

    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." );
Re: How to secure a perl script from attacks
by ww (Archbishop) on Jun 09, 2012 at 21:37 UTC

    "Is there any books...?"

    Grammar aside, yes. Some are even referenced here: Doubtless Amazon, B&N or your local bookstore could suggest more. Then you could browse some, pick a few that you seem to suit your needs, and ask a far more useful and reasonable question, such as

    "Are there are of these the Monks especially recommend (OR recommend against?

    Is there any reason you didn't take self-help(-first) route?

    As to securing scripts... depends on a host of other details you didn't tell us: who's running the server, how well hardened is it, and at what level of security is your security "good enough" for your risk level and tolerance?

    PS: Fraud protection is also an important element for an e-Commerce site. Who's handling the money? Checking creditcard validity?

Re: How to secure a perl script from attacks
by CountZero (Bishop) on Jun 10, 2012 at 07:43 UTC
    Start by using a well tested and existing framework such as Catalyst, Dancer or Rose and you will have eliminated already a lot of common low-level vulnerabilities.


    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
      Such as?
Re: How to secure a perl script from attacks
by zentara (Archbishop) on Jun 10, 2012 at 10:07 UTC
Re: How to secure a perl script from attacks
by pemungkah (Priest) on Jun 11, 2012 at 22:43 UTC
Re: How to secure a perl script from attacks
by Anonymous Monk on Jun 10, 2012 at 07:33 UTC

    I created a E-commerce site ...

    Great, what is it, I'd like to steal all your money?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://975326]
Approved by Perlbotics
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2021-03-06 14:57 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (116 votes). Check out past polls.