Hello Monks,

I am setting up a small web ap using CGI. We are using it to keep track of updates and other tweaks to our applications.

What I want to do is upload images and word docs to our server using some small formatting. I have figured out how to do this. However the question is should I do this and what are some measures I can take to safeguard this.

I'm only allowing access to a certain group to read/write to the directory and have turned off all scripts inside of the dir that i'm writing to.

Here is the relevant code I have so far.

#! C:\perl\bin\perl -w use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use BKG::HTML::format; # Some Security Holes Plugged $CGI::POST_MAX = 100 * 1024 * 1024; # limit posts to 100M max my $q = new CGI; ################# # Get form data # ################# $T=1; $x=1; while ($T) { $test1 = "name_upfile" . $x; $test2 = "upfile" . $x; if (($q->param($test1)) and ($q->param($test2))) { $file_name[$x-1] = $q->param($test1); $file[$x-1] = $q->upload($test2) or die "test:$!"; $x++; } else { $T=0 } } mkdir "C:/web/aps/mi/$name", 0755 or die "Cannot make dir: $!"; $x=0; foreach (@file_name) { open (OUTFILE, ">C:/web/aps/mi/$name/$_") or die "Cannot open $nam +e: $!"; binmode(OUTFILE); while ($bytesread=read($file[$x],$buffer,1024)) { print OUTFILE $buffer; } close OUTFILE or die "Close:$!"; $x++; }

Any and all thoughts are welcome.

In reply to Security Uploading Files by bkiahg

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.