Skip to content

Commit b8764d2

Browse files
committed
Fix allowed cookie values chars, backport AsyncHttpClient#1115
1 parent e8ac297 commit b8764d2

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

src/main/java/com/ning/http/client/cookie/CookieUtil.java

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,46 @@ public class CookieUtil {
2222

2323
private static final BitSet VALID_COOKIE_NAME_OCTETS = validCookieNameOctets(VALID_COOKIE_VALUE_OCTETS);
2424

25+
// cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
2526
// US-ASCII characters excluding CTLs, whitespace, DQUOTE, comma, semicolon, and backslash
2627
private static BitSet validCookieValueOctets() {
27-
2828
BitSet bits = new BitSet(8);
29-
for (int i = 35; i < 127; i++) {
30-
// US-ASCII characters excluding CTLs (%x00-1F / %x7F)
29+
bits.set(0x21);
30+
for (int i = 0x23; i <= 0x2B; i++) {
31+
bits.set(i);
32+
}
33+
for (int i = 0x2D; i <= 0x3A; i++) {
34+
bits.set(i);
35+
}
36+
for (int i = 0x3C; i <= 0x5B; i++) {
37+
bits.set(i);
38+
}
39+
for (int i = 0x5D; i <= 0x7E; i++) {
3140
bits.set(i);
3241
}
33-
bits.set('"', false); // exclude DQUOTE = %x22
34-
bits.set(',', false); // exclude comma = %x2C
35-
bits.set(';', false); // exclude semicolon = %x3B
36-
bits.set('\\', false); // exclude backslash = %x5C
3742
return bits;
3843
}
3944

40-
// token = 1*<any CHAR except CTLs or separators>
41-
// separators = "(" | ")" | "<" | ">" | "@"
42-
// | "," | ";" | ":" | "\" | <">
43-
// | "/" | "[" | "]" | "?" | "="
44-
// | "{" | "}" | SP | HT
45+
// token = 1*<any CHAR except CTLs or separators>
46+
// separators = "(" | ")" | "<" | ">" | "@"
47+
// | "," | ";" | ":" | "\" | <">
48+
// | "/" | "[" | "]" | "?" | "="
49+
// | "{" | "}" | SP | HT
4550
private static BitSet validCookieNameOctets(BitSet validCookieValueOctets) {
4651
BitSet bits = new BitSet(8);
47-
bits.or(validCookieValueOctets);
52+
for (int i = 32; i < 127; i++) {
53+
bits.set(i);
54+
}
4855
bits.set('(', false);
4956
bits.set(')', false);
5057
bits.set('<', false);
5158
bits.set('>', false);
5259
bits.set('@', false);
60+
bits.set(',', false);
61+
bits.set(';', false);
5362
bits.set(':', false);
63+
bits.set('\\', false);
64+
bits.set('"', false);
5465
bits.set('/', false);
5566
bits.set('[', false);
5667
bits.set(']', false);
@@ -62,7 +73,7 @@ private static BitSet validCookieNameOctets(BitSet validCookieValueOctets) {
6273
bits.set('\t', false);
6374
return bits;
6475
}
65-
76+
6677
static int firstInvalidCookieNameOctet(CharSequence cs) {
6778
return firstInvalidOctet(cs, VALID_COOKIE_NAME_OCTETS);
6879
}
@@ -103,10 +114,10 @@ static long computeExpiresAsMaxAge(String expires) {
103114
return maxAgeMillis / 1000 + (maxAgeMillis % 1000 != 0 ? 1 : 0);
104115
}
105116
}
106-
117+
107118
return Long.MIN_VALUE;
108119
}
109-
120+
110121
private CookieUtil() {
111122
// Unused
112123
}

0 commit comments

Comments
 (0)