Skip to content

Commit 73387a6

Browse files
committed
Merge r728015, r728220, r728020 from trunk:
*) mod_rewrite: Introduce DiscardPathInfo|DPI flag to stop the troublesome way that per-directory rewrites append the previous notion of PATH_INFO to each substitution before evaluating subsequent rules. PR38642 [Eric Covener] axe r->path_info in a more standard way, suggested by Aleksander Budzynowski doc typo spotted by Vincent Bray Submitted By: Eric Covner Reviewed by: jorton, pgolluci git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@739600 13f79535-47bb-0310-9956-ffa450edef68
1 parent 9ed209c commit 73387a6

5 files changed

Lines changed: 71 additions & 22 deletions

File tree

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
-*- coding: utf-8 -*-
22
Changes with Apache 2.2.12
33

4+
*) mod_rewrite: Introduce DiscardPathInfo|DPI flag to stop the troublesome
5+
way that per-directory rewrites append the previous notion of PATH_INFO
6+
to each substitution before evaluating subsequent rules.
7+
PR38642 [Eric Covener]
8+
49
*) mod_authnz_ldap: Reduce number of initialization debug messages and make
510
information more clear. PR 46342 [Dan Poirier]
611

STATUS

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,6 @@ RELEASE SHOWSTOPPERS:
8686
PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
8787
[ start all new proposals below, under PATCHES PROPOSED. ]
8888

89-
* mod_rewrite: Introduce DiscardPathInfo|DPI flag to stop the troublesome
90-
way that per-directory rewrites append the previous notion of PATH_INFO
91-
to each substitution before evaluating subsequent rules.
92-
PR38642
93-
trunk:
94-
http://svn.apache.org/viewvc?rev=728015&view=rev
95-
http://svn.apache.org/viewvc?rev=728220&view=rev
96-
http://svn.apache.org/viewvc?rev=728020&view=rev (doc typo)
97-
2.2.x:
98-
trunk works
99-
+1 covener, jorton, pgollucci
100-
niq: Confused by this. path_info is used at line 3923 *before*
101-
being set to NULL at line 4046 in the same function. Not
102-
sure if there may be other issues of order.
103-
covener: 1 rule is executed between these two lines, and the flag
104-
prevents subsequent rules from spilling path_info back into
105-
the local URI. This preserves rulesets that are carefully
106-
watching %{PATH_INFO} in their substitutions. Not pretty
107-
by any means but I think necessary to require opt-in for 2.2.x.
108-
10989
* mod_ssl: Add SSLRenegBufferSize to configure the amount of memory that will
11090
be used for buffering the request body if a per-location SSL renegotiationi
11191
is required due to changed access control requirements.

docs/manual/mod/mod_rewrite.html.en

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,33 @@ cannot use <code>$N</code> in the substitution string!
12401240
<code>HttpOnly</code> flag is used, making the cookie not accessible
12411241
to JavaScript code on browsers that support this feature.</dd>
12421242

1243+
<dt>'<code>discardpathinfo|DPI'
1244+
(discard PATH_INFO)</code></dt><dd>
1245+
<p>In per-directory context, the URI each <code class="directive">RewriteRule</code>
1246+
compares against is the concatenation of the current values of the URI
1247+
and PATH_INFO.</p>
1248+
1249+
<p>The current URI can be the initial URI as requested by the client, the
1250+
result of a previous round of mod_rewrite processing, or the result of
1251+
a prior rule in the current round of mod_rewrite processing.</p>
1252+
1253+
<p>In contrast, the PATH_INFO that is appended to the URI before each
1254+
rule reflects only the value of PATH_INFO before this round of
1255+
mod_rewrite processing. As a consequence, if large portions
1256+
of the URI are matched and copied into a substitution in multiple
1257+
<code class="directive">RewriteRule</code> directives, without regard for
1258+
which parts of the URI came from the current PATH_INFO, the final
1259+
URI may have multiple copies of PATH_INFO appended to it.</p>
1260+
1261+
<p>Use this flag on any substitution where the PATH_INFO that resulted
1262+
from the previous mapping of this request to the filesystem is not of
1263+
interest. This flag permanently forgets the PATH_INFO established
1264+
before this round of mod_rewrite processing began. PATH_INFO will
1265+
not be recalculated until the current round of mod_rewrite processing
1266+
completes. Subsequent rules during this round of processing will see
1267+
only the direct result of substitutions, without any PATH_INFO
1268+
appended.</p></dd>
1269+
12431270
<dt>
12441271
'<code>env|E=</code><em>VAR</em>:<em>VAL</em>'
12451272
(set environment variable)</dt><dd>

docs/manual/mod/mod_rewrite.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,33 @@ cannot use <code>$N</code> in the substitution string!
12551255
<code>HttpOnly</code> flag is used, making the cookie not accessible
12561256
to JavaScript code on browsers that support this feature.</dd>
12571257

1258+
<dt>'<code>discardpathinfo|DPI'
1259+
(discard PATH_INFO)</code></dt><dd>
1260+
<p>In per-directory context, the URI each <directive>RewriteRule</directive>
1261+
compares against is the concatenation of the current values of the URI
1262+
and PATH_INFO.</p>
1263+
1264+
<p>The current URI can be the initial URI as requested by the client, the
1265+
result of a previous round of mod_rewrite processing, or the result of
1266+
a prior rule in the current round of mod_rewrite processing.</p>
1267+
1268+
<p>In contrast, the PATH_INFO that is appended to the URI before each
1269+
rule reflects only the value of PATH_INFO before this round of
1270+
mod_rewrite processing. As a consequence, if large portions
1271+
of the URI are matched and copied into a substitution in multiple
1272+
<directive>RewriteRule</directive> directives, without regard for
1273+
which parts of the URI came from the current PATH_INFO, the final
1274+
URI may have multiple copies of PATH_INFO appended to it.</p>
1275+
1276+
<p>Use this flag on any substitution where the PATH_INFO that resulted
1277+
from the previous mapping of this request to the filesystem is not of
1278+
interest. This flag permanently forgets the PATH_INFO established
1279+
before this round of mod_rewrite processing began. PATH_INFO will
1280+
not be recalculated until the current round of mod_rewrite processing
1281+
completes. Subsequent rules during this round of processing will see
1282+
only the direct result of substitutions, without any PATH_INFO
1283+
appended.</p></dd>
1284+
12581285
<dt>
12591286
'<code>env|E=</code><em>VAR</em>:<em>VAL</em>'
12601287
(set environment variable)</dt><dd>

modules/mappers/mod_rewrite.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
#define RULEFLAG_NOSUB 1<<12
148148
#define RULEFLAG_STATUS 1<<13
149149
#define RULEFLAG_ESCAPEBACKREF 1<<14
150+
#define RULEFLAG_DISCARDPATHINFO 1<<15
150151

151152
/* return code of the rewrite rule
152153
* the result may be escaped - or not
@@ -3281,7 +3282,12 @@ static const char *cmd_rewriterule_setflag(apr_pool_t *p, void *_cfg,
32813282
++error;
32823283
}
32833284
break;
3284-
3285+
case 'd':
3286+
case 'D':
3287+
if (!*key || !strcasecmp(key, "PI") || !strcasecmp(key,"iscardpath")) {
3288+
cfg->flags |= (RULEFLAG_DISCARDPATHINFO);
3289+
}
3290+
break;
32853291
case 'e':
32863292
case 'E':
32873293
if (!*key || !strcasecmp(key, "nv")) { /* env */
@@ -3337,7 +3343,6 @@ static const char *cmd_rewriterule_setflag(apr_pool_t *p, void *_cfg,
33373343
++error;
33383344
}
33393345
break;
3340-
33413346
case 'l':
33423347
case 'L':
33433348
if (!*key || !strcasecmp(key, "ast")) { /* last */
@@ -3889,6 +3894,11 @@ static int apply_rewrite_rule(rewriterule_entry *p, rewrite_ctx *ctx)
38893894

38903895
/* Now adjust API's knowledge about r->filename and r->args */
38913896
r->filename = newuri;
3897+
3898+
if (ctx->perdir && (p->flags & RULEFLAG_DISCARDPATHINFO)) {
3899+
r->path_info = NULL;
3900+
}
3901+
38923902
splitout_queryargs(r, p->flags & RULEFLAG_QSAPPEND);
38933903

38943904
/* Add the previously stripped per-directory location prefix, unless

0 commit comments

Comments
 (0)