简体   繁体   English

接收到包含无效 cookie 的 cookie 标头。

[英]A cookie header was received that contained an invalid cookie.

I am migrating my Server from Tomcat-6 to Tomcat-9 .我正在将我的服务器从Tomcat-6迁移Tomcat-9 My website is designed for the protocol of HTTP/1.1 .我的网站是为 HTTP/1.1 协议设计的。 The server.xml file contains the Connector Protocol of org.apache.coyote.http11.Http11NioProtocol . server.xml 文件包含org.apache.coyote.http11.Http11NioProtocol的连接器协议。 The server starts up normally without generating any errors.服务器正常启动,不会产生任何错误。 However, when I try to access my website using localhost, I get the following error :-但是,当我尝试使用 localhost 访问我的网站时,出现以下错误:-

INFO [https-nio-8445-exec-3] org.apache.tomcat.util.http.parser.Cookie.logInvalidHeader A cookie header was received [ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 21, 22, 23];信息 [https-nio-8445-exec-3] org.apache.tomcat.util.http.parser.Cookie.logInvalidHeader A cookie header was received [2, 3, 4, 5, 6, 7, 8, 9, 10 , 11, 12, 21, 22, 23]; userId=53136] that contained an invalid cookie. userId=53136] 包含无效的 cookie。 That cookie will be ignored.Note: further occurrences of this error will be logged at DEBUG level.该 cookie 将被忽略。注意:此错误的进一步发生将在调试级别记录。

Can anyone please tell me the reason for this error?谁能告诉我这个错误的原因? What causes an invalid cookie?是什么导致无效的 cookie? Can this error be avoided if I use a different connector?如果我使用不同的连接器,可以避免这个错误吗?

I found the API deployed on tomcat able to grab the cookies when I send a cURL request, though there was tomcat warning.我发现部署在 tomcat 上的 API 在我发送 cURL 请求时能够抓取 cookie,尽管有 tomcat 警告。

curl -XPOST -H "Content-Type: application/json"  --cookie "userId=64ad960c-bb7e-48dd-8191-4f31539bc2c2,accessToken=64ad960c-bb7e-48dd-8191-4f31539bc2c2" -d '{"message":"play porcupine tree"}' http://localhost:9090/nlu/convo

But to remove the warning, had to update cookie processor ( LegacyCookieProcessor ) in the tomcat config ( conf/context.xml )但是要删除警告,必须在 tomcat 配置( conf/context.xml )中更新 cookie 处理器( LegacyCookieProcessor

Example,例如,

cat /usr/local/apache-tomcat-8.5.12/conf/context.xml 
<?xml version="1.0" encoding="UTF-8"?>
<!-- The contents of this file will be loaded for each web application -->
<Context>

    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>

    <!--
    <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor" />
    -->

    <CookieProcessor className="org.apache.tomcat.util.http.LegacyCookieProcessor" />

</Context>

I thought org.apache.tomcat.util.http.Rfc6265CookieProcessor would work but did not, LegacyCookieProcessor is required.我认为org.apache.tomcat.util.http.Rfc6265CookieProcessor会起作用,但没有,需要LegacyCookieProcessor

Reference参考

https://tomcat.apache.org/tomcat-8.5-doc/config/cookie-processor.html#Legacy_Cookie_Processor_-_org.apache.tomcat.util.http.LegacyCookieProcessor https://tomcat.apache.org/tomcat-8.5-doc/config/cookie-processor.html#Legacy_Cookie_Processor_-_org.apache.tomcat.util.http.LegacyCookieProcessor

https://tools.ietf.org/html/rfc6265 https://tools.ietf.org/html/rfc6265

LegacyCookieProcessor implements a strict interpretation of the cookie specifications. LegacyCookieProcessor实现了对 cookie 规范的严格解释。 Due to various interoperability issues with browsers not all strict behaviours are enabled by default and additional options are available to further relax the behaviour of this cookie processor if required.由于浏览器的各种互操作性问题,并非所有严格行为都默认启用,如果需要,还可以使用其他选项来进一步放宽此 cookie 处理器的行为。

i was getting this issue with spring boot of version above 2.2.x我在 2.2.x 以上版本的 Spring Boot 中遇到了这个问题

it got fixed after adding below bean添加下面的bean后它得到了修复

public WebServerFactoryCustomizer<TomcatServletWebServerFactory> cookieProcessorCustomizer() {
    return tomcatServletWebServerFactory -> tomcatServletWebServerFactory.addContextCustomizers((TomcatContextCustomizer) context -> {
      context.setCookieProcessor(new LegacyCookieProcessor());
    });
  }

Fwiw: I somehow got my Chrome browser into a really b0rken state, getting it to send a malformed cookie with mismatched quotes: "XSRF-TOKEN=93926112-aa12-440e-8e06-02b7fbce27d5; Fwiw:我以某种方式让我的 Chrome 浏览器进入了一个真正的 b0rken 状态,让它发送一个格式错误的 cookie,其中包含不匹配的引号: "XSRF-TOKEN=93926112-aa12-440e-8e06-02b7fbce27d5;

Just clearing the cookie from the developer tools wasn't sufficient, but Clear storage from the sidebar of the Application tab seems to have done it.仅仅从开发人员工具中清除 cookie 是不够的,但是从Application选项卡的侧边栏中Clear storage似乎已经完成了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM