From: Eric Covener Date: Mon, 15 Jul 2024 12:05:57 +0000 (+0000) Subject: merge leading slashes by default X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1560d34a37681ebc18baa78588579ed87f9da70;p=thirdparty%2Fapache%2Fhttpd.git merge leading slashes by default git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1919246 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/mod/mod_rewrite.xml b/docs/manual/mod/mod_rewrite.xml index fd55811347e..0cfc2f42ec5 100644 --- a/docs/manual/mod/mod_rewrite.xml +++ b/docs/manual/mod/mod_rewrite.xml @@ -1508,6 +1508,13 @@ cannot use $N in the substitution string! details ... + + UNC + Prevents the merging of multiple leading slashes, as used by Windows UNC paths. + details ... + + + Home directory expansion diff --git a/docs/manual/rewrite/flags.xml b/docs/manual/rewrite/flags.xml index 59eb4cd0c93..0b9ccfa9a89 100644 --- a/docs/manual/rewrite/flags.xml +++ b/docs/manual/rewrite/flags.xml @@ -866,6 +866,10 @@ The L flag can be useful in this context to end the This protects from a malicious URL causing the expanded substitution to map to an unexpected filesystem location.

- +
UNC +

Setting this flag prevents the merging of multiple leading slashes, + as used in Windows UNC paths. The flag is not necessary when the rules + substitution starts with multiple literal slashes.

+
diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 0d928e4b997..439af886ba9 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -179,6 +179,7 @@ static const char* really_last_key = "rewrite_really_last"; #define RULEFLAG_ESCAPECTLS (1<<21) #define RULEFLAG_UNSAFE_PREFIX_STAT (1<<22) #define RULEFLAG_UNSAFE_ALLOW3F (1<<23) +#define RULEFLAG_UNC (1<<24) /* return code of the rewrite rule * the result may be escaped - or not @@ -3884,6 +3885,9 @@ static const char *cmd_rewriterule_setflag(apr_pool_t *p, void *_cfg, else if(!strcasecmp(key, "nsafeAllow3F")) { cfg->flags |= RULEFLAG_UNSAFE_ALLOW3F; } + else if(!strcasecmp(key, "NC")) { + cfg->flags |= RULEFLAG_UNC; + } else { ++error; } @@ -4508,6 +4512,16 @@ static rule_return_type apply_rewrite_rule(rewriterule_entry *p, return RULE_RC_MATCH; } + if (!(p->flags & RULEFLAG_UNC)) { + /* merge leading slashes, unless they were literals in the sub */ + if (!AP_IS_SLASH(p->output[0]) || !AP_IS_SLASH(p->output[1])) { + while (AP_IS_SLASH(r->filename[0]) && + AP_IS_SLASH(r->filename[1])) { + r->filename++; + } + } + } + /* Finally remember the forced mime-type */ force_type_handler(p, ctx);