On Thu, Oct 12, 2006 at 12:57:14PM +0300, Peter Pentchev wrote:
> Hi,
>
> First of all, thanks for writing and maintaing a great, lightweight,
> simple webserver!
>
> My attention was recently drawn to Mathopd when a friend decided to use
> it as a lightweight replacement of Apache for one of the Bulgarian
> mirrors of Debian Linux. It's been doing great so far, with a single
> excepion - as y'all might have already guessed, it's /../ components in
> the URL paths. It turns out that some configurations for fetching
> Debian distribution files do indeed depend on traversing directories
> back up - it happens only very rarely, but still, it happens, and our
> new mirror webserver does not quite allow it.
After another discussion with Alexander Velin, the above-mentioned
Debian mirror maintainer, it turned out that it may also be desirable to
sometimes allow // in the URL paths, ignoring the second and further
slashes. So, here's another version of the patch which changes several
things:
src/request.c - check_path():
- now returns a bitmask of flags instead of a single boolean value.
This makes it possible for it to signal both fatal errors and possible
error conditions - see below for deferred error processing.
- as in the previous patch, rewrites the request URL path, removing /./
components and processing /../ by removing the last stored "real" path
component.
- raises a flag in the return code if a dotfile is found in the path.
- raises a flag in the return code if a double slash is found in the
URL path.
src/request.c - process_path():
- only invokes check_path() once now, not twice as in the previous
version of the patch.
- invokes check_path() before faketoreal(), so faketoreal() works on the
real location (consider http://www.example.com/cgi-bin/../doc/).
- defers all error processing, including the dotfiles and double-slash
checks, after the faketoreal() invocation - check_path() is now called
much earlier and it has no idea what the control configuration will
be, whether it will allow dotfiles or not, and what error document to
send to the client.
- checks for allow_dotfiles if check_path() found a dotfile (or dotdir)
in the URL path.
- new: checks for allow_doubleslash if check_path() found // in the URL
path.
doc/config.txt:
doc/syntax.txt:
- document the new AllowDoubleSlash keyword.
src/config.c:
- process the new AllowDoubleSlash keyword.
src/mathopd.h:
- add the allow_doubleslash flag to the control block structure.
If the patches should not make it to the list, they are also available
at http://www.ringlet.net/~roam/patches/mathopd/
G'luck,
Peter
--
Peter Pentchev [EMAIL PROTECTED][EMAIL PROTECTED][EMAIL PROTECTED]
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint FDBA FD79 C26F 3C51 C95E DF9E ED18 B68D 1619 4553
This inert sentence is my body, but my soul is alive, dancing in the sparks of
your brain.
Index: doc/config.txt
===
--- doc/config.txt (revision 333)
+++ doc/config.txt (revision 456)
@@ -91,6 +91,15 @@
a bit, although constructions like '/./', '/../', etc. are
still disallowed.
+Keyword: AllowDoubleSlash
+Where: Control
+Type:Flag
+Default: Off
+Desc:Normally, URL's with two or more slashes in the path portion,
+ like http://www.example.com/mathopd//doc/, will be rejected.
+ If the AllowDoubleSlash flag is set, this restriction is removed,
+ and Mathopd will silently ignore the second and further slashes.
+
Keyword: AnyHost
Where: Virtual
Desc:If a virtual server has this keyword, it will match on any Host:
Index: doc/syntax.txt
===
--- doc/syntax.txt (revision 333)
+++ doc/syntax.txt (revision 456)
@@ -84,6 +84,7 @@
"ScriptUser" string
"RunScriptsAsOwner" string
"AllowDotfiles" flag
+ "AllowDoubleSlash" flag
"UserDirectory" flag
"PutEnv" string-block
"ExtraHeaders" string-block
Index: src/mathopd.h
===
--- src/mathopd.h (revision 333)
+++ src/mathopd.h (revision 456)
@@ -171,6 +171,7 @@
uid_t script_uid;
gid_t script_gid;
int allow_dotfiles;
+ int allow_doubleslash;
int user_directory;
struct simple_list *putenvs;
struct simple_list *extra_headers;
Index: src/config.c
===
--- src/config.c(revision 333)
+++ src/config.c(revision 456)
@@ -84,6 +84,7 @@
static const char c_alias[] = "Alias";
static const char c_allow[] = "Allow";
static const char c_allow_dotfiles[] = "AllowDotfiles";
+static const char c_allow_doubleslash[] = "AllowDoubleSlash";
static const char c_any_host[] =