Skip to content

Commit 88ebfaa

Browse files
committed
Merge r1838684, r1920570, r1920571, r1920572 from trunk:
When a rewrite to proxy is configured in the server config, a check is made to make sure mod_proxy is active. But the same is not done if a rewrite to proxy is configured in an .htaccess file. Basically this patch is the block of code from hook_uri2file that does the proxy check, copied to hook_fixup. Patch provided by Michael Streeter [mstreeter1 gmail.com], slightly modified to use a new APLOGNO PR 56264 mod_rewrite, mod_proxy: mod_proxy to cononicalize rewritten [P] URLs. PR 69235. When mod_rewrite sets a "proxy:" URL with [P], it should be canonicalized by mod_proxy still, notably to handle any "unix:" local socket part. To avoid double encoding in perdir context, a follow up commit should remove the ap_escape_uri() done in mod_rewrite since it's now on mod_proxy to canonicalize, per PR 69260. * Leave the proper escaping of the URL and the adding of r->args to the proxy module which runs after us after r1920570. Just take care to add r->args in case the proxy rule has the [NE] flag set and tell the proxy module to not escape in this case. * Mention the additional bug Submitted by: jailletc36, ylavic, rpluem Reviewed by: rpluem, ylavic, covener Github: closes #484 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1921299 13f79535-47bb-0310-9956-ffa450edef68
1 parent 0531a7d commit 88ebfaa

File tree

4 files changed

+39
-45
lines changed

4 files changed

+39
-45
lines changed

CHANGES

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

4+
*) mod_rewrite, mod_proxy: mod_proxy to canonicalize rewritten [P] URLs,
5+
including "unix:" ones. PR 69235, PR 69260. [Yann Ylavic, Ruediger Pluem]
6+
7+
*) mod_rewrite: Error out in case a RewriteRule in directory context uses the
8+
proxy, but mod_proxy is not loaded. PR 56264.
9+
[Christophe Jaillet, Michael Streeter <[email protected]>]
10+
411
*) http: Remove support for Request-Range header sent by Navigator 2-3 and
512
MSIE 3. [Stefan Fritsch]
613

STATUS

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,6 @@ RELEASE SHOWSTOPPERS:
165165
PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
166166
[ start all new proposals below, under PATCHES PROPOSED. ]
167167

168-
*) mod_rewrite, mod_proxy: mod_proxy to cononicalize rewritten [P] URLs,
169-
including "unix:" ones. PR 69235, PR 69260, PR 56264
170-
Trunk version of patch:
171-
https://svn.apache.org/r1838684
172-
https://svn.apache.org/r1920570
173-
https://svn.apache.org/r1920571
174-
https://svn.apache.org/r1920572
175-
Backport version for 2.4.x of patch:
176-
https://patch-diff.githubusercontent.com/raw/apache/httpd/pull/484.diff
177-
Can be applied via apply_backport_pr.sh 484
178-
+1: rpluem, ylavic, covener
179-
180168
*) mod_ssl: Fix regression in PKCS#11 handling which should work without
181169
SSLCryptoDevice configured
182170
trunk patch: https://svn.apache.org/r1920597

modules/mappers/mod_rewrite.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4515,20 +4515,6 @@ static rule_return_type apply_rewrite_rule(rewriterule_entry *p,
45154515
* ourself).
45164516
*/
45174517
if (p->flags & RULEFLAG_PROXY) {
4518-
/* For rules evaluated in server context, the mod_proxy fixup
4519-
* hook can be relied upon to escape the URI as and when
4520-
* necessary, since it occurs later. If in directory context,
4521-
* the ordering of the fixup hooks is forced such that
4522-
* mod_proxy comes first, so the URI must be escaped here
4523-
* instead. See PR 39746, 46428, and other headaches. */
4524-
if (ctx->perdir && (p->flags & RULEFLAG_NOESCAPE) == 0) {
4525-
char *old_filename = r->filename;
4526-
4527-
r->filename = ap_escape_uri(r->pool, r->filename);
4528-
rewritelog(r, 2, ctx->perdir, "escaped URI in per-dir context "
4529-
"for proxy, %s -> %s", old_filename, r->filename);
4530-
}
4531-
45324518
fully_qualify_uri(r);
45334519

45344520
rewritelog(r, 2, ctx->perdir, "forcing proxy-throughput with %s",
@@ -5051,7 +5037,7 @@ static int hook_uri2file(request_rec *r)
50515037
}
50525038
if ((r->args != NULL)
50535039
&& ((r->proxyreq == PROXYREQ_PROXY)
5054-
|| (rulestatus == ACTION_NOESCAPE))) {
5040+
|| apr_table_get(r->notes, "proxy-nocanon"))) {
50555041
/* see proxy_http:proxy_http_canon() */
50565042
r->filename = apr_pstrcat(r->pool, r->filename,
50575043
"?", r->args, NULL);
@@ -5342,13 +5328,28 @@ static int hook_fixup(request_rec *r)
53425328
if (to_proxyreq) {
53435329
/* it should go on as an internal proxy request */
53445330

5345-
/* make sure the QUERY_STRING and
5346-
* PATH_INFO parts get incorporated
5331+
/* check if the proxy module is enabled, so
5332+
* we can actually use it!
5333+
*/
5334+
if (!proxy_available) {
5335+
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10160)
5336+
"attempt to make remote request from mod_rewrite "
5337+
"without proxy enabled: %s", r->filename);
5338+
return HTTP_FORBIDDEN;
5339+
}
5340+
5341+
if (rulestatus == ACTION_NOESCAPE) {
5342+
apr_table_setn(r->notes, "proxy-nocanon", "1");
5343+
}
5344+
5345+
/* make sure the QUERY_STRING gets incorporated in the case
5346+
* [NE] was specified on the Proxy rule. We are preventing
5347+
* mod_proxy canon handler from incorporating r->args as well
5348+
* as escaping the URL.
53475349
* (r->path_info was already appended by the
53485350
* rewriting engine because of the per-dir context!)
53495351
*/
5350-
if (r->args != NULL) {
5351-
/* see proxy_http:proxy_http_canon() */
5352+
if ((r->args != NULL) && apr_table_get(r->notes, "proxy-nocanon")) {
53525353
r->filename = apr_pstrcat(r->pool, r->filename,
53535354
"?", r->args, NULL);
53545355
}
@@ -5648,10 +5649,7 @@ static void ap_register_rewrite_mapfunc(char *name, rewrite_mapfunc_t *func)
56485649

56495650
static void register_hooks(apr_pool_t *p)
56505651
{
5651-
/* fixup after mod_proxy, so that the proxied url will not
5652-
* escaped accidentally by mod_proxy's fixup.
5653-
*/
5654-
static const char * const aszPre[]={ "mod_proxy.c", NULL };
5652+
static const char * const aszModProxy[] = { "mod_proxy.c", NULL };
56555653

56565654
/* make the hashtable before registering the function, so that
56575655
* other modules are prevented from accessing uninitialized memory.
@@ -5663,10 +5661,12 @@ static void register_hooks(apr_pool_t *p)
56635661
ap_hook_pre_config(pre_config, NULL, NULL, APR_HOOK_MIDDLE);
56645662
ap_hook_post_config(post_config, NULL, NULL, APR_HOOK_MIDDLE);
56655663
ap_hook_child_init(init_child, NULL, NULL, APR_HOOK_MIDDLE);
5666-
5667-
ap_hook_fixups(hook_fixup, aszPre, NULL, APR_HOOK_FIRST);
5664+
5665+
/* allow to change the uri before mod_proxy takes over it */
5666+
ap_hook_translate_name(hook_uri2file, NULL, aszModProxy, APR_HOOK_FIRST);
5667+
/* fixup before mod_proxy so that a [P] URL gets fixed up there */
5668+
ap_hook_fixups(hook_fixup, NULL, aszModProxy, APR_HOOK_FIRST);
56685669
ap_hook_fixups(hook_mimetype, NULL, NULL, APR_HOOK_LAST);
5669-
ap_hook_translate_name(hook_uri2file, NULL, NULL, APR_HOOK_FIRST);
56705670
}
56715671

56725672
/* the main config structure */

modules/proxy/mod_proxy.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3347,27 +3347,26 @@ static int proxy_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
33473347
}
33483348
static void register_hooks(apr_pool_t *p)
33493349
{
3350-
/* fixup before mod_rewrite, so that the proxied url will not
3351-
* escaped accidentally by our fixup.
3352-
*/
3353-
static const char * const aszSucc[] = { "mod_rewrite.c", NULL};
33543350
/* Only the mpm_winnt has child init hook handler.
33553351
* make sure that we are called after the mpm
33563352
* initializes.
33573353
*/
33583354
static const char *const aszPred[] = { "mpm_winnt.c", "mod_proxy_balancer.c",
33593355
"mod_proxy_hcheck.c", NULL};
3356+
static const char * const aszModRewrite[] = { "mod_rewrite.c", NULL };
3357+
33603358
/* handler */
33613359
ap_hook_handler(proxy_handler, NULL, NULL, APR_HOOK_FIRST);
33623360
/* filename-to-URI translation */
33633361
ap_hook_pre_translate_name(proxy_pre_translate_name, NULL, NULL,
33643362
APR_HOOK_MIDDLE);
3365-
ap_hook_translate_name(proxy_translate_name, aszSucc, NULL,
3363+
/* mod_rewrite has a say on the uri before proxy translation */
3364+
ap_hook_translate_name(proxy_translate_name, aszModRewrite, NULL,
33663365
APR_HOOK_FIRST);
33673366
/* walk <Proxy > entries and suppress default TRACE behavior */
33683367
ap_hook_map_to_storage(proxy_map_location, NULL,NULL, APR_HOOK_FIRST);
3369-
/* fixups */
3370-
ap_hook_fixups(proxy_fixup, NULL, aszSucc, APR_HOOK_FIRST);
3368+
/* fixup after mod_rewrite so that a [P] URL from there gets fixed up */
3369+
ap_hook_fixups(proxy_fixup, aszModRewrite, NULL, APR_HOOK_FIRST);
33713370
/* post read_request handling */
33723371
ap_hook_post_read_request(proxy_detect, NULL, NULL, APR_HOOK_FIRST);
33733372
/* pre config handling */

0 commit comments

Comments
 (0)