Box*_*iom 4 asp.net cookies azure azure-web-app-service
要在Chrome 80将有所变动SameSite准备,我从升级我的.NET框架API4.6.2
来4.7.2
。
我创建了一个简单的测试端点,它简单地设置了一个 cookie SameSite=None
:
public class TestController : ApiController
{
public IHttpActionResult Get()
{
var cookie = new HttpCookie("foo", "bar")
{
HttpOnly = true,
Secure = true,
SameSite = SameSiteMode.None
};
HttpContext.Current.Response.SetCookie(cookie);
return Ok();
}
}
Run Code Online (Sandbox Code Playgroud)
这在本地按预期工作,并返回以下标头:
set-cookie: foo=bar; path=/; secure; HttpOnly; SameSite=None
但是,这在发布到配置为 4.7 作为运行时堆栈的 Azure Web 应用程序时不起作用。Web 应用程序返回没有 SameSite 的 cookie 标头:
Set-Cookie: foo=bar; path=/; secure; HttpOnly
如果我将它设置为Strict
或者Lax
它也可以在 Azure 中按预期工作。
这是 Azure 的问题吗?是否需要在 Web 应用程序上配置任何内容才能使其正常工作,或者我可能必须以不同的方式设置 cookie?
来自/sf/answers/2727002421/。也适用于 4.6.1 的一种解决方案是将以下内容添加到您的 web.config
编辑: Chrome 现在希望您secure;
在使用 SameSite=none 时将其包含在 cookie 中。
<system.webServer>
<rewrite>
<outboundRules>
<clear />
<rule name="Add SameSite" preCondition="No SameSite">
<match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="false" />
<action type="Rewrite" value="{R:0}; secure; SameSite=none" />
<conditions>
</conditions>
</rule>
<preConditions>
<preCondition name="No SameSite">
<add input="{RESPONSE_Set_Cookie}" pattern="." />
<add input="{RESPONSE_Set_Cookie}" pattern="; secure; SameSite=none" negate="true" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
这假设您在托管自己的 iis 站点时安装了 url rewrite。https://www.iis.net/downloads/microsoft/url-rewrite
小智 6
Azure 将在月底前更新 - 请参阅此处的官方公告:https : //docs.microsoft.com/answers/questions/6842/announcement-samesite-cookie-handling-and-net-fram.html
我们看到了同样的事情,专门更新到 4.7.2 以解决相同的站点问题。
看来这已通过 Microsoft 于 11 月 10 日发布的版本进行了修补,但尚未在 Azure 上提供。
正在部署的站点以 .Net 4.7.2 为目标,并且更改在本地测试时按预期工作。
如果我们反编译 System.Web.dll(通过 Kudu 下载),我们会看到一个不处理相同站点 cookie 的旧版本。
这对其他人来说似乎是一个问题(尽管 4.8 主题是 4.7.2)。
System.Web.dll 上的时间戳是 11/12/2019 但反编译看到:
if (this._sameSite != SameSiteMode.None)
{
stringBuilder.Append("; SameSite=");
stringBuilder.Append(this._sameSite);
}
Run Code Online (Sandbox Code Playgroud)
微软的 Barry Dorrans 似乎在本页底部确认这尚未推出到 Azure:https : //devblogs.microsoft.com/aspnet/upcoming-samesite-cookie-changes-in-asp-net -and-asp-net-core/在那里我们也提出了这个问题。
编辑:我们被告知补丁将从本周开始推出到 Azure,预计将于 1 月 31 日完成。
更新在这里正式传达:https : //docs.microsoft.com/answers/questions/6842/announcement-samesite-cookie-handling-and-net-fram.html
归档时间: |
|
查看次数: |
6161 次 |
最近记录: |