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.


In reply to Perl CGI - Viewing logfiles - Security Issues by stumbler

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.