如何在 google 翻译 cookie 上设置安全属性
how do I set the secure attribute on the google translate cookie
每次对我们的网站进行 PCI 扫描后,我都必须进入扫描结果并为“Cookie 不使用安全属性”问题添加争议,PCI 失败条件,Google 翻译cookie。有没有办法为 Google 翻译 cookie 设置此属性?我在网上搜索过,但到目前为止什么也没找到,除了 Chrome 78 的旧 GitHub 问题,其中一位发帖人提到 Google 翻译,但只是说它正在经历与其他海报相同的问题。
服务器是 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>
经过两天的无果搜索和反复试验,我终于解决了这个问题。所以我想我会 post 这里的解决方案来避免让其他人头疼。通过使用失败请求跟踪来查看 URL Rewrite 正在做什么(或没有做什么,事实证明)发现的问题是,在评估先决条件时,IIS 评估 all 的 cookie 作为一个字符串。因此,即使 一个 的 cookie 已经具有安全属性,前提条件也会失败并且 none 的其他 cookie 将获得安全属性集。这似乎是 IIS 中的一个错误,因为重写规则本身分别作用于每个 cookie。无论如何,解决方案是完全放弃先决条件。我不喜欢这个“解决方案”的部分是,如果一个 cookie 已经具有 Secure
属性,它会得到第二个。但是浏览器似乎忽略了这一点,现在将所有 cookie 称为安全。
每次对我们的网站进行 PCI 扫描后,我都必须进入扫描结果并为“Cookie 不使用安全属性”问题添加争议,PCI 失败条件,Google 翻译cookie。有没有办法为 Google 翻译 cookie 设置此属性?我在网上搜索过,但到目前为止什么也没找到,除了 Chrome 78 的旧 GitHub 问题,其中一位发帖人提到 Google 翻译,但只是说它正在经历与其他海报相同的问题。
服务器是 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>
经过两天的无果搜索和反复试验,我终于解决了这个问题。所以我想我会 post 这里的解决方案来避免让其他人头疼。通过使用失败请求跟踪来查看 URL Rewrite 正在做什么(或没有做什么,事实证明)发现的问题是,在评估先决条件时,IIS 评估 all 的 cookie 作为一个字符串。因此,即使 一个 的 cookie 已经具有安全属性,前提条件也会失败并且 none 的其他 cookie 将获得安全属性集。这似乎是 IIS 中的一个错误,因为重写规则本身分别作用于每个 cookie。无论如何,解决方案是完全放弃先决条件。我不喜欢这个“解决方案”的部分是,如果一个 cookie 已经具有 Secure
属性,它会得到第二个。但是浏览器似乎忽略了这一点,现在将所有 cookie 称为安全。