stumbler has asked for the wisdom of the Perl Monks concerning the following question:
I am running perl cgi scripts on Apache (1.3.33) webserver.
I have set-up individual working directories for all users in the path,say, /usr/local/wd/<unique user id>
If user 'sam' logs in and executes some programs, the logfiles are stored in the path /usr/local/wd/sam/.
I have written a perl-cgi script to view the log files using HTML::Templates.
CGI script
# Create the HTML Page from the Templates print $query->header(); $user = ... #get username $log_file = .... #get logfile my $template = "err.tmpl"; # Instantiate a new HTML::Template object my $template = HTML::Template->new( filename => $template ); $template->param( username => $user ); $template->param( log_file => $log_file ); # Generate the HTML page print $template->output();
Template File (err.tmpl)
<html> <head><title>Show Log Files</title></head> <body > <script> function show_file(){ window.open('/wd/<tmpl_var name = "username">/<tmpl_var name = "log +_file">') ; } </script> <form method="post" enctype="application/x-www-form-urlencoded" name=" +results"> <table align="center"> <tr><td><a href="javascript:show_file()">Log File</a></td></tr> </table> </form></body></html>
As I have set a soft link for 'wd' to '/usr/local/wd/' , I am able to open the link and view the logfile and everything seemed to be fine.
Then, I realized that by pasting the url ( say http://host.com/wd/sam/logfile1.log ) in the browser,I am able to view the logfile. Also, it opens up the possibility that I can paste http://host.com/wd/ and look at all the folders and files of all users as the webserver runs as a special user.
I am not sure how to prevent this if someone tries to access the folders in the above approach. ( I use CGI::Session to keep track of 'logged in' status of the user for all other pages but when it comes to viewing the logfiles, it goes out of control of CGI::Session )
Looking for some suggestions on how to handle this securely.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl CGI - Viewing logfiles - Security Issues
by Melly (Chaplain) on Jan 10, 2007 at 16:39 UTC | |
by Anonymous Monk on Jan 10, 2007 at 17:28 UTC | |
by wfsp (Abbot) on Jan 10, 2007 at 18:02 UTC | |
by stumbler (Acolyte) on Jan 10, 2007 at 18:41 UTC | |
by Melly (Chaplain) on Jan 10, 2007 at 19:09 UTC | |
|
Re: Perl CGI - Viewing logfiles - Security Issues
by Anonymous Monk on Jan 10, 2007 at 16:33 UTC | |
|
Re: Perl CGI - Viewing logfiles - Security Issues
by Sagacity (Monk) on Jan 11, 2007 at 03:12 UTC | |
|
Re: Perl CGI - Viewing logfiles - Security Issues
by Anonymous Monk on Jan 11, 2007 at 08:05 UTC |