3a27f0
From 0b7dd36575821bd6e4e86f7b51ac001e69abddf9 Mon Sep 17 00:00:00 2001
3a27f0
From: Kamil Dudka <kdudka@redhat.com>
3a27f0
Date: Fri, 12 Apr 2013 15:53:39 +0200
3a27f0
Subject: [PATCH 1/3] test1216: test tailmatching cookie domains
3a27f0
3a27f0
This test is an attempt to repeat the problem YAMADA Yasuharu reported
3a27f0
at http://curl.haxx.se/mail/lib-2013-04/0108.html
3a27f0
3a27f0
Conflicts:
3a27f0
3a27f0
	tests/data/Makefile.am
3a27f0
3a27f0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
3a27f0
---
3a27f0
 tests/data/Makefile.am |    2 +-
3a27f0
 tests/data/Makefile.in |    2 +-
3a27f0
 tests/data/test1216    |   62 ++++++++++++++++++++++++++++++++++++++++++++++++
3a27f0
 3 files changed, 64 insertions(+), 2 deletions(-)
3a27f0
 create mode 100644 tests/data/test1216
3a27f0
3a27f0
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
3a27f0
index 9f569a3..d714e5d 100644
3a27f0
--- a/tests/data/Makefile.am
3a27f0
+++ b/tests/data/Makefile.am
3a27f0
@@ -77,7 +77,7 @@ test1110 test1111 test1112 test1113 test1114 test1115 test1116 test1117	\
3a27f0
 test1118 test1119 test1120 test1121 test1122 test1123 test1124 test1125	\
3a27f0
 test1126 test1127 test1128 test1129 test1130 test1131 test1132 test1133 \
3a27f0
 test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 \
3a27f0
-test1208 test1209 test1210 test1211 \
3a27f0
+test1208 test1209 test1210 test1211 test1216 \
3a27f0
 test1220 test1221 test1222 test1223 \
3a27f0
 test1300 test1301 test1302 test1303 test1304 test1305	\
3a27f0
 test1306 test1307 test1308 test1309 test1310 test1311 test1312 test1313 \
3a27f0
diff --git a/tests/data/Makefile.in b/tests/data/Makefile.in
3a27f0
index d5b0918..a070266 100644
3a27f0
--- a/tests/data/Makefile.in
3a27f0
+++ b/tests/data/Makefile.in
3a27f0
@@ -341,7 +341,7 @@ test1110 test1111 test1112 test1113 test1114 test1115 test1116 test1117	\
3a27f0
 test1118 test1119 test1120 test1121 test1122 test1123 test1124 test1125	\
3a27f0
 test1126 test1127 test1128 test1129 test1130 test1131 test1132 test1133 \
3a27f0
 test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 \
3a27f0
-test1208 test1209 test1210 test1211 \
3a27f0
+test1208 test1209 test1210 test1211 test1216 \
3a27f0
 test1220 test1221 test1222 test1223 \
3a27f0
 test1300 test1301 test1302 test1303 test1304 test1305	\
3a27f0
 test1306 test1307 test1308 test1309 test1310 test1311 test1312 test1313 \
3a27f0
diff --git a/tests/data/test1216 b/tests/data/test1216
3a27f0
new file mode 100644
3a27f0
index 0000000..e63fe92
3a27f0
--- /dev/null
3a27f0
+++ b/tests/data/test1216
3a27f0
@@ -0,0 +1,62 @@
3a27f0
+<testcase>
3a27f0
+<info>
3a27f0
+<keywords>
3a27f0
+HTTP
3a27f0
+HTTP GET
3a27f0
+HTTP proxy
3a27f0
+cookies
3a27f0
+</keywords>
3a27f0
+</info>
3a27f0
+
3a27f0
+# Server-side
3a27f0
+<reply>
3a27f0
+<data>
3a27f0
+HTTP/1.1 200 OK
3a27f0
+Server: Microsoft-IIS/4.0
3a27f0
+Date: Tue, 25 Sep 2001 19:37:44 GMT
3a27f0
+Content-Type: text/html
3a27f0
+Connection: close
3a27f0
+Content-Length: 21
3a27f0
+
3a27f0
+This server says moo
3a27f0
+</data>
3a27f0
+</reply>
3a27f0
+
3a27f0
+# Client-side
3a27f0
+<client>
3a27f0
+<server>
3a27f0
+http
3a27f0
+</server>
3a27f0
+ <name>
3a27f0
+HTTP cookie domains tailmatching the host name
3a27f0
+ </name>
3a27f0
+ <command>
3a27f0
+http://example.fake/c/1216 http://bexample.fake/c/1216 -b log/injar1216 -x %HOSTIP:%HTTPPORT
3a27f0
+</command>
3a27f0
+<file name="log/injar1216">
3a27f0
+example.fake	FALSE	/a	FALSE	2139150993	mooo	indeed
3a27f0
+example.fake	FALSE	/b	FALSE	0		moo1	indeed
3a27f0
+example.fake	FALSE	/c	FALSE	2139150993	moo2	indeed
3a27f0
+</file>
3a27f0
+</client>
3a27f0
+
3a27f0
+# Verify data after the test has been "shot"
3a27f0
+<verify>
3a27f0
+<strip>
3a27f0
+^User-Agent:.*
3a27f0
+</strip>
3a27f0
+<protocol>
3a27f0
+GET http://example.fake/c/1216 HTTP/1.1
3a27f0
+Host: example.fake
3a27f0
+Accept: */*
3a27f0
+Proxy-Connection: Keep-Alive
3a27f0
+Cookie: moo2=indeed
3a27f0
+
3a27f0
+GET http://bexample.fake/c/1216 HTTP/1.1
3a27f0
+Host: bexample.fake
3a27f0
+Accept: */*
3a27f0
+Proxy-Connection: Keep-Alive
3a27f0
+
3a27f0
+</protocol>
3a27f0
+</verify>
3a27f0
+</testcase>
3a27f0
-- 
3a27f0
1.7.1
3a27f0
3a27f0
3a27f0
From 6c5a78d0407788b1092bbc8a19b68b01ccb75f8a Mon Sep 17 00:00:00 2001
3a27f0
From: YAMADA Yasuharu <yasuharu.yamada@access-company.com>
3a27f0
Date: Thu, 11 Apr 2013 00:17:15 +0200
3a27f0
Subject: [PATCH 2/3] cookie: fix tailmatching to prevent cross-domain leakage
3a27f0
3a27f0
Cookies set for 'example.com' could accidentaly also be sent by libcurl
3a27f0
to the 'bexample.com' (ie with a prefix to the first domain name).
3a27f0
3a27f0
This is a security vulnerabilty, CVE-2013-1944.
3a27f0
3a27f0
Bug: http://curl.haxx.se/docs/adv_20130412.html
3a27f0
3a27f0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
3a27f0
---
3a27f0
 lib/cookie.c |   24 +++++++++++++++++++-----
3a27f0
 1 files changed, 19 insertions(+), 5 deletions(-)
3a27f0
3a27f0
diff --git a/lib/cookie.c b/lib/cookie.c
3a27f0
index 18b9155..d4fd78a 100644
3a27f0
--- a/lib/cookie.c
3a27f0
+++ b/lib/cookie.c
3a27f0
@@ -118,15 +118,29 @@ static void freecookie(struct Cookie *co)
3a27f0
   free(co);
3a27f0
 }
3a27f0
 
3a27f0
-static bool tailmatch(const char *little, const char *bigone)
3a27f0
+static bool tailmatch(const char *cooke_domain, const char *hostname)
3a27f0
 {
3a27f0
-  size_t littlelen = strlen(little);
3a27f0
-  size_t biglen = strlen(bigone);
3a27f0
+  size_t cookie_domain_len = strlen(cooke_domain);
3a27f0
+  size_t hostname_len = strlen(hostname);
3a27f0
 
3a27f0
-  if(littlelen > biglen)
3a27f0
+  if(hostname_len < cookie_domain_len)
3a27f0
     return FALSE;
3a27f0
 
3a27f0
-  return Curl_raw_equal(little, bigone+biglen-littlelen) ? TRUE : FALSE;
3a27f0
+  if(!Curl_raw_equal(cooke_domain, hostname+hostname_len-cookie_domain_len))
3a27f0
+    return FALSE;
3a27f0
+
3a27f0
+  /* A lead char of cookie_domain is not '.'.
3a27f0
+     RFC6265 4.1.2.3. The Domain Attribute says:
3a27f0
+       For example, if the value of the Domain attribute is
3a27f0
+       "example.com", the user agent will include the cookie in the Cookie
3a27f0
+       header when making HTTP requests to example.com, www.example.com, and
3a27f0
+       www.corp.example.com.
3a27f0
+   */
3a27f0
+  if(hostname_len == cookie_domain_len)
3a27f0
+    return TRUE;
3a27f0
+  if('.' == *(hostname + hostname_len - cookie_domain_len - 1))
3a27f0
+    return TRUE;
3a27f0
+  return FALSE;
3a27f0
 }
3a27f0
 
3a27f0
 /*
3a27f0
-- 
3a27f0
1.7.1
3a27f0
3a27f0
3a27f0
From 6284e78c9421911a24349621c5b63684823d12f7 Mon Sep 17 00:00:00 2001
3a27f0
From: Kamil Dudka <kdudka@redhat.com>
3a27f0
Date: Fri, 12 Apr 2013 15:55:57 +0200
3a27f0
Subject: [PATCH 3/3] test1218: another cookie tailmatch test
3a27f0
3a27f0
These tests verify commit 3604fde3d3c9b0d, the fix for the "cookie
3a27f0
domain tailmatch" vulnerability. See
3a27f0
http://curl.haxx.se/docs/adv_20130412.html
3a27f0
3a27f0
Conflicts:
3a27f0
3a27f0
	tests/data/Makefile.am
3a27f0
3a27f0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
3a27f0
---
3a27f0
 tests/data/Makefile.am |    2 +-
3a27f0
 tests/data/Makefile.in |    2 +-
3a27f0
 tests/data/test1218    |   61 ++++++++++++++++++++++++++++++++++++++++++++++++
3a27f0
 3 files changed, 63 insertions(+), 2 deletions(-)
3a27f0
 create mode 100644 tests/data/test1218
3a27f0
3a27f0
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
3a27f0
index d714e5d..3e8dae0 100644
3a27f0
--- a/tests/data/Makefile.am
3a27f0
+++ b/tests/data/Makefile.am
3a27f0
@@ -77,7 +77,7 @@ test1110 test1111 test1112 test1113 test1114 test1115 test1116 test1117	\
3a27f0
 test1118 test1119 test1120 test1121 test1122 test1123 test1124 test1125	\
3a27f0
 test1126 test1127 test1128 test1129 test1130 test1131 test1132 test1133 \
3a27f0
 test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 \
3a27f0
-test1208 test1209 test1210 test1211 test1216 \
3a27f0
+test1208 test1209 test1210 test1211 test1216 test1218 \
3a27f0
 test1220 test1221 test1222 test1223 \
3a27f0
 test1300 test1301 test1302 test1303 test1304 test1305	\
3a27f0
 test1306 test1307 test1308 test1309 test1310 test1311 test1312 test1313 \
3a27f0
diff --git a/tests/data/Makefile.in b/tests/data/Makefile.in
3a27f0
index a070266..71c9422 100644
3a27f0
--- a/tests/data/Makefile.in
3a27f0
+++ b/tests/data/Makefile.in
3a27f0
@@ -341,7 +341,7 @@ test1110 test1111 test1112 test1113 test1114 test1115 test1116 test1117	\
3a27f0
 test1118 test1119 test1120 test1121 test1122 test1123 test1124 test1125	\
3a27f0
 test1126 test1127 test1128 test1129 test1130 test1131 test1132 test1133 \
3a27f0
 test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 \
3a27f0
-test1208 test1209 test1210 test1211 test1216 \
3a27f0
+test1208 test1209 test1210 test1211 test1216 test1218 \
3a27f0
 test1220 test1221 test1222 test1223 \
3a27f0
 test1300 test1301 test1302 test1303 test1304 test1305	\
3a27f0
 test1306 test1307 test1308 test1309 test1310 test1311 test1312 test1313 \
3a27f0
diff --git a/tests/data/test1218 b/tests/data/test1218
3a27f0
new file mode 100644
3a27f0
index 0000000..7d86547
3a27f0
--- /dev/null
3a27f0
+++ b/tests/data/test1218
3a27f0
@@ -0,0 +1,61 @@
3a27f0
+<testcase>
3a27f0
+<info>
3a27f0
+<keywords>
3a27f0
+HTTP
3a27f0
+HTTP GET
3a27f0
+HTTP proxy
3a27f0
+cookies
3a27f0
+</keywords>
3a27f0
+</info>
3a27f0
+
3a27f0
+# This test is very similar to 1216, only that it sets the cookies from the
3a27f0
+# first site instead of reading from a file
3a27f0
+<reply>
3a27f0
+<data>
3a27f0
+HTTP/1.1 200 OK
3a27f0
+Date: Tue, 25 Sep 2001 19:37:44 GMT
3a27f0
+Set-Cookie: domain=.example.fake; bug=fixed;
3a27f0
+Content-Length: 21
3a27f0
+
3a27f0
+This server says moo
3a27f0
+</data>
3a27f0
+</reply>
3a27f0
+
3a27f0
+# Client-side
3a27f0
+<client>
3a27f0
+<server>
3a27f0
+http
3a27f0
+</server>
3a27f0
+ <name>
3a27f0
+HTTP cookies and domains with same prefix
3a27f0
+ </name>
3a27f0
+ <command>
3a27f0
+http://example.fake/c/1218 http://example.fake/c/1218 http://bexample.fake/c/1218 -b nonexisting -x %HOSTIP:%HTTPPORT
3a27f0
+</command>
3a27f0
+</client>
3a27f0
+
3a27f0
+# Verify data after the test has been "shot"
3a27f0
+<verify>
3a27f0
+<strip>
3a27f0
+^User-Agent:.*
3a27f0
+</strip>
3a27f0
+<protocol>
3a27f0
+GET http://example.fake/c/1218 HTTP/1.1
3a27f0
+Host: example.fake
3a27f0
+Accept: */*
3a27f0
+Proxy-Connection: Keep-Alive
3a27f0
+
3a27f0
+GET http://example.fake/c/1218 HTTP/1.1
3a27f0
+Host: example.fake
3a27f0
+Accept: */*
3a27f0
+Proxy-Connection: Keep-Alive
3a27f0
+Cookie: bug=fixed
3a27f0
+
3a27f0
+GET http://bexample.fake/c/1218 HTTP/1.1
3a27f0
+Host: bexample.fake
3a27f0
+Accept: */*
3a27f0
+Proxy-Connection: Keep-Alive
3a27f0
+
3a27f0
+</protocol>
3a27f0
+</verify>
3a27f0
+</testcase>
3a27f0
-- 
3a27f0
1.7.1
3a27f0