Jun
8
2005

What I should have known about javax.servlet.http.Cookie

After beating my head against a wall for three hours wondering why setPath() and setDomain() were just not working on my Cookie object…. I got a brainwave. Maybe it wasn’t that the core libraries were broken…. maybe my payload was dodgy. It did have newlines in it, but the object would handle that for me, right?

In retrospect I should have read the Javadoc ;-)


With Version 0 cookies, values should not contain white space, brackets, parentheses, equals signs, commas,double quotes, slashes, question marks, at signs, colons, and semicolons. Empty values may not behave the same way on all browsers.

In the end I just needed to do a myPayload.replace('n', ' '); to kill off the offending newline (which I guess just gets passed verbatim to Set-Header). I must be using v1 cookies, since it didn’t seem to mind about the space.

Anyways… a learning experience.

About the Author: Glen Smith

2 Comments + Add Comment

  • Thank you Glen for an informative post. I wish more blogs would contain some answers to the “hair pulling” questions instead of concentrating solely on theories and framework bashing. I look forward to more nuggets from you. Thanks for puttin’ yourself out there.

  • Google led me here and I thank you, this saved me what I’m sure would have been hours or a nasty hackjob instead.

    Thanks again!

Leave a comment

Glen Smith

About Glen

Co-author Grails in Action