[英]IE11 does not set x-cfrtoken HTTP header, unless with an InPrivate window, this causes server to respond with HTTP 403 Access Denied
我已經為此感到困惑了兩天。 情況:
iframe
運行的(我無法更改它,但是我可以訪問兩個網站)。 沒有iframe,就不會有問題。 似乎在InPrivate模式下,在請求標頭中設置了x-csfrtoken
,在InPrivate模式之外,未設置此標頭 。 然后,服務器返回HTTP 403錯誤,這似乎是問題的根源。
我不知道如何指示服務器(IIS)忽略此令牌。
要查看此行為的實際效果,請轉到該站點並輸入任何內容,然后單擊“ Inloggen”。 您應該看到一個登錄錯誤(荷蘭語),但是在Windows 7的IE11中,不會出現此錯誤。
我在LocalLow
上以不當的權利嘗試了Microsoft的此解決方案 ,但該解決方案無法解決該問題,並且在其他方面似乎無關。
顯然,這是Windows 7和Windows 8 / 8.1上IE11中的錯誤。 我發現瀏覽器確實發送了csrftoken
cookie,但是忘記了必需的x-csrftoken
HTTP Header參數,所有其他瀏覽器(包括Windows 10上的IE和IE11的較新和較新版本)都正確發送了該參數。
如果您的工具鏈通過驗證x-csrftoken
(任何框架都建議使用)來保護自己,則IE11失敗。 此處已針對WebSharper進行了討論 ,但還沒有完整的解決方案。
我發現可以正常工作的解決方法如下。 它很容易處理,它會在到達時更改HTTP標頭,但是其他工具也可以這樣做(請考慮一個代理服務器)。 如果您使用的是WebSharper,則可以將以下代碼放在F#中的global.asax.fs
中(有點雜亂,但我將整理一下作為讀者的練習;)。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.