ce20cb
From 005d3f387bc5c3b2ee94d0597b5e202644c825f5 Mon Sep 17 00:00:00 2001
ce20cb
From: Daniel Stenberg <daniel@haxx.se>
ce20cb
Date: Wed, 31 Oct 2018 11:08:49 +0100
ce20cb
Subject: [PATCH 1/3] runtests: use the local curl for verifying
ce20cb
ce20cb
... revert the mistaken change brought in commit 8440616f53.
ce20cb
ce20cb
Reported-by: Alessandro Ghedini
ce20cb
Bug: https://curl.haxx.se/mail/lib-2018-10/0118.html
ce20cb
ce20cb
Closes #3198
ce20cb
ce20cb
Upstream-commit: 8effa8c2b09906a2f00a3f08322dc5da35245b0a
ce20cb
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
ce20cb
---
ce20cb
 tests/runtests.pl | 2 +-
ce20cb
 1 file changed, 1 insertion(+), 1 deletion(-)
ce20cb
ce20cb
diff --git a/tests/runtests.pl b/tests/runtests.pl
ce20cb
index 8d8ed81..d62fa40 100755
ce20cb
--- a/tests/runtests.pl
ce20cb
+++ b/tests/runtests.pl
ce20cb
@@ -152,7 +152,7 @@ my $NEGTELNETPORT;       # TELNET server port with negotiation
ce20cb
 
ce20cb
 my $srcdir = $ENV{'srcdir'} || '.';
ce20cb
 my $CURL="../src/curl".exe_ext(); # what curl executable to run on the tests
ce20cb
-my $VCURL="curl";   # what curl binary to use to verify the servers with
ce20cb
+my $VCURL=$CURL;   # what curl binary to use to verify the servers with
ce20cb
                    # VCURL is handy to set to the system one when the one you
ce20cb
                    # just built hangs or crashes and thus prevent verification
ce20cb
 my $DBGCURL=$CURL; #"../src/.libs/curl";  # alternative for debugging
ce20cb
-- 
ce20cb
2.37.3
ce20cb
ce20cb
ce20cb
From fbc2ac6f06ec13cc872ce7adb870f4d7c7d5dded Mon Sep 17 00:00:00 2001
ce20cb
From: Daniel Stenberg <daniel@haxx.se>
ce20cb
Date: Mon, 29 Aug 2022 00:09:17 +0200
ce20cb
Subject: [PATCH 2/3] cookie: reject cookies with "control bytes"
ce20cb
ce20cb
Rejects 0x01 - 0x1f (except 0x09) plus 0x7f
ce20cb
ce20cb
Reported-by: Axel Chong
ce20cb
ce20cb
Bug: https://curl.se/docs/CVE-2022-35252.html
ce20cb
ce20cb
CVE-2022-35252
ce20cb
ce20cb
Closes #9381
ce20cb
ce20cb
Upstream-commit: 8dfc93e573ca740544a2d79ebb0ed786592c65c3
ce20cb
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
ce20cb
---
ce20cb
 lib/cookie.c | 29 +++++++++++++++++++++++++++++
ce20cb
 1 file changed, 29 insertions(+)
ce20cb
ce20cb
diff --git a/lib/cookie.c b/lib/cookie.c
ce20cb
index cb0c03b..e0470a1 100644
ce20cb
--- a/lib/cookie.c
ce20cb
+++ b/lib/cookie.c
ce20cb
@@ -371,6 +371,30 @@ static void strstore(char **str, const char *newstr)
ce20cb
   *str = strdup(newstr);
ce20cb
 }
ce20cb
 
ce20cb
+/*
ce20cb
+  RFC 6265 section 4.1.1 says a server should accept this range:
ce20cb
+
ce20cb
+  cookie-octet    = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
ce20cb
+
ce20cb
+  But Firefox and Chrome as of June 2022 accept space, comma and double-quotes
ce20cb
+  fine. The prime reason for filtering out control bytes is that some HTTP
ce20cb
+  servers return 400 for requests that contain such.
ce20cb
+*/
ce20cb
+static int invalid_octets(const char *p)
ce20cb
+{
ce20cb
+  /* Reject all bytes \x01 - \x1f (*except* \x09, TAB) + \x7f */
ce20cb
+  static const char badoctets[] = {
ce20cb
+    "\x01\x02\x03\x04\x05\x06\x07\x08\x0a"
ce20cb
+    "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14"
ce20cb
+    "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x7f"
ce20cb
+  };
ce20cb
+  size_t vlen, len;
ce20cb
+  /* scan for all the octets that are *not* in cookie-octet */
ce20cb
+  len = strcspn(p, badoctets);
ce20cb
+  vlen = strlen(p);
ce20cb
+  return (len != vlen);
ce20cb
+}
ce20cb
+
ce20cb
 /*
ce20cb
  * remove_expired() removes expired cookies.
ce20cb
  */
ce20cb
@@ -541,6 +565,11 @@ Curl_cookie_add(struct Curl_easy *data,
ce20cb
             badcookie = TRUE;
ce20cb
             break;
ce20cb
           }
ce20cb
+          if(invalid_octets(whatptr) || invalid_octets(name)) {
ce20cb
+            infof(data, "invalid octets in name/value, cookie dropped");
ce20cb
+            badcookie = TRUE;
ce20cb
+            break;
ce20cb
+          }
ce20cb
         }
ce20cb
         else if(!len) {
ce20cb
           /* this was a "<name>=" with no content, and we must allow
ce20cb
-- 
ce20cb
2.37.1
ce20cb
ce20cb
ce20cb
From 1a3e2bd48572761236934651091c899a4d460ef5 Mon Sep 17 00:00:00 2001
ce20cb
From: Daniel Stenberg <daniel@haxx.se>
ce20cb
Date: Mon, 29 Aug 2022 00:09:17 +0200
ce20cb
Subject: [PATCH 3/3] test8: verify that "ctrl-byte cookies" are ignored
ce20cb
ce20cb
Upstream-commit: 2fc031d834d488854ffc58bf7dbcef7fa7c1fc28
ce20cb
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
ce20cb
---
ce20cb
 tests/data/test8 | 32 +++++++++++++++++++++++++++++++-
ce20cb
 1 file changed, 31 insertions(+), 1 deletion(-)
ce20cb
ce20cb
diff --git a/tests/data/test8 b/tests/data/test8
ce20cb
index a8548e6..8587611 100644
ce20cb
--- a/tests/data/test8
ce20cb
+++ b/tests/data/test8
ce20cb
@@ -46,6 +46,36 @@ Set-Cookie: trailingspace    = removed; path=/we/want;
ce20cb
 Set-Cookie: nocookie=yes; path=/WE;
ce20cb
 Set-Cookie: blexp=yesyes; domain=%HOSTIP; domain=%HOSTIP; expiry=totally bad;
ce20cb
 Set-Cookie: partialip=nono; domain=.0.0.1;
ce20cb
+Set-Cookie: cookie1=?-junk
ce20cb
+Set-Cookie: cookie2=?-junk
ce20cb
+Set-Cookie: cookie3=?-junk
ce20cb
+Set-Cookie: cookie4=?-junk
ce20cb
+Set-Cookie: cookie5=?-junk
ce20cb
+Set-Cookie: cookie6=?-junk
ce20cb
+Set-Cookie: cookie7=?-junk
ce20cb
+Set-Cookie: cookie8=?-junk
ce20cb
+Set-Cookie: cookie9=junk-	-
ce20cb
+Set-Cookie: cookie11=?-junk
ce20cb
+Set-Cookie: cookie12=?-junk
ce20cb
+Set-Cookie: cookie14=?-junk
ce20cb
+Set-Cookie: cookie15=?-junk
ce20cb
+Set-Cookie: cookie16=?-junk
ce20cb
+Set-Cookie: cookie17=?-junk
ce20cb
+Set-Cookie: cookie18=?-junk
ce20cb
+Set-Cookie: cookie19=?-junk
ce20cb
+Set-Cookie: cookie20=?-junk
ce20cb
+Set-Cookie: cookie21=?-junk
ce20cb
+Set-Cookie: cookie22=?-junk
ce20cb
+Set-Cookie: cookie23=?-junk
ce20cb
+Set-Cookie: cookie24=?-junk
ce20cb
+Set-Cookie: cookie25=?-junk
ce20cb
+Set-Cookie: cookie26=?-junk
ce20cb
+Set-Cookie: cookie27=?-junk
ce20cb
+Set-Cookie: cookie28=?-junk
ce20cb
+Set-Cookie: cookie29=?-junk
ce20cb
+Set-Cookie: cookie30=?-junk
ce20cb
+Set-Cookie: cookie31=?-junk
ce20cb
+Set-Cookie: cookie31=-junk
ce20cb
 
ce20cb
 </file>
ce20cb
 <precheck>
ce20cb
@@ -62,7 +92,7 @@ perl -e 'if ("%HOSTIP" !~ /\.0\.0\.1$/) {print "Test only works for HOSTIPs endi
ce20cb
 GET /we/want/8 HTTP/1.1
ce20cb
 Host: %HOSTIP:%HTTPPORT
ce20cb
 Accept: */*
ce20cb
-Cookie: name with space=is weird but; trailingspace=removed; cookie=perhaps; cookie=yes; foobar=name; blexp=yesyes
ce20cb
+Cookie: name with space=is weird but; trailingspace=removed; cookie=perhaps; cookie=yes; foobar=name; blexp=yesyes; cookie9=junk-	-
ce20cb
 
ce20cb
 </protocol>
ce20cb
 </verify>
ce20cb
-- 
ce20cb
2.37.1
ce20cb