我已经为此感到困惑了两天。情况:
iframe
具有不同域的站点中运行的(我无法更改它,但是我可以访问两个站点)。没有iframe,就不会有问题。似乎在InPrivate模式下,x-csfrtoken
在请求标头中设置了,在InPrivate模式之外,此标头未设置。然后,服务器返回HTTP 403错误,这似乎是问题的根源。
我不知道如何指示服务器(IIS)忽略此令牌。
要查看此行为的实际效果,请转到该站点并输入任何内容,然后单击“ Inloggen”。您应该看到一个登录错误(荷兰语),但是在Windows 7的IE11中,不会出现此错误。
我尝试对Microsoft进行此解决方案,以对进行不当的使用LocalLow
,但该解决方案无法解决该问题,因此似乎无关。
显然,这是Windows 7和Windows 8 / 8.1上IE11中的错误。我发现浏览器确实发送了csrftoken
cookie,但是忘记了必需的x-csrftoken
HTTP Header参数,所有其他浏览器(包括Windows 10上的IE和IE11的旧版本和新版本)都正确发送了该参数。
如果您的工具链通过验证x-csrftoken
(任何框架都建议)来保护自己,则IE11失败。它在这里WebSharper讨论,但没有一个完整的解决方案呢。
我发现可以正常工作的解决方法如下。它很容易处理,它会在到达时更改HTTP标头,但其他工具也可以这样做(以代理服务器为例)。global.asax.fs
如果您使用的是WebSharper ,请在F#中放置以下代码(有点混乱,但是我将整理一下作为读者的练习;)。
member __.Application_BeginRequest(sender: obj, args: System.EventArgs) =
HttpContext.Current
|> function
| null -> ()
| ctx ->
match ctx.Request with
| null -> ()
| req ->
match req.Cookies.Item "csrftoken", req.Headers.Item "x-csrftoken" with
| null, null -> ()
| cookie, null ->
// fix for IE11, which does not always set the HTTP Header "x-csrftoken"
try req.Headers.Item "x-csrftoken" <- cookie.Value
with _ -> () // ignore possible errors
| null, _ ->
// if header is set but cookie is not, there's nothing we can do (cookie collection is read-only)
()
| cookie, csrfHeader when cookie.Value <> csrfHeader ->
try req.Headers.Item "x-csrftoken" <- cookie.Value
with _ -> () // ignore possible errors
| _ ->
() // all is fine, the default: cookie "csfrtoken" and header "x-csfrtoken" are equal
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句