如何使用 Apache 配置设置 SameSite cookie 属性?

Abh*_*bbu  4 apache http-headers samesite

我无法在“应用程序”选项卡中使用内置开发人员工具看到 SameSite=Strict。

我在 Apache 配置中添加了下面的标题代码

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

Run Code Online (Sandbox Code Playgroud)

请让我知道如何使用上述设置设置 SameSite=Strict。

小智  18

对于 apache2 >= 2.2.4

Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure;SameSite=Strict

Run Code Online (Sandbox Code Playgroud)

对于低于 2.2.4 的 apache2

Header set Set-Cookie HttpOnly;Secure;SameSite=Strict

Run Code Online (Sandbox Code Playgroud)

  • 第二个示例设置了一个没有 cookie 名称或 cookie 值的 cookie。 (2认同)

Asu*_*sui  5

在我的本地环境 (Apache 2.4) 中启用 mod_headers 后,我能够通过在我的 vhost 中添加如下指令来实现这一点:

<ifmodule mod_headers.c>
Header always edit Set-Cookie (.*) "$1; SameSite=strict"
</ifmodule> 

Run Code Online (Sandbox Code Playgroud)

区别在哪里?为什么它对你不起作用?也许它在分号后缺少“空格”?

<ifmodule mod_headers.c>
# always is similar to "onerrors"
        Header always edit Set-Cookie (.*) "$1; SameSite=strict"
# success is similar to http 2xx response code
        Header onsuccess edit Set-Cookie (.*) "$1; SameSite=strict"
# remove duplications (apache sends from both tables always and onsuccess)
        ## https://www.tunetheweb.com/security/http-security-headers/secure-cookies/
        #Strip off double SameSite=strict settings as using above you can sometimes get both
        Header edit Set-Cookie ^(.*);\s?SameSite=strict;?\s?(.*);\s?SameSite=strict;?\s?(.*)$ "$1; $2; $3; SameSite=strict"

        #Strip off double ;; settings
        Header edit Set-Cookie ^(.*);\s?;\s?(.*)$ "$1; $2"

</ifmodule>

Run Code Online (Sandbox Code Playgroud)

[apache 手册] ( https://httpd.apache.org/docs/2.2/de/mod/mod_headers.html )

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值