You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Callinswood,Kevin,VEVEY,GLOBE BTC" <Ke...@nestle.com> on 2014/02/02 20:31:13 UTC

cookie issue with Tomcat 7 - does not accept the character "é"

We have upgraded to Tomcat 7 from Tomcat 6 and we are now facing issues due to some of the standard company cookies containing an "é".

Tomcat 6 accepted the "é" but upgrading to Tomcat 7  we get an error if the "é" is any parameter except for the 1st position.  The error received is:

SEVERE: Error processing request
java.lang.IllegalArgumentException: Control character in cookie value
or attribute.

I have tried playing around with the parameters in the catalana.properties file but with no success.  Is there a way to remove all checking of cookies ?

Possible solutions are to revert to Tomcat 6, change web server, or encode the cookies.  We are planning a go-live a week from now so reverting to Tomcat 6 seems to be the solution in the short term. 

Thanks in advance for any advice on this,

Kevin CALLINSWOOD


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: cookie issue with Tomcat 7 - does not accept the character "é"

Posted by "Callinswood,Kevin,VEVEY,GLOBE BTC" <Ke...@nestle.com>.
We have a cookie generated by the home page of our intranet as follows: 

Cookie:  GetUser_Properties="abc","abc","abc","abc","abc","abc","abc","abc","abc";

If you put an é in the first parameter e.g. 
Cookie:  GetUser_Properties="abcé","abc","abc","abc","abc","abc","abc","abc","abc"; 
Then we get result = 200 (success)

If you put an é in any other parameter e.g. 
Cookie:  GetUser_Properties="abc","abcé","abc","abc","abc","abc","abc","abc","abc"; 
Then we the HTTP error = 500.

It's a strange one, and I guess the "é" in the 1st position should also generate HTTP 500 error but it doesn’t.  However, my main concern is that the "é" could appear in any position in the cookie, and therefore we have an issue.

Thanks, Kevin.

-----Original Message-----
From: Christopher Schultz [mailto:chris@christopherschultz.net] 
Sent: dimanche 2 février 2014 21:00
To: Tomcat Users List
Subject: Re: cookie issue with Tomcat 7 - does not accept the character "é"

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Kevin,

On 2/2/14, 2:31 PM, Callinswood,Kevin,VEVEY,GLOBE BTC wrote:
> We have upgraded to Tomcat 7 from Tomcat 6 and we are now facing 
> issues due to some of the standard company cookies containing an "é".
> 
> Tomcat 6 accepted the "é" but upgrading to Tomcat 7 we get an error if 
> the "é" is any parameter except for the 1st position.

What you do mean "any parameter except for the 1st position"? You said this was about cookies...

> The error received is:
> 
> SEVERE: Error processing request
> java.lang.IllegalArgumentException: Control character in cookie value 
> or attribute.

Can you give a protocol dump including byte-translation? For example, é is usually expressed as 0xc9 and appears in ISO-8859-1 as a single byte. Since it's in the top-half of the ISO-8859-1 character set,
UTF-8 requires that it be represented by two bytes: 0xc3 0xa9

Without quoting, unquoted Cookie names and values may be any US-ASCII character from 0x32 - 0x7e except for any of ("(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{"
| "}" | SP | HT). None of the characters above are within that range,
so the cookie value must be quoted. (It looks to me like Cookie names must always be in US-ASCII... I didn't think that was the case but I'm not motivated to track-down every word of the spec looking for justification).

What is the character encoding of the request? What client are you using? Who created the cookie in the first place?

> I have tried playing around with the parameters in the 
> catalana.properties file but with no success.  Is there a way to 
> remove all checking of cookies ?

Tomcat has become more standards-strict in version 7. This page should give you a bit of insight, though it is quite technical:
http://wiki.apache.org/tomcat/Cookies

> Possible solutions are to revert to Tomcat 6, change web server, or 
> encode the cookies.  We are planning a go-live a week from now so 
> reverting to Tomcat 6 seems to be the solution in the short term.

You decided to start testing with a new major application server version 1 week before deployment? Hmm. Sounds like using Tomcat 6 is the right short-term move. You really need to identify the problem,
though: it's only going to get worse.

Now, if you had Tomcat 6 create those cookies and the client is sending them back tom Tomcat 7, then you may want to expire those old cookies and see what a Tomcat 7 roundtrip looks like. Tomcat 7 may be more properly encoding the cookies in the first place, solving the problem before it begins.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJS7qPGAAoJEBzwKT+lPKRYmeEP/A8O5vxtTJ2dnQnQn6dzkNv7
g+YSx8c1Va1QkHlZe1vUefUlZJ1SkzFivbmyTX3TFsKI8wDPNOWRjJusHxDKnIjl
URpeCew8/1vUWtuN1xvCXO4OWE5UdPRktmKn+aO4anuKvZGrl7OnEMXx0Ans4U9k
6SLYcYkT8rnwjrwyp5/xoc8hEaUWRHQZCNAaU1//OC0OFV+MLiL2IgVucg8CdvIk
v/z5DxIvGvhTkHBzWztlOku6l43yyJMEs8XsYPGwOgAY4KYu1vDLMBtDq3HZ9Coz
mSX3ytGrth3XAJbPdcopYcVU96XFEtOPwvBcGU+GEVf2Gc0C1GWE1ZVntwlTAbvD
TBISsjzuOouI/6LjjdCAUnHNBjnHGv0vk0R3CFXu4igxDKM/2CrBA/keJ7IUYQku
dB/y4hsNPkQ4wHJVLof7l+bYI6TbzS6xVpR3QPwlmVub0mRiYND4kcnDYrf21SFU
hsAewZyRGxk41pM/Y5e0Ep1tCqVbgMn76nwuhmL07YLnkY7+75LMVJgnT2HA4ZXh
SUwB2zp4qa43baQ0T+iAe6a1wEPRjdlV2PKeHlFv1u304HG8Ke4bB6QBQWlWDXYr
lqiqMetQNrkKK6WXmGkvkXnu736EGizeMY/D+C7RFPb5i+7ejsX/nMV5C6nHrZM9
xX9SxRXlZkABNFwV+8kg
=0leN
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



Re: [OT] cookie issue with Tomcat 7 - does not accept the character "é"

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

André,

On 2/4/14, 5:59 AM, André Warnier wrote:
> Why is it exactly that we can come up with things like websockets
> and HTML-5 and SOAP and java annotations, but not with a new
> HTTP/HTML version which would make Unicode/UTF-8 the *default*, and
> everything else into exceptions ?

Because the standards were written without the benefit of hindsight.

Talk to us in 10 years when Websocket looks like a rats-nest of
false-starts, failed standards, and divergent implementations.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJS8RD8AAoJEBzwKT+lPKRYvmMP/iZNbLzx7xIAxUfcKSbbtRvc
9ZGiTJ2oi646lHcWj8DKyr7mEiNiiuptRMswOflsYyK6ZhvTYr0LZhhvoY7IPto0
DejnwnAO+ywMjMk5FuVChrO535QCAZWxlgyRo6aAyl4Kwppaf/7OPl4/MRlu2O4J
7GG+i4pnPQKzBpGy5o8X7l6miMNXjPjUHXrGlZSUyn8wj3zOLqBbgTkSzQQuCkYj
GL/evamN2L4AX6YNdRIXVWQfVWvv76qmznd5cIVntcx0+ryj+kJOcNcEjMah+OwK
6Qh6pfJS1BumWL+EavjhXc9TtM5W5wkemfmN3KxomfzmHqkkFfi9GwKvmCrl5JcB
F/G9rd+N23eamUXioK84bE+3JP33KfELSbjv7AVVFHP/zhkxf/Bl031hqVQ6XsKU
cBQ26tx4ATGpBhaKjrvrbDGEUkVszsH9LiWpPGrSlVRKupPvmrv54kOuTiGhgCZc
xoY3LlmEA8r3DQtyAGqUS045j0+QIo8VWByqSDloAqEvROBWHGJwZ6drTXRpd0yw
/pKtVluR4ECN3nByqvyB866HjgqoVkpl77hEqcK/4k7G9kDdmDAzV3/5r/377/Bf
YrIXC+HN5zSgycSfG+O+HLvNYL1lfJwRdMrjqzZC+jpVewalGgqUkgW/HUVTbWra
E1qpB0AEnfaF9KGuraJv
=I3X1
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT] cookie issue with Tomcat 7 - does not accept the character "é"

Posted by André Warnier <aw...@ice-sa.com>.
Mark Thomas wrote:
> Cookie handling is fundamentally a complete mess. Specifications exist
> but are not fully implemented, are not consistent with related
> specifications, etc.
> 
> Having tried to sort this out the last time around and having read
> Jeremy's great work on documenting where we stand at the present moment,
> it often feels like it wouldn't be too hard to make a case that just
> about any cookie name or value that isn't an token (as per RFC2616) is
> either valid or invalid depending on which specification(s) you choose
> to read.
> 
> I'd strongly encourage anyone thinking about commenting further on this
> thread to take the time to read the wiki page [1] where the Tomcat
> committers (and Jeremy in particular) are currently trying to figure out
> exactly how Tomcat should handle cookies in the future.
> 
> Mark
> 
> 
> [1] http://wiki.apache.org/tomcat/Cookies
> 

Hi agree whith everything you say above.

About the Wiki, what seems to be missing is additional lines in the tables showing some 
examples of cookie values containing what English-speaking people often call "additional" 
or "accented" characters (and what other people just call "characters").  For example, 
what happens when the cookie value is a string like "ÄÖÜäöüéèîôâ" (that's about the extent 
of what I can enter easily on this current German keyboard).

And let's also reflect on the fact that no matter what else we have been discussing here, 
we have still not provided the original OP of this thread with any useful and practical 
recommendation to resolve his problem, which seems to originate in a variation between how 
Tomcat 6 and Tomcat 7 handle cookies with "accented characters" in their value.


Otherwise, to generalise the debate, it is not just cookies, but just about anything which 
has to do with non-US-ASCII characters under HTTP and HTML which is a mess, and has been a 
mess for several years if not decades.  The current jumble of RFCs that deal with this 
issue is in the end more confusing than helpful.  And all the current "solutions" in terms 
of implementation (browser-side as well as server-side) resemble patches over patches over 
wooden legs.

I am not saying that resolving the issue is simple, nor that one can simply ignore the 
past and/or backward-compatibility issues.  But, despite the immense respect I have for 
people like Roy Fielding and their achievements, I cannot but slowly get the impression 
that the Internet RFC mechanism is, in that respect, slowly getting "fossilised", and that 
nobody seems to have the energy and drive anymore to think radically, and tackle the issue 
from the top down.

Nobody nowadays discusses anymore that Unicode and UTF-8 provide a form of "universal" 
solution to most of the issues in terms of alphabets, character sets and encodings 
suitable for 99% of the human users of computers and of the Internet.  And nobody 
discusses anymore that 99% of currently in-use hardware and software can handle arbitrary 
sequences of bytes and bits perfectly fine.

Yet in terms of programming "for the Internet", we still have to live with - and work 
around every day - a set of standards and recommendations based on a myriad of alphabets 
and encodings which can each properly represent only a tiny fraction of the languages that 
people worldwide speak and read.
And the issues related to encoding/decoding/transliterating between these different 
alphabets and encodings, are costing thousands of productive hours lost every day, 
independently of the confusions and aggravations that they generate.

Why is it exactly that we can come up with things like websockets and HTML-5 and SOAP and 
java annotations, but not with a new HTTP/HTML version which would make Unicode/UTF-8 the 
*default*, and everything else into exceptions ?

That for the sake of interoperability and mutual comprehension, things like HTTP header 
*names* would be restricted to sequences of printable characters in a limited range that 
is available on all human interface devices and universally readable is one thing; but why 
would HTTP header *values* or URI path or query-string components (which often have to 
carry real-world multilingual textual information) be similarly limited, and confusing and 
inconsistent ?  Why does it still have to be so difficult, in 2014, to create a web 
user-interface application which insures that people from different countries can enter 
their name and place of residence as they know it, and not have the server-side or 
client-side application mangle them ?

If someone were to take the text of RFC 2616 and replace any direct or indirect mention of 
US-ASCII and ISO-8859-1 in it, by Unicode/UTF-8, and present this as an RFC for HTTP 2.0, 
would the Internet instantly crumble ?
Hoe does one go about doing this ?



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: cookie issue with Tomcat 7 - does not accept the character "é"

Posted by Mark Thomas <ma...@apache.org>.
Cookie handling is fundamentally a complete mess. Specifications exist
but are not fully implemented, are not consistent with related
specifications, etc.

Having tried to sort this out the last time around and having read
Jeremy's great work on documenting where we stand at the present moment,
it often feels like it wouldn't be too hard to make a case that just
about any cookie name or value that isn't an token (as per RFC2616) is
either valid or invalid depending on which specification(s) you choose
to read.

I'd strongly encourage anyone thinking about commenting further on this
thread to take the time to read the wiki page [1] where the Tomcat
committers (and Jeremy in particular) are currently trying to figure out
exactly how Tomcat should handle cookies in the future.

Mark


[1] http://wiki.apache.org/tomcat/Cookies

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: cookie issue with Tomcat 7 - does not accept the character "é"

Posted by André Warnier <aw...@ice-sa.com>.
Konstantin Kolinko wrote:
> 2014-02-04 André Warnier <aw...@ice-sa.com>:
>> Konstantin Kolinko wrote:
>>> 2014-02-03 André Warnier <aw...@ice-sa.com>:
>>>> André Warnier wrote:
>>>>> Chris,
>>>>>
>>>>> a note :
>>>>>
>>>>> Christopher Schultz wrote:
>>>>> ...
>>>>>
>>>>>
>>>>>> Without quoting, unquoted Cookie names and values may be any US-ASCII
>>>>>> character from 0x32 - 0x7e except for any of ("(" | ")" | "<" | ">" |
>>>>>> "@" | "," | ";" | ":" | "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{"
>>>>>> | "}" | SP | HT). None of the characters above are within that range,
>>>>>> so the cookie value must be quoted. (It looks to me like Cookie names
>>>>>> must always be in US-ASCII... I didn't think that was the case but I'm
>>>>>> not motivated to track-down every word of the spec looking for
>>>>>> justification).
>>>>>>
>>>>>> What is the character encoding of the request? What client are you
>>>>>> using? Who created the cookie in the first place?
>>>>>>
>>>>> I did the tracking down of the (tortuous) specs, and come to this :
>>>>>
>>>>> 1) the ISO-8859-1 character set includes "é" (Catalan and other
>>>>> languages)
>>>>> (*)
>>>>>
>>>>> 2) the US-ASCII character set is a subset of ISO-8859-1, and does not
>>>>> include "é".
>>>>>
>>>>> 3) The default character set for HTTP 1.1 is ISO-8859-1, as stated
>>>>> explicitly and implicitly in various places in RFC 2616 [1].
>>>>>
>>>>> However, RFC 2616 does not define the "Cookie" nor "Set-Cookie" headers,
>>>>> and it also does not specifically indicate which character set should be
>>>>> used for HTTP Request/Response header values. It refers for that to MIME
>>>>> (RFC 822), which talks only about US-ASCII.
>>>>>
>>>>> 2) The "Cookie" and "Set-Cookie" headers seem to be subsequently and
>>>>> lastly defined in RFC 6265 [2].
>>>>> In section 4.1.1 [3], the syntax of these headers is defined, as :
>>>>>
>>>>>  cookie-pair       = cookie-name "=" cookie-value
>>>>>  cookie-name       = token
>>>>>  cookie-value      = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
>>>>>  cookie-octet      = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
>>>>>                        ; US-ASCII characters excluding CTLs,
>>>>>                        ; whitespace DQUOTE, comma, semicolon,
>>>>>                        ; and backslash
>>>>>  token             = <token, defined in [RFC2616], Section 2.2>
>>>>>
>>>>> Thus, it seems that you are right, and that a cookie *value* can
>>>>> (regrettably still) only consist of US-ASCII characters (not including
>>>>> "é"
>>>>> thus).
>>>>>
>>>>> (I cannot find in the specs a way to quote a non-US-ASCII character
>>>>> either; that's apparently only allowed in parts defined as "comments")
>>>>>
>>>>> (It is stated somewhere else in RFC 6265 that it is recommended to
>>>>> encode
>>>>> the Cookie value via e.g. Base64, if it were to potentially contain non
>>>>> US-ASCII characters).
>>>>>
>>>>> The cookie name is a "token", and the definition of "token" sends us
>>>>> back
>>>>> to RFC2616.
>>>>> In "2.2 Basic Rules", RFC2616 states :
>>>>>
>>>>>    token          = 1*<any CHAR except CTLs or separators>
>>>>>        separators     = "(" | ")" | "<" | ">" | "@"
>>>>>                       | "," | ";" | ":" | "\" | <">
>>>>>                       | "/" | "[" | "]" | "?" | "="
>>>>>                       | "{" | "}" | SP | HT
>>>>> ...
>>>>>       CHAR           = <any US-ASCII character (octets 0 - 127)>
>>>>>       CTL            = <any US-ASCII control character
>>>>>                         (octets 0 - 31) and DEL (127)>
>>>>>
>>>>> So, this all would tend to show that you are right, and that Cookie
>>>>> names
>>>>> (as well as values) can only consist of US-ASCII characters, and that
>>>>> "é" is
>>>>> thus not allowed (without some form of encoding that would represent it
>>>>> as a
>>>>> sequence of US-ASCII characters).
>>>>>
>>>>> Which, in my personal opinion is a lasting p-i-t-a and shame.  And I
>>>>> cannot imagine how it can be nowadays that nobody has yet gotten around
>>>>> to
>>>>> proposing a HTTP 2.0 RFC where the default character set would be
>>>>> Unicode,
>>>>> UTF-8 encoded, for everything excluding maybe header names.  But that's
>>>>> neither here nor there.
>>>>>
>>>>> To get back to the original OP's question thus, it seems to me that
>>>>> - Tomcat 7.x would not be in violation of the specs, if it indeed
>>>>> rejects
>>>>> a Cookie header containing any non-US-ASCII character (whether in the
>>>>> cookie
>>>>> name or value).
>>>>> - That the error message could be improved ("é" is not a control
>>>>> character, it's just invalid here)
>>>>> - but that the real fix for the OP may be to Base64-encode the cookie
>>>>> value before sending it to the browser.
>>>>> That's also because it may happen one day that even a browser which
>>>>> respects the specs to the letter (one never knows), could reject a value
>>>>> like : "abcé","abc","abc","abc","abc","abc","abc","abc","abc";
>>>>>
>>>>>
>>>>> [1] http://tools.ietf.org/search/rfc2616
>>>>> [2] http://tools.ietf.org/search/rfc6265
>>>>> [3] http://tools.ietf.org/search/rfc6265#section-4.1.1
>>>>>
>>>>>
>>>> As an appendix, and triggered by another post to this list, here is
>>>> another
>>>> way of encoding HTTP header values :
>>>>
>>>> Cookie: ACE_COOKIE=R660302447; TD3World=R760446058
>>>> SM_TRANSACTIONID:
>>>> =?UTF-8?B?MGE2NDA2MDEtNDAzMy01MjdjYzlkMy0wMDBhLTJjMWI0NjJi?=
>>>> SM_AUTHTYPE: =?UTF-8?B?QXV0bw==?=
>>>> SM_SDOMAIN: =?UTF-8?B?LnRveW90YS1ldXJvcGUuY29t?=
>>>>
>>>> In this case, the cookie values are encoded using a "MIME extension"
>>>> scheme
>>>> which indicates (between =? ? ?) prior to a string's value, the character
>>>> set/encoding in which the subsequent string is to be interpreted.
>>>> This is not explicitly mentioned in any of the above references, but as I
>>>> recall, this is part of another series of RFC's, maybe starting at this
>>>> one
>>>> :
>>>> http://tools.ietf.org/html/rfc2184
>>>> Now how this works out (also browser-side) with Cookie headers composed
>>>> of
>>>> cookie names and values, I couldn't say.
>>>>
>>> RFC 2616
>>> also says the following on page 16:
>>>
>>>    The TEXT rule is only used for descriptive field contents and values
>>>    that are not intended to be interpreted by the message parser. Words
>>>    of *TEXT MAY contain characters from character sets other than ISO-
>>>    8859-1 [22] only when encoded according to the rules of RFC 2047
>>>    [14].
>>>
>>>        TEXT           = <any OCTET except CTLs,
>>>                         but including LWS>
>>>
>>> RFC 2047 is also referenced in Javadoc for HttpServletResponse.setHeader()
>>>
>>> The "B" encoding used in an example above is one of encodings allowed
>>> by RFC2047 ch.4.1.
>>>
>>> http://www.ietf.org/rfc/rfc2047.txt
>>>
>> Yes, but it never says anywhere that a "cookie value" may contain "*TEXT".
>> Explicitly, it only mentions "*cookie-octet".
>>
> 
> I meant the following part (page 32 of RFC 2616) which defines what
> syntax of HTTP headers is, in general.
> 
>        message-header = field-name ":" [ field-value ]
>        field-name     = token
>        field-value    = *( field-content | LWS )
>        field-content  = <the OCTETs making up the field-value
>                         and consisting of either *TEXT or combinations
>                         of token, separators, and quoted-string>
> 
> TEXT is as I quoted above.
> tokens are US-ASCII minus some characters
> quotes-string is TEXT inside of double quotes.
> 
> Thus there are limits on headers syntax in general,
> including "Cookie" and "Set-Cookie" headers.
> 
>> And, what does it all mean browser-side, particularly for Cookies ?
>>
> 
> Browsers have to be compliant. Are they?

Supposedly.  But in the practice, are they ?
If I send from the server a cookie via a Response header like :

Set-Cookie: =?iso-8859-1?B?mycookie=äöüéè

do IE 7+, Firefox, Chrome browsers interpret this correctly, and understand this as a 
cookie named "mycookie" with a value of "äöüéè" ?
If one of them doesn't, then this is not a practical answer to the OP's problem.

(He can complain to the developers of the non-compliant browser, but how much of a chance 
does he have to get it fixed soon enough for his problem ?)

> 
>> Most browsers for example have a "show cookies" function, where they will
>> display the cookie name, value, and other attributes separately.
> 
> That is display of their internal database. It has nothing to do with
> what is allowed on the wire.
> 

Agreed, but my point here was to illustrate the "does the browser understand it" question.

To be practical :

In the OP's original question, the server application would like to set a cookie named 
'GetUser_Properties' with a value '"abc","abcé","abc","abc","abc","abc","abc","abc","abc"'

Clearly (I think) according to the specs, this is not valid :

Set-Cookie: GetUser_Properties="abc","abcé","abc","abc","abc","abc","abc","abc","abc"

As I understand from the specs, this might be valid (one line):

Set-Cookie: 
=?iso-8859-1?Q?GetUser_Properties="abc","abcé","abc","abc","abc","abc","abc","abc","abc"

But, does an average browser understand it ?
And if Tomcat 6 / 7 receive a cookie header like (1 line) :

Cookie: 
=?iso-8859-1?Q?GetUser_Properties="abc","abcé","abc","abc","abc","abc","abc","abc","abc"

do they understand it ?

Or, would you have any other recommendation of how the server should set this cookie ?

What I would do (assuming that the browser-side itself doesn't need to use the value of 
the cookie, just re-send it to the server unchanged)
is :

Set-Cookie: GetUser_Properties=BBBB..BB

where "BBBB..BB" is the Base64-encoded value of the iso-8859-1 string 
'"abc","abcé","abc","abc","abc","abc","abc","abc","abc"'

and the server-side application, when receiving the corresponding cookie, should 
Base64-decode the cookie value before parsing it.

And I am quite sure that
1) it matches all the specs
2) any browser and any server would support this.
3) it is not "native" to any webserver to Base64-encode/decode cookie values, but it is 
fairly easy to implement




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: cookie issue with Tomcat 7 - does not accept the character "é"

Posted by Konstantin Kolinko <kn...@gmail.com>.
2014-02-04 André Warnier <aw...@ice-sa.com>:
> Konstantin Kolinko wrote:
>>
>> 2014-02-03 André Warnier <aw...@ice-sa.com>:
>>>
>>> André Warnier wrote:
>>>>
>>>> Chris,
>>>>
>>>> a note :
>>>>
>>>> Christopher Schultz wrote:
>>>> ...
>>>>
>>>>
>>>>> Without quoting, unquoted Cookie names and values may be any US-ASCII
>>>>> character from 0x32 - 0x7e except for any of ("(" | ")" | "<" | ">" |
>>>>> "@" | "," | ";" | ":" | "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{"
>>>>> | "}" | SP | HT). None of the characters above are within that range,
>>>>> so the cookie value must be quoted. (It looks to me like Cookie names
>>>>> must always be in US-ASCII... I didn't think that was the case but I'm
>>>>> not motivated to track-down every word of the spec looking for
>>>>> justification).
>>>>>
>>>>> What is the character encoding of the request? What client are you
>>>>> using? Who created the cookie in the first place?
>>>>>
>>>> I did the tracking down of the (tortuous) specs, and come to this :
>>>>
>>>> 1) the ISO-8859-1 character set includes "é" (Catalan and other
>>>> languages)
>>>> (*)
>>>>
>>>> 2) the US-ASCII character set is a subset of ISO-8859-1, and does not
>>>> include "é".
>>>>
>>>> 3) The default character set for HTTP 1.1 is ISO-8859-1, as stated
>>>> explicitly and implicitly in various places in RFC 2616 [1].
>>>>
>>>> However, RFC 2616 does not define the "Cookie" nor "Set-Cookie" headers,
>>>> and it also does not specifically indicate which character set should be
>>>> used for HTTP Request/Response header values. It refers for that to MIME
>>>> (RFC 822), which talks only about US-ASCII.
>>>>
>>>> 2) The "Cookie" and "Set-Cookie" headers seem to be subsequently and
>>>> lastly defined in RFC 6265 [2].
>>>> In section 4.1.1 [3], the syntax of these headers is defined, as :
>>>>
>>>>  cookie-pair       = cookie-name "=" cookie-value
>>>>  cookie-name       = token
>>>>  cookie-value      = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
>>>>  cookie-octet      = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
>>>>                        ; US-ASCII characters excluding CTLs,
>>>>                        ; whitespace DQUOTE, comma, semicolon,
>>>>                        ; and backslash
>>>>  token             = <token, defined in [RFC2616], Section 2.2>
>>>>
>>>> Thus, it seems that you are right, and that a cookie *value* can
>>>> (regrettably still) only consist of US-ASCII characters (not including
>>>> "é"
>>>> thus).
>>>>
>>>> (I cannot find in the specs a way to quote a non-US-ASCII character
>>>> either; that's apparently only allowed in parts defined as "comments")
>>>>
>>>> (It is stated somewhere else in RFC 6265 that it is recommended to
>>>> encode
>>>> the Cookie value via e.g. Base64, if it were to potentially contain non
>>>> US-ASCII characters).
>>>>
>>>> The cookie name is a "token", and the definition of "token" sends us
>>>> back
>>>> to RFC2616.
>>>> In "2.2 Basic Rules", RFC2616 states :
>>>>
>>>>    token          = 1*<any CHAR except CTLs or separators>
>>>>        separators     = "(" | ")" | "<" | ">" | "@"
>>>>                       | "," | ";" | ":" | "\" | <">
>>>>                       | "/" | "[" | "]" | "?" | "="
>>>>                       | "{" | "}" | SP | HT
>>>> ...
>>>>       CHAR           = <any US-ASCII character (octets 0 - 127)>
>>>>       CTL            = <any US-ASCII control character
>>>>                         (octets 0 - 31) and DEL (127)>
>>>>
>>>> So, this all would tend to show that you are right, and that Cookie
>>>> names
>>>> (as well as values) can only consist of US-ASCII characters, and that
>>>> "é" is
>>>> thus not allowed (without some form of encoding that would represent it
>>>> as a
>>>> sequence of US-ASCII characters).
>>>>
>>>> Which, in my personal opinion is a lasting p-i-t-a and shame.  And I
>>>> cannot imagine how it can be nowadays that nobody has yet gotten around
>>>> to
>>>> proposing a HTTP 2.0 RFC where the default character set would be
>>>> Unicode,
>>>> UTF-8 encoded, for everything excluding maybe header names.  But that's
>>>> neither here nor there.
>>>>
>>>> To get back to the original OP's question thus, it seems to me that
>>>> - Tomcat 7.x would not be in violation of the specs, if it indeed
>>>> rejects
>>>> a Cookie header containing any non-US-ASCII character (whether in the
>>>> cookie
>>>> name or value).
>>>> - That the error message could be improved ("é" is not a control
>>>> character, it's just invalid here)
>>>> - but that the real fix for the OP may be to Base64-encode the cookie
>>>> value before sending it to the browser.
>>>> That's also because it may happen one day that even a browser which
>>>> respects the specs to the letter (one never knows), could reject a value
>>>> like : "abcé","abc","abc","abc","abc","abc","abc","abc","abc";
>>>>
>>>>
>>>> [1] http://tools.ietf.org/search/rfc2616
>>>> [2] http://tools.ietf.org/search/rfc6265
>>>> [3] http://tools.ietf.org/search/rfc6265#section-4.1.1
>>>>
>>>>
>>> As an appendix, and triggered by another post to this list, here is
>>> another
>>> way of encoding HTTP header values :
>>>
>>> Cookie: ACE_COOKIE=R660302447; TD3World=R760446058
>>> SM_TRANSACTIONID:
>>> =?UTF-8?B?MGE2NDA2MDEtNDAzMy01MjdjYzlkMy0wMDBhLTJjMWI0NjJi?=
>>> SM_AUTHTYPE: =?UTF-8?B?QXV0bw==?=
>>> SM_SDOMAIN: =?UTF-8?B?LnRveW90YS1ldXJvcGUuY29t?=
>>>
>>> In this case, the cookie values are encoded using a "MIME extension"
>>> scheme
>>> which indicates (between =? ? ?) prior to a string's value, the character
>>> set/encoding in which the subsequent string is to be interpreted.
>>> This is not explicitly mentioned in any of the above references, but as I
>>> recall, this is part of another series of RFC's, maybe starting at this
>>> one
>>> :
>>> http://tools.ietf.org/html/rfc2184
>>> Now how this works out (also browser-side) with Cookie headers composed
>>> of
>>> cookie names and values, I couldn't say.
>>>
>>
>> RFC 2616
>> also says the following on page 16:
>>
>>    The TEXT rule is only used for descriptive field contents and values
>>    that are not intended to be interpreted by the message parser. Words
>>    of *TEXT MAY contain characters from character sets other than ISO-
>>    8859-1 [22] only when encoded according to the rules of RFC 2047
>>    [14].
>>
>>        TEXT           = <any OCTET except CTLs,
>>                         but including LWS>
>>
>> RFC 2047 is also referenced in Javadoc for HttpServletResponse.setHeader()
>>
>> The "B" encoding used in an example above is one of encodings allowed
>> by RFC2047 ch.4.1.
>>
>> http://www.ietf.org/rfc/rfc2047.txt
>>
>
> Yes, but it never says anywhere that a "cookie value" may contain "*TEXT".
> Explicitly, it only mentions "*cookie-octet".
>

I meant the following part (page 32 of RFC 2616) which defines what
syntax of HTTP headers is, in general.

       message-header = field-name ":" [ field-value ]
       field-name     = token
       field-value    = *( field-content | LWS )
       field-content  = <the OCTETs making up the field-value
                        and consisting of either *TEXT or combinations
                        of token, separators, and quoted-string>

TEXT is as I quoted above.
tokens are US-ASCII minus some characters
quotes-string is TEXT inside of double quotes.

Thus there are limits on headers syntax in general,
including "Cookie" and "Set-Cookie" headers.

> And, what does it all mean browser-side, particularly for Cookies ?
>

Browsers have to be compliant. Are they?

> Most browsers for example have a "show cookies" function, where they will
> display the cookie name, value, and other attributes separately.

That is display of their internal database. It has nothing to do with
what is allowed on the wire.

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: cookie issue with Tomcat 7 - does not accept the character "é"

Posted by André Warnier <aw...@ice-sa.com>.
Konstantin Kolinko wrote:
> 2014-02-03 André Warnier <aw...@ice-sa.com>:
>> André Warnier wrote:
>>> Chris,
>>>
>>> a note :
>>>
>>> Christopher Schultz wrote:
>>> ...
>>>
>>>
>>>> Without quoting, unquoted Cookie names and values may be any US-ASCII
>>>> character from 0x32 - 0x7e except for any of ("(" | ")" | "<" | ">" |
>>>> "@" | "," | ";" | ":" | "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{"
>>>> | "}" | SP | HT). None of the characters above are within that range,
>>>> so the cookie value must be quoted. (It looks to me like Cookie names
>>>> must always be in US-ASCII... I didn't think that was the case but I'm
>>>> not motivated to track-down every word of the spec looking for
>>>> justification).
>>>>
>>>> What is the character encoding of the request? What client are you
>>>> using? Who created the cookie in the first place?
>>>>
>>> I did the tracking down of the (tortuous) specs, and come to this :
>>>
>>> 1) the ISO-8859-1 character set includes "é" (Catalan and other languages)
>>> (*)
>>>
>>> 2) the US-ASCII character set is a subset of ISO-8859-1, and does not
>>> include "é".
>>>
>>> 3) The default character set for HTTP 1.1 is ISO-8859-1, as stated
>>> explicitly and implicitly in various places in RFC 2616 [1].
>>>
>>> However, RFC 2616 does not define the "Cookie" nor "Set-Cookie" headers,
>>> and it also does not specifically indicate which character set should be
>>> used for HTTP Request/Response header values. It refers for that to MIME
>>> (RFC 822), which talks only about US-ASCII.
>>>
>>> 2) The "Cookie" and "Set-Cookie" headers seem to be subsequently and
>>> lastly defined in RFC 6265 [2].
>>> In section 4.1.1 [3], the syntax of these headers is defined, as :
>>>
>>>  cookie-pair       = cookie-name "=" cookie-value
>>>  cookie-name       = token
>>>  cookie-value      = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
>>>  cookie-octet      = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
>>>                        ; US-ASCII characters excluding CTLs,
>>>                        ; whitespace DQUOTE, comma, semicolon,
>>>                        ; and backslash
>>>  token             = <token, defined in [RFC2616], Section 2.2>
>>>
>>> Thus, it seems that you are right, and that a cookie *value* can
>>> (regrettably still) only consist of US-ASCII characters (not including "é"
>>> thus).
>>>
>>> (I cannot find in the specs a way to quote a non-US-ASCII character
>>> either; that's apparently only allowed in parts defined as "comments")
>>>
>>> (It is stated somewhere else in RFC 6265 that it is recommended to encode
>>> the Cookie value via e.g. Base64, if it were to potentially contain non
>>> US-ASCII characters).
>>>
>>> The cookie name is a "token", and the definition of "token" sends us back
>>> to RFC2616.
>>> In "2.2 Basic Rules", RFC2616 states :
>>>
>>>    token          = 1*<any CHAR except CTLs or separators>
>>>        separators     = "(" | ")" | "<" | ">" | "@"
>>>                       | "," | ";" | ":" | "\" | <">
>>>                       | "/" | "[" | "]" | "?" | "="
>>>                       | "{" | "}" | SP | HT
>>> ...
>>>       CHAR           = <any US-ASCII character (octets 0 - 127)>
>>>       CTL            = <any US-ASCII control character
>>>                         (octets 0 - 31) and DEL (127)>
>>>
>>> So, this all would tend to show that you are right, and that Cookie names
>>> (as well as values) can only consist of US-ASCII characters, and that "é" is
>>> thus not allowed (without some form of encoding that would represent it as a
>>> sequence of US-ASCII characters).
>>>
>>> Which, in my personal opinion is a lasting p-i-t-a and shame.  And I
>>> cannot imagine how it can be nowadays that nobody has yet gotten around to
>>> proposing a HTTP 2.0 RFC where the default character set would be Unicode,
>>> UTF-8 encoded, for everything excluding maybe header names.  But that's
>>> neither here nor there.
>>>
>>> To get back to the original OP's question thus, it seems to me that
>>> - Tomcat 7.x would not be in violation of the specs, if it indeed rejects
>>> a Cookie header containing any non-US-ASCII character (whether in the cookie
>>> name or value).
>>> - That the error message could be improved ("é" is not a control
>>> character, it's just invalid here)
>>> - but that the real fix for the OP may be to Base64-encode the cookie
>>> value before sending it to the browser.
>>> That's also because it may happen one day that even a browser which
>>> respects the specs to the letter (one never knows), could reject a value
>>> like : "abcé","abc","abc","abc","abc","abc","abc","abc","abc";
>>>
>>>
>>> [1] http://tools.ietf.org/search/rfc2616
>>> [2] http://tools.ietf.org/search/rfc6265
>>> [3] http://tools.ietf.org/search/rfc6265#section-4.1.1
>>>
>>>
>> As an appendix, and triggered by another post to this list, here is another
>> way of encoding HTTP header values :
>>
>> Cookie: ACE_COOKIE=R660302447; TD3World=R760446058
>> SM_TRANSACTIONID:
>> =?UTF-8?B?MGE2NDA2MDEtNDAzMy01MjdjYzlkMy0wMDBhLTJjMWI0NjJi?=
>> SM_AUTHTYPE: =?UTF-8?B?QXV0bw==?=
>> SM_SDOMAIN: =?UTF-8?B?LnRveW90YS1ldXJvcGUuY29t?=
>>
>> In this case, the cookie values are encoded using a "MIME extension" scheme
>> which indicates (between =? ? ?) prior to a string's value, the character
>> set/encoding in which the subsequent string is to be interpreted.
>> This is not explicitly mentioned in any of the above references, but as I
>> recall, this is part of another series of RFC's, maybe starting at this one
>> :
>> http://tools.ietf.org/html/rfc2184
>> Now how this works out (also browser-side) with Cookie headers composed of
>> cookie names and values, I couldn't say.
>>
> 
> RFC 2616
> also says the following on page 16:
> 
>    The TEXT rule is only used for descriptive field contents and values
>    that are not intended to be interpreted by the message parser. Words
>    of *TEXT MAY contain characters from character sets other than ISO-
>    8859-1 [22] only when encoded according to the rules of RFC 2047
>    [14].
> 
>        TEXT           = <any OCTET except CTLs,
>                         but including LWS>
> 
> RFC 2047 is also referenced in Javadoc for HttpServletResponse.setHeader()
> 
> The "B" encoding used in an example above is one of encodings allowed
> by RFC2047 ch.4.1.
> 
> http://www.ietf.org/rfc/rfc2047.txt
> 

Yes, but it never says anywhere that a "cookie value" may contain "*TEXT". Explicitly, it 
only mentions "*cookie-octet".

And, what does it all mean browser-side, particularly for Cookies ?

Most browsers for example have a "show cookies" function, where they will display the 
cookie name, value, and other attributes separately.

The above encoding scheme is meant to encode the whole "HTTP header value" part.
For example, if the server sends a response header like :

Set-Cookie: =?UTF-8?B?(something)

and the encoded part of that header would be a "cookie-name=cookie-value" string,
would the average browser decode that string properly in a cookie-name, cookie-value, etc. ?

And how would that same browser send back this cookie later, in a "Cookie:" HTTP request 
header to the server ?
Similarly-encoded ?

Similarly, the Tomcat Wiki article to which Mark pointed us earlier, talks about many 
aspects of cookies, but not very much in detail about the precise subject of the original 
OP's post, which was the characters that could be used in a Cookie value, respectively for 
Tomcat 6 and Tomcat 7. (And according to the OP, there is a difference in that respect 
between Tomcat 6.x and Tomcat 7.x; I haven't checked).

In general, in the case of HTTP and character sets, there is such a spaghetti-bowl of 
mutually-referencing RFC's, that it is really not easy to know what one "SHOULD" or 
"SHOULD NOT" do in the end.
And if interpret the Wiki article correctly, then it seems that now there is also a HTML-5 
recommendation to add to the mix.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: cookie issue with Tomcat 7 - does not accept the character "é"

Posted by Konstantin Kolinko <kn...@gmail.com>.
2014-02-03 André Warnier <aw...@ice-sa.com>:
> André Warnier wrote:
>>
>> Chris,
>>
>> a note :
>>
>> Christopher Schultz wrote:
>> ...
>>
>>
>>>
>>> Without quoting, unquoted Cookie names and values may be any US-ASCII
>>> character from 0x32 - 0x7e except for any of ("(" | ")" | "<" | ">" |
>>> "@" | "," | ";" | ":" | "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{"
>>> | "}" | SP | HT). None of the characters above are within that range,
>>> so the cookie value must be quoted. (It looks to me like Cookie names
>>> must always be in US-ASCII... I didn't think that was the case but I'm
>>> not motivated to track-down every word of the spec looking for
>>> justification).
>>>
>>> What is the character encoding of the request? What client are you
>>> using? Who created the cookie in the first place?
>>>
>>
>> I did the tracking down of the (tortuous) specs, and come to this :
>>
>> 1) the ISO-8859-1 character set includes "é" (Catalan and other languages)
>> (*)
>>
>> 2) the US-ASCII character set is a subset of ISO-8859-1, and does not
>> include "é".
>>
>> 3) The default character set for HTTP 1.1 is ISO-8859-1, as stated
>> explicitly and implicitly in various places in RFC 2616 [1].
>>
>> However, RFC 2616 does not define the "Cookie" nor "Set-Cookie" headers,
>> and it also does not specifically indicate which character set should be
>> used for HTTP Request/Response header values. It refers for that to MIME
>> (RFC 822), which talks only about US-ASCII.
>>
>> 2) The "Cookie" and "Set-Cookie" headers seem to be subsequently and
>> lastly defined in RFC 6265 [2].
>> In section 4.1.1 [3], the syntax of these headers is defined, as :
>>
>>  cookie-pair       = cookie-name "=" cookie-value
>>  cookie-name       = token
>>  cookie-value      = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
>>  cookie-octet      = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
>>                        ; US-ASCII characters excluding CTLs,
>>                        ; whitespace DQUOTE, comma, semicolon,
>>                        ; and backslash
>>  token             = <token, defined in [RFC2616], Section 2.2>
>>
>> Thus, it seems that you are right, and that a cookie *value* can
>> (regrettably still) only consist of US-ASCII characters (not including "é"
>> thus).
>>
>> (I cannot find in the specs a way to quote a non-US-ASCII character
>> either; that's apparently only allowed in parts defined as "comments")
>>
>> (It is stated somewhere else in RFC 6265 that it is recommended to encode
>> the Cookie value via e.g. Base64, if it were to potentially contain non
>> US-ASCII characters).
>>
>> The cookie name is a "token", and the definition of "token" sends us back
>> to RFC2616.
>> In "2.2 Basic Rules", RFC2616 states :
>>
>>    token          = 1*<any CHAR except CTLs or separators>
>>        separators     = "(" | ")" | "<" | ">" | "@"
>>                       | "," | ";" | ":" | "\" | <">
>>                       | "/" | "[" | "]" | "?" | "="
>>                       | "{" | "}" | SP | HT
>> ...
>>       CHAR           = <any US-ASCII character (octets 0 - 127)>
>>       CTL            = <any US-ASCII control character
>>                         (octets 0 - 31) and DEL (127)>
>>
>> So, this all would tend to show that you are right, and that Cookie names
>> (as well as values) can only consist of US-ASCII characters, and that "é" is
>> thus not allowed (without some form of encoding that would represent it as a
>> sequence of US-ASCII characters).
>>
>> Which, in my personal opinion is a lasting p-i-t-a and shame.  And I
>> cannot imagine how it can be nowadays that nobody has yet gotten around to
>> proposing a HTTP 2.0 RFC where the default character set would be Unicode,
>> UTF-8 encoded, for everything excluding maybe header names.  But that's
>> neither here nor there.
>>
>> To get back to the original OP's question thus, it seems to me that
>> - Tomcat 7.x would not be in violation of the specs, if it indeed rejects
>> a Cookie header containing any non-US-ASCII character (whether in the cookie
>> name or value).
>> - That the error message could be improved ("é" is not a control
>> character, it's just invalid here)
>> - but that the real fix for the OP may be to Base64-encode the cookie
>> value before sending it to the browser.
>> That's also because it may happen one day that even a browser which
>> respects the specs to the letter (one never knows), could reject a value
>> like : "abcé","abc","abc","abc","abc","abc","abc","abc","abc";
>>
>>
>> [1] http://tools.ietf.org/search/rfc2616
>> [2] http://tools.ietf.org/search/rfc6265
>> [3] http://tools.ietf.org/search/rfc6265#section-4.1.1
>>
>>
>
> As an appendix, and triggered by another post to this list, here is another
> way of encoding HTTP header values :
>
> Cookie: ACE_COOKIE=R660302447; TD3World=R760446058
> SM_TRANSACTIONID:
> =?UTF-8?B?MGE2NDA2MDEtNDAzMy01MjdjYzlkMy0wMDBhLTJjMWI0NjJi?=
> SM_AUTHTYPE: =?UTF-8?B?QXV0bw==?=
> SM_SDOMAIN: =?UTF-8?B?LnRveW90YS1ldXJvcGUuY29t?=
>
> In this case, the cookie values are encoded using a "MIME extension" scheme
> which indicates (between =? ? ?) prior to a string's value, the character
> set/encoding in which the subsequent string is to be interpreted.
> This is not explicitly mentioned in any of the above references, but as I
> recall, this is part of another series of RFC's, maybe starting at this one
> :
> http://tools.ietf.org/html/rfc2184
> Now how this works out (also browser-side) with Cookie headers composed of
> cookie names and values, I couldn't say.
>

RFC 2616
also says the following on page 16:

   The TEXT rule is only used for descriptive field contents and values
   that are not intended to be interpreted by the message parser. Words
   of *TEXT MAY contain characters from character sets other than ISO-
   8859-1 [22] only when encoded according to the rules of RFC 2047
   [14].

       TEXT           = <any OCTET except CTLs,
                        but including LWS>

RFC 2047 is also referenced in Javadoc for HttpServletResponse.setHeader()

The "B" encoding used in an example above is one of encodings allowed
by RFC2047 ch.4.1.

http://www.ietf.org/rfc/rfc2047.txt

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: cookie issue with Tomcat 7 - does not accept the character "é"

Posted by Mark Thomas <ma...@apache.org>.
On 03/02/2014 12:19, André Warnier wrote:
> André Warnier wrote:
>> Christopher Schultz wrote:

>>> Without quoting, unquoted Cookie names and values may be any US-ASCII
>>> character from 0x32 - 0x7e except for any of ("(" | ")" | "<" | ">" |
>>> "@" | "," | ";" | ":" | "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{"
>>> | "}" | SP | HT). None of the characters above are within that range,
>>> so the cookie value must be quoted. (It looks to me like Cookie names
>>> must always be in US-ASCII... I didn't think that was the case but I'm
>>> not motivated to track-down every word of the spec looking for
>>> justification).

Read https://wiki.apache.org/tomcat/Cookies
Look for the references to UTF-8. It isn't currently supported but it
will be.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: cookie issue with Tomcat 7 - does not accept the character "é"

Posted by André Warnier <aw...@ice-sa.com>.
André Warnier wrote:
> Chris,
> 
> a note :
> 
> Christopher Schultz wrote:
> ...
> 
> 
>>
>> Without quoting, unquoted Cookie names and values may be any US-ASCII
>> character from 0x32 - 0x7e except for any of ("(" | ")" | "<" | ">" |
>> "@" | "," | ";" | ":" | "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{"
>> | "}" | SP | HT). None of the characters above are within that range,
>> so the cookie value must be quoted. (It looks to me like Cookie names
>> must always be in US-ASCII... I didn't think that was the case but I'm
>> not motivated to track-down every word of the spec looking for
>> justification).
>>
>> What is the character encoding of the request? What client are you
>> using? Who created the cookie in the first place?
>>
> 
> I did the tracking down of the (tortuous) specs, and come to this :
> 
> 1) the ISO-8859-1 character set includes "é" (Catalan and other 
> languages) (*)
> 
> 2) the US-ASCII character set is a subset of ISO-8859-1, and does not 
> include "é".
> 
> 3) The default character set for HTTP 1.1 is ISO-8859-1, as stated 
> explicitly and implicitly in various places in RFC 2616 [1].
> 
> However, RFC 2616 does not define the "Cookie" nor "Set-Cookie" headers, 
> and it also does not specifically indicate which character set should be 
> used for HTTP Request/Response header values. It refers for that to MIME 
> (RFC 822), which talks only about US-ASCII.
> 
> 2) The "Cookie" and "Set-Cookie" headers seem to be subsequently and 
> lastly defined in RFC 6265 [2].
> In section 4.1.1 [3], the syntax of these headers is defined, as :
> 
>  cookie-pair       = cookie-name "=" cookie-value
>  cookie-name       = token
>  cookie-value      = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
>  cookie-octet      = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
>                        ; US-ASCII characters excluding CTLs,
>                        ; whitespace DQUOTE, comma, semicolon,
>                        ; and backslash
>  token             = <token, defined in [RFC2616], Section 2.2>
> 
> Thus, it seems that you are right, and that a cookie *value* can 
> (regrettably still) only consist of US-ASCII characters (not including 
> "é" thus).
> 
> (I cannot find in the specs a way to quote a non-US-ASCII character 
> either; that's apparently only allowed in parts defined as "comments")
> 
> (It is stated somewhere else in RFC 6265 that it is recommended to 
> encode the Cookie value via e.g. Base64, if it were to potentially 
> contain non US-ASCII characters).
> 
> The cookie name is a "token", and the definition of "token" sends us 
> back to RFC2616.
> In "2.2 Basic Rules", RFC2616 states :
> 
>    token          = 1*<any CHAR except CTLs or separators>
>        separators     = "(" | ")" | "<" | ">" | "@"
>                       | "," | ";" | ":" | "\" | <">
>                       | "/" | "[" | "]" | "?" | "="
>                       | "{" | "}" | SP | HT
> ...
>       CHAR           = <any US-ASCII character (octets 0 - 127)>
>       CTL            = <any US-ASCII control character
>                         (octets 0 - 31) and DEL (127)>
> 
> So, this all would tend to show that you are right, and that Cookie 
> names (as well as values) can only consist of US-ASCII characters, and 
> that "é" is thus not allowed (without some form of encoding that would 
> represent it as a sequence of US-ASCII characters).
> 
> Which, in my personal opinion is a lasting p-i-t-a and shame.  And I 
> cannot imagine how it can be nowadays that nobody has yet gotten around 
> to proposing a HTTP 2.0 RFC where the default character set would be 
> Unicode, UTF-8 encoded, for everything excluding maybe header names.  
> But that's neither here nor there.
> 
> To get back to the original OP's question thus, it seems to me that
> - Tomcat 7.x would not be in violation of the specs, if it indeed 
> rejects a Cookie header containing any non-US-ASCII character (whether 
> in the cookie name or value).
> - That the error message could be improved ("é" is not a control 
> character, it's just invalid here)
> - but that the real fix for the OP may be to Base64-encode the cookie 
> value before sending it to the browser.
> That's also because it may happen one day that even a browser which 
> respects the specs to the letter (one never knows), could reject a value 
> like : "abcé","abc","abc","abc","abc","abc","abc","abc","abc";
> 
> 
> [1] http://tools.ietf.org/search/rfc2616
> [2] http://tools.ietf.org/search/rfc6265
> [3] http://tools.ietf.org/search/rfc6265#section-4.1.1
> 
> 

As an appendix, and triggered by another post to this list, here is another way of 
encoding HTTP header values :

Cookie: ACE_COOKIE=R660302447; TD3World=R760446058
SM_TRANSACTIONID:
=?UTF-8?B?MGE2NDA2MDEtNDAzMy01MjdjYzlkMy0wMDBhLTJjMWI0NjJi?=
SM_AUTHTYPE: =?UTF-8?B?QXV0bw==?=
SM_SDOMAIN: =?UTF-8?B?LnRveW90YS1ldXJvcGUuY29t?=

In this case, the cookie values are encoded using a "MIME extension" scheme which 
indicates (between =? ? ?) prior to a string's value, the character set/encoding in which 
the subsequent string is to be interpreted.
This is not explicitly mentioned in any of the above references, but as I recall, this is 
part of another series of RFC's, maybe starting at this one :
http://tools.ietf.org/html/rfc2184
Now how this works out (also browser-side) with Cookie headers composed of cookie names 
and values, I couldn't say.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: cookie issue with Tomcat 7 - does not accept the character "é"

Posted by André Warnier <aw...@ice-sa.com>.
Chris,

a note :

Christopher Schultz wrote:
...


> 
> Without quoting, unquoted Cookie names and values may be any US-ASCII
> character from 0x32 - 0x7e except for any of ("(" | ")" | "<" | ">" |
> "@" | "," | ";" | ":" | "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{"
> | "}" | SP | HT). None of the characters above are within that range,
> so the cookie value must be quoted. (It looks to me like Cookie names
> must always be in US-ASCII... I didn't think that was the case but I'm
> not motivated to track-down every word of the spec looking for
> justification).
> 
> What is the character encoding of the request? What client are you
> using? Who created the cookie in the first place?
> 

I did the tracking down of the (tortuous) specs, and come to this :

1) the ISO-8859-1 character set includes "é" (Catalan and other languages) (*)

2) the US-ASCII character set is a subset of ISO-8859-1, and does not include "é".

3) The default character set for HTTP 1.1 is ISO-8859-1, as stated explicitly and 
implicitly in various places in RFC 2616 [1].

However, RFC 2616 does not define the "Cookie" nor "Set-Cookie" headers, and it also does 
not specifically indicate which character set should be used for HTTP Request/Response 
header values. It refers for that to MIME (RFC 822), which talks only about US-ASCII.

2) The "Cookie" and "Set-Cookie" headers seem to be subsequently and lastly defined in RFC 
6265 [2].
In section 4.1.1 [3], the syntax of these headers is defined, as :

  cookie-pair       = cookie-name "=" cookie-value
  cookie-name       = token
  cookie-value      = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
  cookie-octet      = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
                        ; US-ASCII characters excluding CTLs,
                        ; whitespace DQUOTE, comma, semicolon,
                        ; and backslash
  token             = <token, defined in [RFC2616], Section 2.2>

Thus, it seems that you are right, and that a cookie *value* can (regrettably still) only 
consist of US-ASCII characters (not including "é" thus).

(I cannot find in the specs a way to quote a non-US-ASCII character either; that's 
apparently only allowed in parts defined as "comments")

(It is stated somewhere else in RFC 6265 that it is recommended to encode the Cookie value 
via e.g. Base64, if it were to potentially contain non US-ASCII characters).

The cookie name is a "token", and the definition of "token" sends us back to RFC2616.
In "2.2 Basic Rules", RFC2616 states :

    token          = 1*<any CHAR except CTLs or separators>
        separators     = "(" | ")" | "<" | ">" | "@"
                       | "," | ";" | ":" | "\" | <">
                       | "/" | "[" | "]" | "?" | "="
                       | "{" | "}" | SP | HT
...
       CHAR           = <any US-ASCII character (octets 0 - 127)>
       CTL            = <any US-ASCII control character
                         (octets 0 - 31) and DEL (127)>

So, this all would tend to show that you are right, and that Cookie names (as well as 
values) can only consist of US-ASCII characters, and that "é" is thus not allowed (without 
some form of encoding that would represent it as a sequence of US-ASCII characters).

Which, in my personal opinion is a lasting p-i-t-a and shame.  And I cannot imagine how it 
can be nowadays that nobody has yet gotten around to proposing a HTTP 2.0 RFC where the 
default character set would be Unicode, UTF-8 encoded, for everything excluding maybe 
header names.  But that's neither here nor there.

To get back to the original OP's question thus, it seems to me that
- Tomcat 7.x would not be in violation of the specs, if it indeed rejects a Cookie header 
containing any non-US-ASCII character (whether in the cookie name or value).
- That the error message could be improved ("é" is not a control character, it's just 
invalid here)
- but that the real fix for the OP may be to Base64-encode the cookie value before sending 
it to the browser.
That's also because it may happen one day that even a browser which respects the specs to 
the letter (one never knows), could reject a value like : 
"abcé","abc","abc","abc","abc","abc","abc","abc","abc";


[1] http://tools.ietf.org/search/rfc2616
[2] http://tools.ietf.org/search/rfc6265
[3] http://tools.ietf.org/search/rfc6265#section-4.1.1


(*) The question of whether Catalan is a language, or merely a northern dialect of 
Valenciano, is left to the reader's appreciation ( ;-) ).

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: cookie issue with Tomcat 7 - does not accept the character "é"

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Kevin,

On 2/2/14, 2:31 PM, Callinswood,Kevin,VEVEY,GLOBE BTC wrote:
> We have upgraded to Tomcat 7 from Tomcat 6 and we are now facing 
> issues due to some of the standard company cookies containing an
> "é".
> 
> Tomcat 6 accepted the "é" but upgrading to Tomcat 7 we get an
> error if the "é" is any parameter except for the 1st position.

What you do mean "any parameter except for the 1st position"? You said
this was about cookies...

> The error received is:
> 
> SEVERE: Error processing request 
> java.lang.IllegalArgumentException: Control character in cookie
> value or attribute.

Can you give a protocol dump including byte-translation? For example,
é is usually expressed as 0xc9 and appears in ISO-8859-1 as a single
byte. Since it's in the top-half of the ISO-8859-1 character set,
UTF-8 requires that it be represented by two bytes: 0xc3 0xa9

Without quoting, unquoted Cookie names and values may be any US-ASCII
character from 0x32 - 0x7e except for any of ("(" | ")" | "<" | ">" |
"@" | "," | ";" | ":" | "\" | <"> | "/" | "[" | "]" | "?" | "=" | "{"
| "}" | SP | HT). None of the characters above are within that range,
so the cookie value must be quoted. (It looks to me like Cookie names
must always be in US-ASCII... I didn't think that was the case but I'm
not motivated to track-down every word of the spec looking for
justification).

What is the character encoding of the request? What client are you
using? Who created the cookie in the first place?

> I have tried playing around with the parameters in the 
> catalana.properties file but with no success.  Is there a way to 
> remove all checking of cookies ?

Tomcat has become more standards-strict in version 7. This page should
give you a bit of insight, though it is quite technical:
http://wiki.apache.org/tomcat/Cookies

> Possible solutions are to revert to Tomcat 6, change web server,
> or encode the cookies.  We are planning a go-live a week from now
> so reverting to Tomcat 6 seems to be the solution in the short
> term.

You decided to start testing with a new major application server
version 1 week before deployment? Hmm. Sounds like using Tomcat 6 is
the right short-term move. You really need to identify the problem,
though: it's only going to get worse.

Now, if you had Tomcat 6 create those cookies and the client is
sending them back tom Tomcat 7, then you may want to expire those old
cookies and see what a Tomcat 7 roundtrip looks like. Tomcat 7 may be
more properly encoding the cookies in the first place, solving the
problem before it begins.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJS7qPGAAoJEBzwKT+lPKRYmeEP/A8O5vxtTJ2dnQnQn6dzkNv7
g+YSx8c1Va1QkHlZe1vUefUlZJ1SkzFivbmyTX3TFsKI8wDPNOWRjJusHxDKnIjl
URpeCew8/1vUWtuN1xvCXO4OWE5UdPRktmKn+aO4anuKvZGrl7OnEMXx0Ans4U9k
6SLYcYkT8rnwjrwyp5/xoc8hEaUWRHQZCNAaU1//OC0OFV+MLiL2IgVucg8CdvIk
v/z5DxIvGvhTkHBzWztlOku6l43yyJMEs8XsYPGwOgAY4KYu1vDLMBtDq3HZ9Coz
mSX3ytGrth3XAJbPdcopYcVU96XFEtOPwvBcGU+GEVf2Gc0C1GWE1ZVntwlTAbvD
TBISsjzuOouI/6LjjdCAUnHNBjnHGv0vk0R3CFXu4igxDKM/2CrBA/keJ7IUYQku
dB/y4hsNPkQ4wHJVLof7l+bYI6TbzS6xVpR3QPwlmVub0mRiYND4kcnDYrf21SFU
hsAewZyRGxk41pM/Y5e0Ep1tCqVbgMn76nwuhmL07YLnkY7+75LMVJgnT2HA4ZXh
SUwB2zp4qa43baQ0T+iAe6a1wEPRjdlV2PKeHlFv1u304HG8Ke4bB6QBQWlWDXYr
lqiqMetQNrkKK6WXmGkvkXnu736EGizeMY/D+C7RFPb5i+7ejsX/nMV5C6nHrZM9
xX9SxRXlZkABNFwV+8kg
=0leN
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org