The objective was to write a simple HTTP server that supported resuming of downloads via the Range heeaders. The server should also be fairly secure, as it runs unattended on my firewall box, and thus, it should also not require any fancy setup that could be misconfigured.

The server must be run with the taint option of Perl for even more security. I toyed with the idea of locking the server in a chroot() jail, but getting Perl/HTTP::Daemon to work in such a jail is no easy feat, so I ditched the idea (see objective above).

The server works under both, Win32 and Unix, but under Win32 it dosen't support fork, as the fork emulation is not always working for me. In the spirit of simplicity, it also dosen't support any CGI capabilities, since CGI capabilities present a security hole waiting to be exploited. Also, "hidden" files starting with a dot (".") are not available for download as well. On the upside, the server fully supports persistent connections.

Of course, the total number of lines is arbitrarily set at 99 lines, as there is much whitespace to be compressed, but I wanted to keep a sensible mix of obfuscation/compression and readability, as I think that maybe other people than me would want to use this code.

Command line options

perl -wT miniserver.pl [document_root]

Disclaimer

Even though I tried to be as paranoid as possible about my own code, I can't guarantee that the code is secure in any way other than taking up valuable CPU time and/or disk space. If you find any interesting exploits, please add them in a reply here, so others can learn from my mistakes.

2001-10-05 Update: Fixed small germanism thanks to John M. Dlugosz

2001-10-05 Update: Fixed missing use strict; at the top of the script. Thanks to ybiC for mentioning it to me. My Pascal upbringing seems to have protected me against violating strict, as no code rework was necessary...

2004-07-11 Update: Fixed _stamp routine so it actually displays a useful timestamp. Thanks to BrowserUK for finding it in that code.


In reply to Documentation for the Simple HTTP server in under 100 lines by Corion
in thread Simple HTTP in under 100 lines by Corion

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.