Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Greetings Gracious Monks of the Monastery!
I'm working on a simple newsletter script that receives email addresses from a form and stores them in a file. Here is what I have so far:
#!/usr/bin/perl -wT use strict; use CGI; use Email::Valid; # retrieve form parameter(s) my $q = new CGI; my $tainted_email = $q->param("email"); # check that $tainted_email is valid my $is_valid = Email::Valid->address('$tainted_email'); # if $tainted_email is valid, store the address in $email my $email = ""; if ($is_valid) { $email = $tainted_email; } # grab user information my $ip_address = $ENV{REMOTE_ADDR}; my $referrer = $ENV{HTTP_REFERER}; if ($email) { # store the data in a plain text file open LOG, ">>newsletter.txt" or die "Cannot Access Logfile: $!" print LOG "$email : $ip_address : $referrer\n"; close LOG; } # print thank-you page
The checks based on whether or not $tainted_email is valid seem rather messy to me. My primary concern is validating all the parameters that aren't sent to the script, including the IP address and the referrer. I want to ensure they're of valid structure, and of valid length. I'm also looking for a simple-as-possible storage mechanism for them (escaping issues?).
Also - I don't have access to httpd.conf but I'd like to ensure no one can read the files the info is stored in. Is there a simple way to do this (ie file permissions? I'm not sure what user the webserver is running as), or do I have to have .htaccess files enabled? Thank you for your time :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Subscription form script
by tcf22 (Priest) on Aug 06, 2003 at 12:12 UTC | |
by Anonymous Monk on Aug 06, 2003 at 12:16 UTC | |
by tcf22 (Priest) on Aug 06, 2003 at 14:10 UTC | |
|
Re: Subscription form script
by bobn (Chaplain) on Aug 06, 2003 at 13:21 UTC | |
by Anonymous Monk on Aug 06, 2003 at 13:56 UTC | |
|
Re: Subscription form script
by waswas-fng (Curate) on Aug 06, 2003 at 14:26 UTC | |
by Anonymous Monk on Aug 06, 2003 at 16:26 UTC | |
by waswas-fng (Curate) on Aug 06, 2003 at 18:25 UTC | |
by Anonymous Monk on Aug 07, 2003 at 00:49 UTC | |
by waswas-fng (Curate) on Aug 07, 2003 at 02:23 UTC |