6

I'm a developer and I face the exception below when Cookie contain umlaut characters (ä,ö,ü), I tried many solutions and configurations without any result.

I use Tomcat7

Any solution please

Feb 21, 2013 6:29:16 AM org.apache.coyote.http11.AbstractHttp11Processor process
SEVERE: Error processing request
java.lang.IllegalArgumentException: Control character in cookie value or attribute.
    at org.apache.tomcat.util.http.CookieSupport.isHttpSeparator(CookieSupport.java:193)
    at org.apache.tomcat.util.http.Cookies.getTokenEndPosition(Cookies.java:488)
    at org.apache.tomcat.util.http.Cookies.processCookieHeader(Cookies.java:291)
    at org.apache.tomcat.util.http.Cookies.processCookies(Cookies.java:168)
    at org.apache.tomcat.util.http.Cookies.getCookieCount(Cookies.java:106)
    at org.apache.catalina.connector.CoyoteAdapter.parseSessionCookiesId(CoyoteAdapter.java:919)
    at org.apache.catalina.connector.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:688)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:402)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1600)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
user2364106
  • 61
  • 1
  • 2
  • See http://stackoverflow.com/questions/6108207/definite-guide-to-valid-cookie-values and http://stackoverflow.com/questions/1969232/allowed-characters-in-cookies. A solution is to encode your string in UTF-8, and the use base64 to get acceptable ascii characters. – JB Nizet May 08 '13 at 21:59

3 Answers3

3

According to a comment on another question you need to upgrade to tomcat 8.0.15 (or higher) and enable the RFC 6455 cookie processor. Documented here: http://tomcat.apache.org/tomcat-8.0-doc/config/cookie-processor.html

Enable it in your conf/context.xml via:

<Context>
  <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor" />
</Context>
MrSpock
  • 1,470
  • 16
  • 10
  • In my case tomcat 7.0.68 upgraded to 8.5.15 could solve the problem, but it cause another problem: `java.lang.IllegalArgumentException: An invalid domain [.foo.bar.com] was specified for this cookie` – zhuguowei Feb 29 '20 at 04:02
0

Use UTF-8 Encoding.

You can either set it globally:

java -Dfile.encoding=UTF-8

Or locally:

System.setProperty("file.encoding", "UTF-8");

byte inbytes[] = new byte[1024];
FileInputStream fis = new FileInputStream("the.location.of.your.cookie");
fis.read(inbytes);

Also, if you are editing the cookies manually, don't save Ä. Instead use the UTF-8 equivalent, which is

System.out.println("\u00c4");



Chars   Unicode
------------------------------
Ä, ä    \u00c4, \u00e4
Ö, ö    \u00d6, \u00f6
Ü, ü    \u00dc, \u00fc
ß       \u00df
Alexandre Santos
  • 8,170
  • 10
  • 42
  • 64
0

Right now I have met the same problem, First I have tried upgraded tomcat 7 to tomcat 8.5.51 it work but it raised new problem

java.lang.IllegalArgumentException: An invalid domain [.foo.bar.com] was specified for this cookie

because I do not need the cookie in my case, so I just exclude cookie at Nginx level, and it also could resolve this problem

    proxy_set_header Cookie "";
zhuguowei
  • 8,401
  • 16
  • 70
  • 106