I am writing a script that will allow teachers to upload files (called activity sheets) via a Web form. The files are then subsequently written out to a directory on the server which has Web access forbidden to everyone via an .htaccess file. Even I, who have root access, cannot access the file through a browser. The file cannot be viewed by the general public until I have manually examined it and determined that it is exactly what it is supposed to be (word processing documents, images, and spreadsheets. Nothing else is allowed) and has no macrovirii. I think this part is relatively secure.
My humble supplication for information from wiser monks is this: what type of security holes exist with a browse button? The relevant Perl code:
.
.
.
use CGI;
my $template = new CGI;
.
.
.
sub storeSheet {
my ($sheet, $file, $data) = @_;
my ($path, $filename);
my $storagePath = "/www/htdocs/documents/activity_sheets/";
# Here we extract the filename and file
$path = $template->param($sheet);
$path =~ m!([^/:\\]*)$!; # capture filename
$filename = $1;
no strict 'refs'; # $filename is a symbolic reference
open (SHEET, ">${storagePath}OSEN${filename}") || die "Can't open
+$filename: $!\n";
while (read($path, $data, 1024)) {
print SHEET $data;
}
close SHEET;
use strict 'refs';
}
I had a devil of a time just finding information about how to do this. I have two concerns.
- What dangers are involved in my using "no strict 'refs';" here and how can I avoid this?
- Users can supply their own path information. I'm not sure how security works here. Can they include a path with backticks and execute their own code? Is there anything else I need to know about this>
Any wisdom on this matter would be greatly appreciated. If their are other concerns, I would love to know about them.
Incidentally, I've reduced this to a minimal test case, so my apologies if I missed anything in the code.
Cheers!
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.