Warning: You have a whopping security hole in your script. Because you don't check that the user-supplied filename is safe, the user could use this script to open (and possible run) any file on your box that the script would have the rights to access.

As for your original question, you have a few options. The easiest is to allow basic authentication and require each user to login in before they can get to your cgi-bin. However, basic authentication sends the data "Base64" encoded, which is plain-text. If you need this secure, this is not a good solution.

You could build a simple password authentication application that controls access to the other applications, but that also won't be terribly secure unless you use SSL, which is really the only way you're going to get decent security. Incidentally, my cgi course has information for a simple authentication program in Lesson 4, part 2. In fact, after looking at your code, I think there are a few other pointers you might appreciate from that course (no offense!).

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to Re: file download security by Ovid
in thread file download security by lonewolf32

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.