Antiforgery Token Cookie Not Appearing in Request Headers Only in when Embeded in Iframe

狂风中的少年 提交于 2019-12-11 06:34:56

问题


I'm trying to embed a simple web app that will POST user input that is running asp.net Core 2.0 into an iframe. The problem I am having is that while embedded, the request headers that are being generated lack the cookie header that contains the .AspNetCore.Antiforgery.[token]. It is being generated as expected outside of the iframe.

This is causing a 400 error because the post is unable to validate the token.

Request Headers generated outside of iframe: Request Headers: NO IFRAME

Request Headers generated inside of iframe: Request Headers: INSIDE IFRAME

Has anyone had this issue with the antiforgery token library?

Thanks!!


回答1:


Turns out the SameSite property on the cookie class for the antiforgery options needs to be set to None for this to work:

services.AddAntiforgery(options => { options.Cookie.SameSite = SameSiteMode.None; });



来源:https://stackoverflow.com/questions/52669145/antiforgery-token-cookie-not-appearing-in-request-headers-only-in-when-embeded-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!