使用 Apache 配置在 JSESSIONID cookie 上设置 SameSite 属性

Setting the SameSite Attribute on the JSESSIONID cookie using Apache config

我有 Apache 2.4 和 Tomcat 9 安装程序。我需要在 JSESSIONID cookie 上设置 SameSite 属性。

使用Fiddler,登录时看到cookie设置如下;

Set-Cookie: JSESSIONID=XXXXXXXXXXX; Path=/prod1; Secure; HttpOnly

我还想使用 Apache 在 cookie 上设置 SameSite 属性。我在 vhost conf 中有以下内容,但这似乎不起作用。

Header always edit* Set-Cookie "^(JSESSIONID.*)$" ;SameSite=Lax

我知道 Header 指令可以正常工作,因为我已经在此行上方设置了其他属性(不在 cookie 上)。 但是,这似乎不起作用。我尝试了一些变体,但似乎无法正常工作。

有什么建议吗?

经过更多的尝试和错误,我发现删除始终条件有效并且 JSESIONID cookie 具有 SameSite 属性。

看Apachemod_headers文档,原因不明。文档说

always is not a superset of onsuccess with respect to existing headers

但是,没有给出太多细节。 参考:Apache Module mod_headers