Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

CGI Contact Form / Mailer

by vladb (Vicar)
on Feb 13, 2006 at 18:44 UTC ( #529891=sourcecode: print w/ replies, xml ) Need Help??

Category:
Author/Contact Info Apologies for literally assaulting you with my "yet another" cgi mail script. I sincerely hope no harm has been done. Vladb.
Description: Please use NMS scripts.

Comment on CGI Contact Form / Mailer
Re: CGI Contact Form / Mailer
by merlyn (Sage) on Feb 14, 2006 at 02:01 UTC
    There's a potential spam issue, because your error checking is poor. However, since you don't provide a sample template, I can't be sure.

    Your code:

    defined $from && $from =~ m/.+\@.+/
    doesn't forbid a newline. If that newline is inserted into the header of the message, a spammer can create an arbitrary subject and sender, and then a blank line, permitting an arbitrary body. Sure, your added header and sender will be at the bottom of the message, but at that point, who cares?

    Also, just being able to send a message to a recipient designated by a form field is considered very bad manners in this day and age. Please discontinue the promotion of your mailscript.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Thanks for the catch, merlyn. But ...

      if you examine the script closer, it is not mandating the use of any form fields to determine the recepient. Instead, the script is relying on internal config to determine these values. There's only an option to include the form field that is available to the user. Although, I admit, I may have to include a disclaimer about potential risks involved in using such form field. Yet, I did use similar script on some of my clients' internal company servers for feedback collection, in which case, a hidden form field containing recepient email address wouldn't pose any threat. This does appear to be a case of an older feature making it's way to the final revision. Which, as you pointed out, may not be a good thing.

      In fact, the only form field "required" to run the script is the special _mf_ parameter. And even that may be omitted if the script is using the default config only. Also the parameter is retreived from the outside environment in a safe manner:
      my $mf = $cgi->param('_mf_'); $mf =~ s/\.\/\\//g; # remove . \ / chars $mf ||= "default";
      The rest is and should be all configured via internal .conf files, further minimizing any outside tampering with the script. Additional security measure could be to taint check the rest of 'information' fields that are being sent along with the email.

      conf/default.conf
      # smtp server SMTP_HOST=mail.yourhost SMTP_PORT=110 SMTP_TIMEOUT=60 # name form imputs which are lists (comma separated) # FORM_INPUT_LISTS= # recipient email RECIPIENT=myemail@myhost.com # sender field required REQUIRE_SENDER=no # sender field (from html form) SENDER_FIELD=EMAIL # subject (could contain html::template variables!) SUBJECT=Contact From <TMPL_VAR NAME>, <TMPL_VAR COMPANY> # mail template (to the recipient) MAIL_TMPL=mail #------------- CONFIRM ------------ # sender template (optional) # mail to be sent to the sender CONFIRM_MAIL_TMPL=mail_confirm # subject of the confirmation email CONFIRM_SUBJECT=Thank you for your interest in ... # CONFIRM_REPLYTO=mycontact@myhost.com #------------- OK ----------------- # redirect when mail was sent ok # REDIRECT_OK=/thankyou.shtml # template to use on successful send # (overrides redirect_ok) # # TMPL_OK=<template path> #------------- FAIL --------------- # redirect when couldn't send mail and other non system errors # # REDIRECT_FAIL=<url path> # template to use on failure # (overrides redirect_fail) # TMPL_FAIL=fail #----------- USER ERROR ----------- # template for usage error page # TMPL_USER_ERROR=user_error # redirect url on user (usage) error # (user_error_tmpl will be ignored) # # REDIRECT_USER_ERROR=<url path>
      You are right on the other items though, and I admit script needs alittle rework around potential security holes.

      And yet, despite of all said, I am baffled that having made the effort to package and give the script away, I'm simply asked to fold it back. It truly is a disappointing loss of my time ...

      Please, don't take me wrong though. I do thoroughly appreciate the fact that unlike others who chose to -- this contribution, you actually made the effort and took some of your scarce time to include an explanation for doing so.


      _____________________
      "We've all heard that a million monkeys banging on a million typewriters will eventually reproduce
      the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true."

      Robert Wilensky, University of California

        And yet, despite of all said, I am baffled that having made the effort to package and give the script away, I'm simply asked to fold it back. It truly is a disappointing loss of my time ...
        I guess my statement regarding the world not needing yet another mailform program is driven by two things:
        • The damage done by Matt Wright with his buggy mailform script
        • The excellent work done by the NMS team to both recreate an upward compatible replacement, and continue to maintain and support the script for free
        If you were not aware of the NMS version of mailform, perhaps a bit more research on your part would have been advised. It would have saved you time and resources. You could have used that time to create something unique, instead of retreading a far-too-rewritten area, and poorly.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.

Re: CGI Contact Form / Mailer
by davorg (Chancellor) on Feb 14, 2006 at 13:48 UTC

    You might like to consider the nms formmail instead.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: CGI Contact Form / Mailer
by chanio (Priest) on Feb 14, 2006 at 16:19 UTC
    Besides the true reasons previously exposed, I should add that your site is very nicely designed. And that I like the images that you chose. Specially this one: customers.jpg

    The whole aspect of the site is very simple and clean. And speaks a lot about what could be expected of the work done. I like the spaces left between the information.

    I share your pride of having your good code working as expected. I also did my own form mailer. It was my first code done with CGI::Application and HTML::Template. But I wouldn't show it here, since it might be far from being perfect in what today matters: security, ecology, style, etc.

      Thanks for the good mention, chanio. Frankly, I have no idea why, say, I never took the time to look into NMS. I still believe my script is different and I'll stick to using it, with a few minor security fixes in place. Personally, I believe it's different from the one offered through NMS and I find (oddly enough, heh) it to be easier to use. Since I began writing my own mailer script some three years ago (at which time, I doubt, NMS version was in place anyway), it's been always a work in progress.

      Looking back, I don't know what devil pushed me to package it up for public consumption. I should really think twice next time.. or at the least, maybe post it in the Discussion session for some constructive criticism.


      _____________________
      "We've all heard that a million monkeys banging on a million typewriters will eventually reproduce
      the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true."

      Robert Wilensky, University of California

        Well, I used to like Matt's scripts, anyway. He had the spirit of the first american people that populated North America. In other words, he did it all by himself. Not using CPAN modules.

        Then, other fans like me (or that just wanted to correct Matt's big and famous mistakes: NMS), rewrote all those well known scripts correcting all their security flaws and adding some tested modules.

        Why? Because, modules are like 'cans' of experience in specific aspects. I wouldn't dare to write better ones without spending some years in the effort. They are done by people that have to deal with certain issues because of their work and afterwards they decide to share their experience with the perl community to make all our jobs easier, better and 'safer'.

        Normally, after trying coding all by myself (without any module), the next step is doing a newer version all handled by modules. It is very easy after I have understood all what was required to do it on my own. It is a safer code because there are lots of security aspects to take into acount in order to put my code in the web.

        We all have to learn this lesson, since it is never well explained from the start. Don't worry. Next code published, try to do it simpler or with modules. That's all!

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://529891]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2014-11-23 01:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (127 votes), past polls