Skip to content

Commit e473edd

Browse files
committed
("Need to Protect against null Cookie Value, and null Cookie Path & Domain) Collaborative work with Dominic Tootell
1 parent 3010b3e commit e473edd

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/main/java/com/ning/http/client/Cookie.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public String getDomain() {
5656
}
5757

5858
public String getName() {
59-
return name;
59+
return name == null ? "" : name;
6060
}
6161

6262
public String getValue() {
63-
return value;
63+
return value == null ? "" : value;
6464
}
6565

6666
public String getPath() {

src/main/java/com/ning/http/util/AsyncHttpProviderUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ public static Cookie parseCookie(String value) {
400400
String[] fields = value.split(";\\s*");
401401
String[] cookie = fields[0].split("=");
402402
String cookieName = cookie[0];
403-
String cookieValue = cookie[1];
403+
String cookieValue = (cookie.length==1) ? null : cookie[1];
404+
404405
int maxAge = -1;
405406
String path = null;
406407
String domain = null;
@@ -414,6 +415,7 @@ public static Cookie parseCookie(String value) {
414415
secure = true;
415416
} else if (fields[j].indexOf('=') > 0) {
416417
String[] f = fields[j].split("=");
418+
if(f.length==1) continue; // Add protection against null field values
417419

418420
// favor 'max-age' field over 'expires'
419421
if (!maxAgeSet && "max-age".equalsIgnoreCase(f[0])) {

src/test/java/com/ning/http/client/async/RemoteSiteTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,23 @@ public void stripQueryStringNegativeTest() throws Throwable {
221221
c.close();
222222
}
223223

224+
@Test(groups = {"online", "default_provider"})
225+
public void evilCoookieTest() throws Throwable {
226+
AsyncHttpClient c = getAsyncHttpClient(null);
227+
228+
RequestBuilder builder2 = new RequestBuilder("GET");
229+
builder2.setFollowRedirects(true);
230+
builder2.setUrl("http://www.google.com/");
231+
builder2.addHeader("Content-Type", "text/plain");
232+
builder2.addCookie(new com.ning.http.client.Cookie(".google.com", "evilcookie", "test", "/", 10, false));
233+
com.ning.http.client.Request request2 = builder2.build();
234+
Response response = c.executeRequest(request2).get();
235+
236+
assertNotNull(response);
237+
assertEquals(response.getStatusCode(), 200);
238+
c.close();
239+
}
240+
224241
@Test(groups = {"online", "default_provider"}, enabled = false)
225242
public void testAHC62Com() throws Throwable {
226243
AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build());

0 commit comments

Comments
 (0)