You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by co...@apache.org on 2024/07/15 12:07:57 UTC

svn commit: r1919248 - in /httpd/httpd/branches/2.4.x: ./ docs/manual/mod/mod_rewrite.xml docs/manual/rewrite/flags.xml modules/mappers/mod_rewrite.c

Author: covener
Date: Mon Jul 15 12:07:57 2024
New Revision: 1919248

URL: http://svn.apache.org/viewvc?rev=1919248&view=rev
Log:
Merge r1919246 from trunk:

merge leading slashes by default

Submitted By: ylavic, covener
Reviewed By: ylavic, covener, gbechis


Modified:
    httpd/httpd/branches/2.4.x/   (props changed)
    httpd/httpd/branches/2.4.x/docs/manual/mod/mod_rewrite.xml
    httpd/httpd/branches/2.4.x/docs/manual/rewrite/flags.xml
    httpd/httpd/branches/2.4.x/modules/mappers/mod_rewrite.c

Propchange: httpd/httpd/branches/2.4.x/
------------------------------------------------------------------------------
  Merged /httpd/httpd/trunk:r1919246

Modified: httpd/httpd/branches/2.4.x/docs/manual/mod/mod_rewrite.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/docs/manual/mod/mod_rewrite.xml?rev=1919248&r1=1919247&r2=1919248&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/docs/manual/mod/mod_rewrite.xml (original)
+++ httpd/httpd/branches/2.4.x/docs/manual/mod/mod_rewrite.xml Mon Jul 15 12:07:57 2024
@@ -1497,6 +1497,13 @@ cannot use <code>$N</code> in the substi
         <em><a href="../rewrite/flags.html#flag_unsafe_prefix_stat">details ...</a></em>
         </td>
     </tr>
+    <tr>
+        <td>UNC</td>
+        <td>Prevents the merging of multiple leading slashes, as used by Windows UNC paths.
+        <em><a href="../rewrite/flags.html#flag_unc">details ...</a></em>
+        </td>
+    </tr>
+
     </table>
 
 <note><title>Home directory expansion</title>

Modified: httpd/httpd/branches/2.4.x/docs/manual/rewrite/flags.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/docs/manual/rewrite/flags.xml?rev=1919248&r1=1919247&r2=1919248&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/docs/manual/rewrite/flags.xml (original)
+++ httpd/httpd/branches/2.4.x/docs/manual/rewrite/flags.xml Mon Jul 15 12:07:57 2024
@@ -866,6 +866,10 @@ The <code>L</code> flag can be useful in
     This protects from a malicious URL causing the expanded substitution to
     map to an unexpected filesystem location.</p>
 </section>
-
+<section id="flag_unc"><title>UNC</title>
+    <p> 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. </p>
+</section>
 
 </manualpage>

Modified: httpd/httpd/branches/2.4.x/modules/mappers/mod_rewrite.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/mappers/mod_rewrite.c?rev=1919248&r1=1919247&r2=1919248&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/mappers/mod_rewrite.c (original)
+++ httpd/httpd/branches/2.4.x/modules/mappers/mod_rewrite.c Mon Jul 15 12:07:57 2024
@@ -179,6 +179,7 @@ static const char* really_last_key = "re
 #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
@@ -3843,6 +3844,9 @@ static const char *cmd_rewriterule_setfl
         else if(!strcasecmp(key, "nsafeAllow3F")) {
             cfg->flags |= RULEFLAG_UNSAFE_ALLOW3F;
         }
+        else if(!strcasecmp(key, "NC")) {
+            cfg->flags |= RULEFLAG_UNC;
+        }
         else {
             ++error;
         }
@@ -4462,6 +4466,16 @@ static rule_return_type apply_rewrite_ru
         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);
 



Re: svn commit: r1919248 - in /httpd/httpd/branches/2.4.x: ./ docs/manual/mod/mod_rewrite.xml docs/manual/rewrite/flags.xml modules/mappers/mod_rewrite.c

Posted by Christophe JAILLET <ch...@wanadoo.fr>.
Le 15/07/2024 à 14:07, covener@apache.org a écrit :
> Author: covener
> Date: Mon Jul 15 12:07:57 2024
> New Revision: 1919248
>
> URL: http://svn.apache.org/viewvc?rev=1919248&view=rev
> Log:
> Merge r1919246 from trunk:
>
> merge leading slashes by default
>
> Submitted By: ylavic, covener
> Reviewed By: ylavic, covener, gbechis
>
>
> Modified:
>      httpd/httpd/branches/2.4.x/   (props changed)
>      httpd/httpd/branches/2.4.x/docs/manual/mod/mod_rewrite.xml
>      httpd/httpd/branches/2.4.x/docs/manual/rewrite/flags.xml
>      httpd/httpd/branches/2.4.x/modules/mappers/mod_rewrite.c
>
> Propchange: httpd/httpd/branches/2.4.x/
> ------------------------------------------------------------------------------
>    Merged /httpd/httpd/trunk:r1919246
>
> Modified: httpd/httpd/branches/2.4.x/docs/manual/mod/mod_rewrite.xml
> URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/docs/manual/mod/mod_rewrite.xml?rev=1919248&r1=1919247&r2=1919248&view=diff
> ==============================================================================
> --- httpd/httpd/branches/2.4.x/docs/manual/mod/mod_rewrite.xml (original)
> +++ httpd/httpd/branches/2.4.x/docs/manual/mod/mod_rewrite.xml Mon Jul 15 12:07:57 2024
> @@ -1497,6 +1497,13 @@ cannot use <code>$N</code> in the substi
>           <em><a href="../rewrite/flags.html#flag_unsafe_prefix_stat">details ...</a></em>
>           </td>
>       </tr>
> +    <tr>
> +        <td>UNC</td>
> +        <td>Prevents the merging of multiple leading slashes, as used by Windows UNC paths.
> +        <em><a href="../rewrite/flags.html#flag_unc">details ...</a></em>
> +        </td>
> +    </tr>
> +
>       </table>

Hi,


A compatibility note should be added somewhere for this new flag.
I should have some cycles the WE for it, but if anyone wants to fix it 
before me, it is fine as well.


CJ