关于session 失效问题 解决了很多天 ,终于再最后完美解决了问题、
首先说一下走的坑,一开始iframe 丢失session解决方法是用nginx进行反向代理来解决这个问题
配置如下
server {
listen 80;
# listen somename:8080;
server_name 127.0.0.1;
location /{
# root html;
proxy_pass http://localhost:8001;
}
}
结果还是没有解决问题 ,各种找问题 网上大多都是用P3P跟iis 修改,但我这是纯html啊 不是asp页面所以全部不行。
然后又发现配置nginx中的
server {
listen 80;
# listen somename:8080;
server_name 127.0.0.1;
location /{
# root html;
#proxy_cookie_domain localhost 127.0.0.1;
proxy_pass http://localhost:8001;
#proxy_set_header Cookie $http_cookie;
proxy_redirect http://localhost:8001/ http://127.0.0.1:80/;
#proxy_cookie_domain http://127.0.0.1 http://localhost:8001;
}
}
proxy_redirect 跟proxy_cookie_domain 还有proxy_cookie_path 具体配置自行百度
但是还是没办法解决问题。
后来询问了一个大神 ,一看游览器内核,Google内核80以上了,(此时其他游览器是正常的 但我都没有尝试 以后注意 ,不然就可以早点发现原因)
其实控制台有排除警告一直没有注意但是
A cookie associated with a cross-site resource at http://xxx.xxxx.xxx/ was set without the `SameSite` attribute. It has been blocked, as Chrome now only delivers cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at
所以后来知道Google 将在2020年2月4号发布的 Chrome 80 版本(schedule:https://www.chromestatus.com/features/schedule)中默认屏蔽所有第三方 Cookie,即默认为所有 Cookie 加上 SameSite=Lax 属性(https://www.chromestatus.com/feature/5088147346030592),并且拒绝非Secure的Cookie设为 SameSite=None(https://www.chromestatus.com/feature/5633521622188032)此举是为了从源头屏蔽 CSRF 漏洞
最后解决方案
解决方案
方案一
Chrome 中打开 chrome://flags/#same-site-by-default-cookies 和 chrome://flags/#cookies-without-same-site-must-be-secure ,设置为 Disabled ,重启浏览器
方案二
降级到 Chrome 79 及以下版本,并关闭自动更新
方案三 (适用于 API)
将 API 切换为 HTTPS 协议(需要有 SSL 证书),并且检查响应头中的 Set-Cookie 中是否包含了 SameSite=None 和 Secure字样
如果没有 HTTPS 协议的 API, 请尝试 方案一 或 方案二
方案四
改造 http 服务,购买 SSL 证书,升级到 https 服务,并执行方案三.1
同时后台也可以改 但是我没有试过
留下文章那个连接
https://blog.youkuaiyun.com/weixin_44269886/article/details/102459425
最后终于可以了 放下一口气!