【问题标题】:how do I set the secure attribute on the google translate cookie如何在谷歌翻译 cookie 上设置安全属性
【发布时间】:2021-06-14 18:07:41
【问题描述】:

每次对我们的网站进行 PCI 扫描后,我都必须进入扫描结果并为 Google 翻译 cookie 的“Cookie 不使用安全属性”问题(PCI 失败条件)添加争议。有没有办法为谷歌翻译 cookie 设置这个属性?我在网上搜索过,但到目前为止什么也没找到,除了 Chrome 78 的一个旧 GitHub 问题,其中一张海报提到谷歌翻译,但只是说它遇到了与其他海报相同的问题。

服务器是 Windows Server 2016 上的 IIS 10。

这是我尝试过的。我将以下内容放入web.config,但传出的cookie仍然没有Secure属性。

<outboundRules rewriteBeforeCache="true">
    <rule name="Add Secure" preCondition="No Secure" patternSyntax="Wildcard">
        <match serverVariable="RESPONSE_Set_Cookie" pattern="*" negate="false" />
        <action type="Rewrite" value="{R:0}; secure" />
        <conditions />
    </rule>
    <rule name="Add HttpOnly" preCondition="No HttpOnly" patternSyntax="Wildcard">
        <match serverVariable="RESPONSE_Set_Cookie" pattern="*" negate="false" />
        <action type="Rewrite" value="{R:0}; HttpOnly" />
        <conditions />
    </rule>
    <rule name="Add SameSite" preCondition="No SameSite" patternSyntax="Wildcard">
        <match serverVariable="RESPONSE_Set_Cookie" pattern="*" negate="false" />
        <action type="Rewrite" value="{R:0}; SameSite=None" />
        <conditions />
    </rule>
    <preConditions>
        <preCondition name="No Secure">
            <add input="{RESPONSE_Set_Cookie}" pattern="." />
            <add input="{RESPONSE_Set_Cookie}" pattern="; secure" negate="true" />
        </preCondition>
        <preCondition name="No HttpOnly">
            <add input="{RESPONSE_Set_Cookie}" pattern="." />
            <add input="{RESPONSE_Set_Cookie}" pattern="; HttpOnly" negate="true" />
        </preCondition>
        <preCondition name="No SameSite">
            <add input="{RESPONSE_Set_Cookie}" pattern="." />
            <add input="{RESPONSE_Set_Cookie}" pattern="; SameSite" negate="true" />
        </preCondition>
    </preConditions>
</outboundRules>

【问题讨论】:

  • 使用上述规则,我现在正确地将HttpOnlySameSite=None 属性设置为googtrans cookie。但由于某种原因,它仍然没有应用secure 属性。

标签: cookies google-translate


【解决方案1】:

经过两天徒劳的搜索和反复试验,我终于解决了这个问题。所以我想我会在这里发布解决方案来避免其他人的头痛。通过使用 Failed Request Tracing 来查看 URL Rewrite 正在做什么(或不做什么,事实证明)发现的问题是,在评估先决条件时,IIS 将 all 的 cookie 评估为一个字符串.因此,即使 one 的 cookie 已经具有安全属性,前提条件将失败,并且 none 的其他 cookie 将获得安全属性集。这似乎是 IIS 中的一个错误,因为重写规则本身分别作用于每个 cookie。无论如何,解决方案是完全放弃先决条件。我不喜欢这个“解决方案”的部分,它确实使它成为一种解决方法,如果一个 cookie 已经具有 Secure 属性,它会得到第二个。但浏览器似乎忽略了这一点,现在将所有 cookie 称为 Secure。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    相关资源
    最近更新 更多