Safari 扩展 cookie 无法识别/通过
我最近将 Chrome 扩展程序移植到 Safari,并遇到了这种错误(错误、功能等)。
因此,在全局页面中,我有一个对安全页面的 XMLHTTP 请求,该页面仅在您登录后可用。
示例:
- 我只是使用浏览器登录 - 就像通常在 facebook 或其他安全页面上所做的
- 那样 之后,在全局页面中,我加载一个仅登录可用的 xmlhttp - 它说我没有登录
,似乎全局页面有点有它自己的cookie,所以安全页面认为我是新的
ps:在 Chrome 中我可以加载该页面,它认为我代表登录用户行事,所以我猜 Safari
pps 中有一些限制:我听说有一个在 Safari 中阻止第三方 cookie 选项,但即使我将其选中为“从不阻止”,它仍然不起作用
I've recently been porting a Chrome extension to Safari, and encountered this kind of error (bug, feature, etc.)
So, in global page i have a XMLHTTP request to a secure page which is available only after you login.
Example:
- I simply login using browser - as usually you do on facebook or other secure pages
- After that, in global page, I load a login-only-available xmlhttp - and it says i'm not logged in
it seems that global page somewhat has it's own cookies, so a secure page thinks i'm new
ps: in Chrome i can load that page and it thinks i'm acting on behalf of logged in user, so i guess there are some restrictions in Safari
pps: i heard there's a Block third-party cookies option in Safari, but even if i checked it to "Never block" it still doesn't work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不幸的是,这个问题在 safari 5.1.7 windows 版本中仍然存在。
我找到了一种解决方法,可以使用消息传递将登录凭据(用户名/密码对)传递到全局页面,并且全局页面使用它们以静默方式登录。
Unfortunately the problem is still existent in safari 5.1.7 windows version.
I've found a workaround to pass login credentials (username/password pairs) to the global page using message passing and global page use them to login silently.
我在 Windows 版 Safari 5.1.2 中遇到了这个问题,但升级到当前版本 (5.1.7) 后问题消失了。也许他们在某个中间版本上修复了它。它也适用于 Mac OS X 的 Safari 5.1.3。
I had that problem with Safari 5.1.2 for Windows, but after upgrading to the current version (5.1.7) the problem disappeared. Maybe they fixed it on some intermediate version. It is also working for me on a Safari 5.1.3 for Mac OS X.
Cookie 可以选择标记为 HttpOnly 或 Secure。如果它没有传递它们,您可能正在尝试从 HTTPS 登录后登录页面访问同一站点上的 HTTP 资源,因此浏览器将不允许通过非安全链接发送安全 cookie。实际上,HTTP 和 HTTPS 站点被视为分开的。
您需要确保登录后将浏览器重定向到 HTTP 并设置 HttpOnly cookie,或者仅通过 HTTPS 执行 XMLHttpRequest。这会更安全,并且不会真正增加太多服务器开销(过去在硬件速度较慢时会出现这种情况,但谷歌表示,当 Gmail 转而使用 HTTPS 作为默认设置时,它对服务器负载的影响不会超过几个)的百分比)。
尝试将整个站点设置为通过 HTTPS 运行,看看是否可以解决问题。另外,使用 firebug 和 firecookie 扩展 查看 cookie 是否启用了这些选项之一(右侧两列)。
Cookies can optionally be marked as either HttpOnly or Secure. If it's not passing them across, you are probably trying to access a HTTP resource on the same site from the HTTPS post-login landing page, so the browser won't allow the secure cookie to be sent over a non-secure link. Effectively, the HTTP and HTTPS sites are being treated as separate.
You either need to make sure that after login, you get the browser redirected to HTTP and set a HttpOnly cookie, or just do the XMLHttpRequest over HTTPS. This would be more secure and doesn't really add much server overhead (it used to when hardware was slow, but Google say that when Gmail went over to using HTTPS as a default, it didn't impact on server load more than a couple of percent).
Try setting the entire site to run over HTTPS and see if that fixes it. Also, use firebug and the firecookie extension to see whether the cookies have either of these options enabled (right hand two columns).
Cookie 不能是“会话 Cookie”,它们必须是持久的。设置到期日期。
需要在服务器端完成。例如,对于 Node.js/Express 来说是这样的:
Cookies must not be "Session cookies", they must be persistent. Set expiration date.
It needs to be done on server-side. In example, for Node.js/Express something like this: