diff options
| author | Tim Rühsen <tim.ruehsen@gmx.de> | 2018-04-27 10:41:56 +0200 |
|---|---|---|
| committer | Tim Rühsen <tim.ruehsen@gmx.de> | 2018-05-06 18:24:58 +0200 |
| commit | 1fc9c95ec144499e69dc8ec76dbe07799d7d82cd (patch) | |
| tree | 87e8787f27138e418eeed26c8d388d18d9523248 | |
| parent | f51936745aab064c4342eba1e049d4df45fa09f0 (diff) | |
| download | wget-1fc9c95ec144499e69dc8ec76dbe07799d7d82cd.tar.gz | |
Fix cookie injection (CVE-2018-0494)
* src/http.c (resp_new): Replace \r\n by space in continuation lines
Fixes #53763
"Malicious website can write arbitrary cookie entries to cookie jar"
HTTP header parsing left the \r\n from continuation line intact.
The Set-Cookie code didn't check and could be tricked to write
\r\n into the cookie jar, allowing a server to generate cookies at will.
| -rw-r--r-- | src/http.c | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -613,9 +613,9 @@ struct response { resp_header_*. */ static struct response * -resp_new (const char *head) +resp_new (char *head) { - const char *hdr; + char *hdr; int count, size; struct response *resp = xnew0 (struct response); @@ -644,15 +644,23 @@ resp_new (const char *head) break; /* Find the end of HDR, including continuations. */ - do + for (;;) { - const char *end = strchr (hdr, '\n'); + char *end = strchr (hdr, '\n'); + if (end) hdr = end + 1; else hdr += strlen (hdr); + + if (*hdr != ' ' && *hdr != '\t') + break; + + // continuation, transform \r and \n into spaces + *end = ' '; + if (end > head && end[-1] == '\r') + end[-1] = ' '; } - while (*hdr == ' ' || *hdr == '\t'); } DO_REALLOC (resp->headers, size, count + 1, const char *); resp->headers[count] = NULL; |
