My palms got a little sweaty as I read the replies to the
node concerning security risks with Matt's Scripts. I have never used those, but it got me wondering about my own use of
sendmail. I have been using the examples from the Mouse book
CGI Programming with Perl (even after all their dire warnings about using it at) with decent results (people are getting the e-mails!). I'm still trying to get my head around the security issues and want some XP'ed monks to take a look and tell me if I'm overlooking anything. The
Validate.pm (doing the untainting) is on my
scratchpad (thanks to
chromatic for his help on this module and calling it).
So,
1) Is this secure?
2) Why is it when I add -T to the shebang, I get a
Can't locate Validate.pm in @INC error (works fine without it)?
#!/usr/bin/perl
print "Content-type: text/plain\n\n";
use strict;
use warnings;
use Validate;
use CGI qw(:standard);
my @errors;
my $sendto = Validate->alphanum (param('sendto'));
push @errors, "Missing or invalid addressee\n" unless $sendto;
my $email = Validate->email (param('email'));
push @errors, "Missing or invalid e-mail address\n" unless $email;
# similar untainting for all other user input here, then...
if (@errors) { &printerrors; exit; }
#-----------send email ---------
$sendto .= "\@somewebsite.org";
open(MAIL,"| /usr/lib/sendmail -t") or die "Could not open sendmai
+l: $!";
print MAIL "From: $name\n";
print MAIL "To: $sendto\n";
print MAIL "Subject: $subject\n\n";
print MAIL "E-mail: $email\n\n";
print MAIL "Message: $message\n\n";
print MAIL "\n\n";
close MAIL or die "Could not close sendmail: $!";
print "Thanks for your message.";
exit;
sub printerrors {
for (@errors) { print $_."\n" }
}
__END__
Thank you all!
—Brad
"A little yeast leavens the whole dough."
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.