mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 23:59:41 +08:00
Fix rewrite and over-long header handling on Windows
op_rewrite checked what it built with targetunsafe(), which describes a path on this machine: on Windows it must name a drive or a share, so a rewritten request path was refused and every rewrite rule failed there. A rewrite produces a request path and is checked as one. The header loop stopped at HTTPSRV_MAXHDR and answered anyway, leaving the rest of the request in the stream for the next one to be read out of. It refuses the request instead. A header longer than the buffer arrives as several lines, so the count bounds what is read rather than what a client may send in one header. The test for the buffer growth after a PCRE rewrite sent its request through to an httpsrv origin, which stops reading at that same cap; it uses an origin which reads whatever it is sent, since what is under test is the proxy in the middle.
This commit is contained in:
1 parent
7eca490bf3
commit
32a5e1e6ab
3 files changed
+43
-14
No files matched your search
+14
-2
@@ -937,7 +937,11 @@ static int op_rewrite(struct httpreq *r, const unsigned char *params)
|
||||
if(!params || !*params) return op_forbidden(r);
|
||||
if(expand(path, sizeof(path), params, r->path, r->caps, r->ncaps))
|
||||
return op_forbidden(r);
|
||||
if(targetunsafe(path) || path[0] != '/') return op_forbidden(r);
|
||||
/* What comes out is a request path and is checked as one. A path on this
|
||||
machine is a different thing, and asking a rewrite to look like one
|
||||
would leave nothing writable on Windows, where such a path names a
|
||||
drive or a share. */
|
||||
if(path[0] != '/' || pathunsafe(path)) return op_forbidden(r);
|
||||
strcpy(r->path, path);
|
||||
return HTTPSRV_REWRITTEN;
|
||||
}
|
||||
@@ -1327,9 +1331,12 @@ static int httpsrv_request(struct clientparam *param, struct httpreq *r)
|
||||
strcpy(r->path, decoded);
|
||||
}
|
||||
|
||||
while(hdrs++ < HTTPSRV_MAXHDR &&
|
||||
/* A header longer than the buffer arrives as several lines, so the count
|
||||
bounds what is read and not what a client may send in one header. */
|
||||
while(hdrs < HTTPSRV_MAXHDR &&
|
||||
(i = sockgetlinebuf(param, CLIENT, (unsigned char *)buf, sizeof(buf) - 1,
|
||||
'\n', conf.timeouts[STRING_S])) > 2){
|
||||
hdrs++;
|
||||
if(rawkeep(r, buf, i)) RETURN(710);
|
||||
buf[i] = 0;
|
||||
if(!strncasecmp(buf, "host:", 5) && !r->proxy){
|
||||
@@ -1384,6 +1391,11 @@ static int httpsrv_request(struct clientparam *param, struct httpreq *r)
|
||||
}
|
||||
}
|
||||
|
||||
/* The headers ran past what this server reads, so the rest of the request
|
||||
is still in the stream and there is no answering it: what follows would
|
||||
be read as the request after this one. */
|
||||
if(hdrs >= HTTPSRV_MAXHDR) RETURN(712);
|
||||
|
||||
/* The next request begins where this body ends, so a body which cannot
|
||||
be read to its end - one this server does not frame, or one longer
|
||||
than it is willing to read - closes the connection instead.
|
||||
|
||||
Reference in new issue
Block a user