From 0cbdc982fd602b66522d7bd11a08bc1f46ca8c33 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 13 Jun 2023 15:31:23 +0200 Subject: [PATCH] Fix CVE-2022-35252 Merge: curl/curl@8dfc93e573ca740544a2d79ebb --- r5dev/thirdparty/curl/cookie.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/r5dev/thirdparty/curl/cookie.c b/r5dev/thirdparty/curl/cookie.c index 6b678aeb..16df0838 100644 --- a/r5dev/thirdparty/curl/cookie.c +++ b/r5dev/thirdparty/curl/cookie.c @@ -347,6 +347,28 @@ static bool isip(const char *domain) return FALSE; } +/* + RFC 6265 section 4.1.1 says a server should accept this range: + cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E + But Firefox and Chrome as of June 2022 accept space, comma and double-quotes + fine. The prime reason for filtering out control bytes is that some HTTP + servers return 400 for requests that contain such. +*/ +static int invalid_octets(const char *p) +{ + /* Reject all bytes \x01 - \x1f (*except* \x09, TAB) + \x7f */ + static const char badoctets[] = { + "\x01\x02\x03\x04\x05\x06\x07\x08\x0a" + "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" + "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x7f" + }; + size_t vlen, len; + /* scan for all the octets that are *not* in cookie-octet */ + len = strcspn(p, badoctets); + vlen = strlen(p); + return (len != vlen); +} + /**************************************************************************** * * Curl_cookie_add() @@ -463,6 +485,11 @@ Curl_cookie_add(struct Curl_easy *data, badcookie = TRUE; break; } + if(invalid_octets(whatptr) || invalid_octets(name)) { + infof(data, "invalid octets in name/value, cookie dropped"); + badcookie = TRUE; + break; + } } else if(!len) { /* this was a "=" with no content, and we must allow