Skip to content

Commit 2aa446f

Browse files
committed
Merge r1919620, r1919621, r1919623, r1919628, r1921237 from trunk:
mod_proxy_fcgi: Don't re-encode SCRIPT_FILENAME. PR 69203 Before r1918550 (r1918559 in 2.4.60), "SetHandler proxy:..." configurations did not pass through proxy_fixup() hence the proxy_canon_handler hooks, leaving fcgi's SCRIPT_FILENAME environment variable (from r->filename) decoded, or more exactly not re-encoded. We still want to call ap_proxy_canon_url() for "fcgi:" to handle/strip the UDS "unix:" case and check that r->filename is valid and contains no controls, but proxy_fcgi_canon() will not ap_proxy_canonenc_ex() thus re-encode anymore. Note that this will do the same for "ProxyPass fcgi:...", there is no reason that using SetHandler or ProxyPass don't result in the same thing. If an opt in/out makes sense we should probably look at ProxyFCGIBackendType. Follow up to r1919620: CHANGES entry indent. Follow up to r1919620: init path after "proxy:" is skipped. Follow up to r1919620: Restore r->filename re-encoding for ProxyPass URLs. mod_proxy_fgci: Follow up to r1919628: Simplify. Variable from_handler is used once so axe it. Submitted by: ylavic Reviewed by: ylavic, covener, jorton Github: closes #470 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1922080 13f79535-47bb-0310-9956-ffa450edef68
1 parent abbc289 commit 2aa446f

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

CHANGES

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

4+
*) mod_proxy_fcgi: Don't re-encode SCRIPT_FILENAME when set via SetHandler.
5+
PR 69203. [Yann Ylavic]
6+
47
*) mod_rewrite, mod_proxy: mod_proxy to canonicalize rewritten [P] URLs,
58
including "unix:" ones. PR 69235, PR 69260. [Yann Ylavic, Ruediger Pluem]
69

changes-entries/bz69203.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*) mod_proxy_fcgi: Don't re-encode SCRIPT_FILENAME when set via SetHandler.
2+
PR 69203. [Yann Ylavic]

modules/proxy/mod_proxy.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,7 @@ static int proxy_handler(request_rec *r)
12401240

12411241
r->proxyreq = PROXYREQ_REVERSE;
12421242
r->filename = apr_pstrcat(r->pool, r->handler, r->filename, NULL);
1243+
apr_table_setn(r->notes, "proxy-sethandler", "1");
12431244

12441245
/* Still need to canonicalize r->filename */
12451246
rc = ap_proxy_canon_url(r);
@@ -1249,6 +1250,7 @@ static int proxy_handler(request_rec *r)
12491250
}
12501251
}
12511252
else if (r->proxyreq && strncmp(r->filename, "proxy:", 6) == 0) {
1253+
apr_table_unset(r->notes, "proxy-sethandler");
12521254
rc = OK;
12531255
}
12541256
if (rc != OK) {

modules/proxy/mod_proxy_fcgi.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ static int proxy_fcgi_canon(request_rec *r, char *url)
6363
apr_port_t port, def_port;
6464
fcgi_req_config_t *rconf = NULL;
6565
const char *pathinfo_type = NULL;
66+
fcgi_dirconf_t *dconf = ap_get_module_config(r->per_dir_config,
67+
&proxy_fcgi_module);
6668

6769
if (ap_cstr_casecmpn(url, "fcgi:", 5) == 0) {
6870
url += 5;
@@ -92,9 +94,30 @@ static int proxy_fcgi_canon(request_rec *r, char *url)
9294
host = apr_pstrcat(r->pool, "[", host, "]", NULL);
9395
}
9496

95-
if (apr_table_get(r->notes, "proxy-nocanon")
97+
if (apr_table_get(r->notes, "proxy-sethandler")
98+
|| apr_table_get(r->notes, "proxy-nocanon")
9699
|| apr_table_get(r->notes, "proxy-noencode")) {
97-
path = url; /* this is the raw/encoded path */
100+
char *c = url;
101+
102+
/* We do not call ap_proxy_canonenc_ex() on the path here, don't
103+
* let control characters pass still, and for php-fpm no '?' either.
104+
*/
105+
if (FCGI_MAY_BE_FPM(dconf)) {
106+
while (!apr_iscntrl(*c) && *c != '?')
107+
c++;
108+
}
109+
else {
110+
while (!apr_iscntrl(*c))
111+
c++;
112+
}
113+
if (*c) {
114+
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10414)
115+
"To be forwarded path contains control characters%s (%s)",
116+
FCGI_MAY_BE_FPM(dconf) ? " or '?'" : "", url);
117+
return HTTP_FORBIDDEN;
118+
}
119+
120+
path = url; /* this is the raw path */
98121
}
99122
else {
100123
core_dir_config *d = ap_get_core_module_config(r->per_dir_config);
@@ -106,16 +129,6 @@ static int proxy_fcgi_canon(request_rec *r, char *url)
106129
return HTTP_BAD_REQUEST;
107130
}
108131
}
109-
/*
110-
* If we have a raw control character or a ' ' in nocanon path,
111-
* correct encoding was missed.
112-
*/
113-
if (path == url && *ap_scan_vchar_obstext(path)) {
114-
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10414)
115-
"To be forwarded path contains control "
116-
"characters or spaces");
117-
return HTTP_FORBIDDEN;
118-
}
119132

120133
r->filename = apr_pstrcat(r->pool, "proxy:fcgi://", host, sport, "/",
121134
path, NULL);

0 commit comments

Comments
 (0)