Hi monks,

I would like to be at least certain that my Perl cgi code doesn't fall prey to obvious hack attacks. I'm wondering if I'm on the right right as far cgi security is concerned with the following measures I've taken:

1) taint mode is enabled on the main script

2) fatal_to_browser is turned off

3) use strict is on

4) Perl modules reside in a directory below the web directory (i.e. /usr/home/mysite/perlmodules)

5) Use CGI.pm instead of own code to parse data

6) Every user input goes through the following regex:

# null byte $data =~ s/\x00//g; $data =~ s/"/"/g; $data =~ s/\|/\|/g; # to prevent sql injection $data =~ s/drop/dr0p/ig; $data =~ s/insert/ins3rt/ig; $data =~ s/select/se1ect/ig; # letter 'l' becomes number '1' $data =~ s/delete/de1ete/ig; $data =~ s/alter/a1ter/ig; $data =~ s/update/upd4te/ig; # unix command? $data =~ s/rrm//ig; # javascript $data =~ s/script/skript/ig;
Am I doing the right things? Is there anything terribly obvious that I need to add to the list?

Cheers and many thanks in advance :)

update: I'm using a shared server. I've correctly set the permission to my alloted directory.


In reply to CGI (in)security by kiat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.