Read the request body before replying, and generate certificates portably

httpsrv parsed Content-Length and never read what followed. The reply is
followed by a close, and closing a socket that still holds unread data
resets the connection instead of ending it, so a POST could cost the client
the reply it was about to read. Windows does that reliably; the same test
passes on Linux and macOS, which is why it looked flaky. Drain the body,
bounded at a megabyte.

The test CA was built with -addext, which LibreSSL - the openssl on a stock
macOS - does not apply the same way, leaving a certificate that is not
usable as a CA and a client that cannot build a chain to it. Put the
extensions in a file both accept, and verify the generated chain before any
of it is handed to a proxy, so a failure there is not read as a fault in
the proxy.
This commit is contained in:
Vladimir Dubrovin 2026-08-26 09:28:46 +03:00
parent 527f0704a4
commit 488317da1d
3 changed files with 72 additions and 19 deletions

View file

@ -27,6 +27,7 @@
#define HTTPSRV_LINE 1024
#define HTTPSRV_BLOCK 8192
#define HTTPSRV_MAXHDR 64
#define HTTPSRV_MAXBODY 1048576
/* Returns the value of a query parameter, or def when it is missing or not a
@ -363,6 +364,28 @@ int httpopbyname(const unsigned char *name)
return -1;
}
/* Read and discard a request body.
The reply is followed by a close, and closing a socket that still holds
unread data resets the connection rather than ending it, which costs the
client the reply it was about to read. Bounded, so a client cannot keep
the server reading.
*/
static void httpsrv_drain(struct clientparam *param, unsigned long len)
{
char buf[HTTPSRV_BLOCK];
if(len > HTTPSRV_MAXBODY) len = HTTPSRV_MAXBODY;
while(len){
int want = (len > (unsigned long)sizeof(buf))? (int)sizeof(buf) : (int)len;
int got = sockgetlinebuf(param, CLIENT, (unsigned char *)buf, want, EOF,
conf.timeouts[STRING_S]);
if(got <= 0) break;
len -= (unsigned long)got;
}
}
void * httpsrvchild(struct clientparam *param)
{
struct httpreq r;
@ -451,6 +474,8 @@ void * httpsrvchild(struct clientparam *param)
}
}
if(r.contentlen) httpsrv_drain(param, r.contentlen);
if(r.host[0]){
char host[sizeof(r.host)];
char *colon;