user1122069
user1122069

Reputation: 1817

Cookies with "[]" symbols aren't parsed by Java servlets

I've tried sending cookies like "test[]=111" to Java servlets, and the systems (Tomcat, Jetty) ignore the cookie and do not populate it.

The same cookie is valid on a PHP system and also on the browser. Is "test[]" a valid cookie name? Or if so, since most browsers seem to support it, why is it ignored on Java servlets?

Upvotes: 0

Views: 34

Answers (1)

Steve C
Steve C

Reputation: 19445

According to RFC-6265, a cookie name is a token.

RFC-2616 defines a token as:

   token          = 1*<any CHAR except CTLs or separators>
   separators     = "(" | ")" | "<" | ">" | "@"
                  | "," | ";" | ":" | "\" | <">
                  | "/" | "[" | "]" | "?" | "="
                  | "{" | "}" | SP | HT

Your cookie name is invalid as [] fall into the "separators" category.

Upvotes: 2

Related Questions