I'm wanting to add a dictionary lookup at my website that just directly interfaces with the availabe dict shell command. I also want to do this securely. How should I go about doing this? —Not the implementation, but the sanitizing of data before it is passed through to qx// (the shell)?

Basically what I've got so far:

use CGI; use My::QXcall; $cgi = CGI->new(); my(@terms) = $cgi->param('t'); # do stuff sanitize input data, etc. foreach (@terms) { $_ =~ s/(?:^\s)|(?:\s$)//o; # trims leading/trailing whitespace # [other stuff I should be doing would go here...] } # look up terms with dict print QXcall(qq{dict ${\ scalar join(' ', map { "'" . quotemeta($_) . "'" } @terms) }});

Does that code do enough in the way of security? I'm wondering if taint should be figuring in here somewhere...or something(s) else?

...And by the way, here's the non-standard "My" module referenced in the above code if you'd like to see it to get some more context:

package My::QXcall; use strict; use vars qw( $VERSION @ISA @EXPORT ); use Exporter; @ISA = qw( Exporter My ); $VERSION = 0.00_1; # Wed Jun 11 17:14:17 CDT 2003 @EXPORT = qw( QXcall QXstatus QXsignal QXerror QXoserror QXerrli +ne ); our($STAT, $SIG, $ERR, $OSERR, $LINE); sub QXcall { undef($STAT); undef($SIG); undef($ERR); undef($OSERR); undef($LINE); my($call,$errmsg) = @_; my(@call) = `$call`; $STAT = $? >> 8; $SIG = $SIG{ $? & 127 } || $? & 127; if ($STAT) { $OSERR = $^E; $LINE = (caller)[2]||'?'; $ERR = $errmsg ? $errmsg . NL : '' . join("\n",@call) . qq[syscall failed with status $STAT, signal $SIG] . "\n"; } @call } sub QXstatus { $STAT } sub QXsignal { $SIG } sub QXerror { $ERR } sub QXoserror { $OSERR } sub QXerrline { $LINE } 1;

Thanks everyone!

--
Tommy Butler, a.k.a. Tommy

In reply to Safely passing CGI form data to a shell command by Tommy

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.