summaryrefslogtreecommitdiffstats
path: root/curl-7.15.5-CVE-2013-1944.patch
blob: d6062ce8b45f142149bc0702026fe7298c4d8fe1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
From 3ecd4749cf14d33240d3b6e89d7014699881b8a1 Mon Sep 17 00:00:00 2001
From: Yang Tse <yangsita@gmail.com>
Date: Fri, 2 Feb 2007 01:36:08 +0000
Subject: [PATCH 1/5] fix test case 62 which was failing due to cookies expiring 1 Feb 2007


Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 tests/data/test62 |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/data/test62 b/tests/data/test62
index 6d01f88..847a0ab 100644
--- a/tests/data/test62
+++ b/tests/data/test62
@@ -32,9 +32,9 @@ http://%HOSTIP:%HTTPPORT/we/want/62 -b log/jar62.txt -H "Host: www.host.foo.com"
 # http://www.netscape.com/newsref/std/cookie_spec.html
 # This file was generated by libcurl! Edit at your own risk.
 
-.foo.com	TRUE	/we/want/	FALSE	1170327387	test	yes
-.host.foo.com	TRUE	/we/want/	FALSE	1170327387	test2	yes
-.fake.host.foo.com	TRUE	/we/want/	FALSE	1170327387	test4	yes
+.foo.com	TRUE	/we/want/	FALSE	2147483647	test	yes
+.host.foo.com	TRUE	/we/want/	FALSE	2147483647	test2	yes
+.fake.host.foo.com	TRUE	/we/want/	FALSE	2147483647	test4	yes
 
 .foo.com	TRUE	/moo	TRUE	0	test3	maybe
 </file>
-- 
1.7.1


From 4feeba0a65d65a390a7d53e3212e3fe2b589e339 Mon Sep 17 00:00:00 2001
From: Yang Tse <yangsita@gmail.com>
Date: Mon, 5 Feb 2007 02:38:25 +0000
Subject: [PATCH 2/5] Year 2038 has its own problems (32 bit integer overflow). So cookie expiration date is lowered to expire at most in 2035.


Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 tests/data/test62 |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tests/data/test62 b/tests/data/test62
index 847a0ab..d3d0715 100644
--- a/tests/data/test62
+++ b/tests/data/test62
@@ -32,9 +32,9 @@ http://%HOSTIP:%HTTPPORT/we/want/62 -b log/jar62.txt -H "Host: www.host.foo.com"
 # http://www.netscape.com/newsref/std/cookie_spec.html
 # This file was generated by libcurl! Edit at your own risk.
 
-.foo.com	TRUE	/we/want/	FALSE	2147483647	test	yes
-.host.foo.com	TRUE	/we/want/	FALSE	2147483647	test2	yes
-.fake.host.foo.com	TRUE	/we/want/	FALSE	2147483647	test4	yes
+.foo.com	TRUE	/we/want/	FALSE	2054030187	test	yes
+.host.foo.com	TRUE	/we/want/	FALSE	2054030187	test2	yes
+.fake.host.foo.com	TRUE	/we/want/	FALSE	2054030187	test4	yes
 
 .foo.com	TRUE	/moo	TRUE	0	test3	maybe
 </file>
-- 
1.7.1


From d12cbcf4a507fd57976c3a877ab1e629a1e24677 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Sat, 13 Apr 2013 14:11:12 +0200
Subject: [PATCH 3/5] test1216: test tailmatching cookie domains

This test is an attempt to repeat the problem YAMADA Yasuharu reported
at http://curl.haxx.se/mail/lib-2013-04/0108.html

Conflicts:

	tests/data/Makefile.am

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 tests/data/Makefile.am |    2 +-
 tests/data/test1216    |   62 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 1 deletions(-)
 create mode 100644 tests/data/test1216

diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
index 233bf03..ae555c6 100644
--- a/tests/data/Makefile.am
+++ b/tests/data/Makefile.am
@@ -34,5 +34,5 @@ EXTRA_DIST = test1 test108 test117 test127 test20 test27 test34 test46	   \
  test250 test251 test252 test253 test254 test255 test521 test522 test523   \
  test256 test257 test258 test259 test260 test261 test262 test263 test264   \
  test265 test266 test267 test268 test269 test270 test271 test272 test273   \
- test274 test275 test524 test276 test277
+ test274 test275 test524 test276 test277 test1216
 
diff --git a/tests/data/test1216 b/tests/data/test1216
new file mode 100644
index 0000000..a87b812
--- /dev/null
+++ b/tests/data/test1216
@@ -0,0 +1,62 @@
+<info>
+<keywords>
+HTTP
+HTTP GET
+HTTP proxy
+cookies
+</keywords>
+</info>
+
+# Server-side
+<reply>
+<data>
+HTTP/1.1 200 OK
+Server: Microsoft-IIS/4.0
+Date: Tue, 25 Sep 2001 19:37:44 GMT
+Content-Type: text/html
+Connection: close
+Content-Length: 21
+
+This server says moo
+</data>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+ <name>
+HTTP cookie domains tailmatching the host name
+ </name>
+ <command>
+http://example.fake/c/1216 http://bexample.fake/c/1216 -b log/injar1216 -x %HOSTIP:%HTTPPORT
+</command>
+<file name="log/injar1216">
+example.fake	FALSE	/a	FALSE	2139150993	mooo	indeed
+example.fake	FALSE	/b	FALSE	0		moo1	indeed
+example.fake	FALSE	/c	FALSE	2139150993	moo2	indeed
+</file>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<strip>
+^User-Agent:.*
+</strip>
+<protocol>
+GET http://example.fake/c/1216 HTTP/1.1
+Host: example.fake
+Pragma: no-cache
+Accept: */*
+Proxy-Connection: Keep-Alive
+Cookie: moo2=indeed
+
+GET http://bexample.fake/c/1216 HTTP/1.1
+Host: bexample.fake
+Pragma: no-cache
+Accept: */*
+Proxy-Connection: Keep-Alive
+
+</protocol>
+</verify>
-- 
1.7.1


From e489a51084884148bd9c014f5fa4d9f4189a86a0 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Sat, 13 Apr 2013 14:12:13 +0200
Subject: [PATCH 4/5] cookie: fix tailmatching to prevent cross-domain leakage

Cookies set for 'example.com' could accidentaly also be sent by libcurl
to the 'bexample.com' (ie with a prefix to the first domain name).

This is a security vulnerabilty, CVE-2013-1944.

Bug: http://curl.haxx.se/docs/adv_20130412.html

Conflicts:

	lib/cookie.c

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 lib/cookie.c |   24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/lib/cookie.c b/lib/cookie.c
index 779ca4c..ddd10a6 100644
--- a/lib/cookie.c
+++ b/lib/cookie.c
@@ -124,15 +124,29 @@ static void freecookie(struct Cookie *co)
   free(co);
 }
 
-static bool tailmatch(const char *little, const char *bigone)
+static bool tailmatch(const char *cooke_domain, const char *hostname)
 {
-  size_t littlelen = strlen(little);
-  size_t biglen = strlen(bigone);
+  size_t cookie_domain_len = strlen(cooke_domain);
+  size_t hostname_len = strlen(hostname);
 
-  if(littlelen > biglen)
+  if(hostname_len < cookie_domain_len)
     return FALSE;
 
-  return (bool)strequal(little, bigone+biglen-littlelen);
+  if(!strequal(cooke_domain, hostname+hostname_len-cookie_domain_len))
+    return FALSE;
+
+  /* A lead char of cookie_domain is not '.'.
+     RFC6265 4.1.2.3. The Domain Attribute says:
+       For example, if the value of the Domain attribute is
+       "example.com", the user agent will include the cookie in the Cookie
+       header when making HTTP requests to example.com, www.example.com, and
+       www.corp.example.com.
+   */
+  if(hostname_len == cookie_domain_len)
+    return TRUE;
+  if('.' == *(hostname + hostname_len - cookie_domain_len - 1))
+    return TRUE;
+  return FALSE;
 }
 
 /*
-- 
1.7.1


From 9f76a41483fa6737a58e32d9bca3cab1d56e5d58 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Sat, 13 Apr 2013 14:13:15 +0200
Subject: [PATCH 5/5] test1218: another cookie tailmatch test

These tests verify commit 3604fde3d3c9b0d, the fix for the "cookie
domain tailmatch" vulnerability. See
http://curl.haxx.se/docs/adv_20130412.html

Conflicts:

	tests/data/Makefile.am

Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 tests/data/Makefile.am |    2 +-
 tests/data/test1218    |   62 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 1 deletions(-)
 create mode 100644 tests/data/test1218

diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
index ae555c6..8f2e83e 100644
--- a/tests/data/Makefile.am
+++ b/tests/data/Makefile.am
@@ -34,5 +34,5 @@ EXTRA_DIST = test1 test108 test117 test127 test20 test27 test34 test46	   \
  test250 test251 test252 test253 test254 test255 test521 test522 test523   \
  test256 test257 test258 test259 test260 test261 test262 test263 test264   \
  test265 test266 test267 test268 test269 test270 test271 test272 test273   \
- test274 test275 test524 test276 test277 test1216
+ test274 test275 test524 test276 test277 test1216 test1218
 
diff --git a/tests/data/test1218 b/tests/data/test1218
new file mode 100644
index 0000000..9e2d63b
--- /dev/null
+++ b/tests/data/test1218
@@ -0,0 +1,62 @@
+<info>
+<keywords>
+HTTP
+HTTP GET
+HTTP proxy
+cookies
+</keywords>
+</info>
+
+# This test is very similar to 1216, only that it sets the cookies from the
+# first site instead of reading from a file
+<reply>
+<data>
+HTTP/1.1 200 OK
+Date: Tue, 25 Sep 2001 19:37:44 GMT
+Set-Cookie: domain=.example.fake; bug=fixed;
+Content-Length: 21
+
+This server says moo
+</data>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+ <name>
+HTTP cookies and domains with same prefix
+ </name>
+ <command>
+http://example.fake/c/1218 http://example.fake/c/1218 http://bexample.fake/c/1218 -b nonexisting -x %HOSTIP:%HTTPPORT
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<strip>
+^User-Agent:.*
+</strip>
+<protocol>
+GET http://example.fake/c/1218 HTTP/1.1
+Host: example.fake
+Pragma: no-cache
+Accept: */*
+Proxy-Connection: Keep-Alive
+
+GET http://example.fake/c/1218 HTTP/1.1
+Host: example.fake
+Pragma: no-cache
+Accept: */*
+Proxy-Connection: Keep-Alive
+Cookie: bug=fixed
+
+GET http://bexample.fake/c/1218 HTTP/1.1
+Host: bexample.fake
+Pragma: no-cache
+Accept: */*
+Proxy-Connection: Keep-Alive
+
+</protocol>
+</verify>
-- 
1.7.1