【问题标题】:How to set a Secure and HTTP Flag on a Cookie only when it doesnt have one? ( .htaccess )仅当没有 Cookie 时,如何在 Cookie 上设置安全和 HTTP 标志? ( .htaccess )
【发布时间】:2017-10-03 20:46:35
【问题描述】:

我目前正在使用这个htaccess来添加secure和HTTPonly

Header always edit Set-Cookie (.*) "$1; HTTPOnly; Secure"

但是因为这个域上的一个cookie已经有这个标志,我怎么能只将它应用到没有它的那些?因为我没有直接访问服务器的权限,所以需要通过 .htaccess 来完成

【问题讨论】:

  • 你有什么 apache 版本?
  • @Webdesigner Apache/2.4.10

标签: apache .htaccess security cookies server


【解决方案1】:

以下方法将检查浏览器是否向我们发送了 HTTPOnly 和 Secure Cookie。如果这些不包括在内,您可以像往常一样使用 Header 命令进行设置。

<If "%{HTTP_COOKIE}" !=~ "m#HTTPOnly.*Secure#">
    Header always edit Set-Cookie (.*) "$1; HTTPOnly; Secure"
</If>

这仅适用于 apache 2.4+

【讨论】:

    【解决方案2】:

    这个问题的解决方案是这样的:

    Header always edit Set-Cookie (.*) "$1; HttpOnly; Secure"
    #Strip off double Secure or HttpOnly settings as if App and Apache sets above you can sometimes get both
    Header always edit Set-Cookie (?i)^(.*);\s?Secure;?\s?(.*)?;?\s?Secure;?\s?(.*)$ "$1; $2; $3; Secure"
    Header always edit Set-Cookie (?i)^(.*);\s?HttpOnly;?\s?(.*)?;?\s?HttpOnly;?\s?(.*)$ "$1; $2; $3; HttpOnly"
    #Strip off double ;; settings
    Header always edit* Set-Cookie (;\s?){2,} "; "
    
    猜你喜欢
    • 2015-02-08
    • 2012-10-13
    • 2014-04-08
    • 2010-11-29
    • 2018-04-28
    • 2017-09-11
    • 2022-01-07
    • 2016-09-11
    • 2020-01-11
    相关资源
    最近更新 更多