Skip to content

Commit d4f6ad9

Browse files
committed
Follow up to r1919620: Restore r->filename re-encoding for ProxyPass URLs.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1919628 13f79535-47bb-0310-9956-ffa450edef68
1 parent fed3dde commit d4f6ad9

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

changes-entries/bz69203.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
*) mod_proxy_fcgi: Don't re-encode SCRIPT_FILENAME. PR 69203. [Yann Ylavic]
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: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ static int proxy_fcgi_canon(request_rec *r, char *url)
5959
{
6060
char *host, sport[7];
6161
const char *err;
62-
char *path, *pc;
62+
char *path;
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);
68+
int from_handler;
6669

6770
if (ap_cstr_casecmpn(url, "fcgi:", 5) == 0) {
6871
url += 5;
@@ -71,12 +74,11 @@ static int proxy_fcgi_canon(request_rec *r, char *url)
7174
return DECLINED;
7275
}
7376

74-
path = url;
7577
port = def_port = ap_proxy_port_of_scheme("fcgi");
7678

7779
ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r,
7880
"canonicalising URL %s", url);
79-
err = ap_proxy_canon_netloc(r->pool, &path, NULL, NULL, &host, &port);
81+
err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
8082
if (err) {
8183
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01059)
8284
"error parsing URL %s: %s", url, err);
@@ -93,20 +95,40 @@ static int proxy_fcgi_canon(request_rec *r, char *url)
9395
host = apr_pstrcat(r->pool, "[", host, "]", NULL);
9496
}
9597

96-
/* We do not call ap_proxy_canonenc_ex() on the path here because the CGI
97-
* environment variable SCRIPT_FILENAME based on it want the decoded/local
98-
* path, don't let control characters pass still.
99-
*
100-
* XXX: should we encode based on dconf->backend_type though?
101-
*/
102-
for (pc = path; *pc; pc++) {
103-
if (apr_iscntrl(*pc)) {
98+
from_handler = apr_table_get(r->notes, "proxy-sethandler") != NULL;
99+
if (from_handler
100+
|| apr_table_get(r->notes, "proxy-nocanon")
101+
|| apr_table_get(r->notes, "proxy-noencode")) {
102+
char *c = path = url; /* this is the raw path */
103+
104+
/* We do not call ap_proxy_canonenc_ex() on the path here, don't
105+
* let control characters pass still, and for php-fpm no '?' either.
106+
*/
107+
if (FCGI_MAY_BE_FPM(dconf)) {
108+
while (!apr_iscntrl(*c) && *c != '?')
109+
c++;
110+
}
111+
else {
112+
while (!apr_iscntrl(*c))
113+
c++;
114+
}
115+
if (*c) {
104116
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10414)
105-
"To be forwarded path contains control "
106-
"characters");
117+
"To be forwarded path contains control characters%s",
118+
FCGI_MAY_BE_FPM(dconf) ? " or '?'" : "");
107119
return HTTP_FORBIDDEN;
108120
}
109121
}
122+
else {
123+
core_dir_config *d = ap_get_core_module_config(r->per_dir_config);
124+
int flags = d->allow_encoded_slashes && !d->decode_encoded_slashes ? PROXY_CANONENC_NOENCODEDSLASHENCODING : 0;
125+
126+
path = ap_proxy_canonenc_ex(r->pool, url, strlen(url), enc_path, flags,
127+
r->proxyreq);
128+
if (!path) {
129+
return HTTP_BAD_REQUEST;
130+
}
131+
}
110132

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

0 commit comments

Comments
 (0)