会话 cookie 应该始终是 HttpOnly 吗?
会话 cookie 应该始终是 HttpOnly 吗?
Should a session cookie always be HttpOnly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
会话 cookie 应该始终是 HttpOnly 吗?
Should a session cookie always be HttpOnly?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
JavaScript 应该访问会话 cookie 的原因很少。我遇到的唯一一种情况是 flash 必须有权访问 cookie,因为它必须发出通过相同 cookie 授权的自己的请求。为了给 flash cookie,我必须将 cookie 打印到页面上(这使得 JS 可以使用它们)。
这仍然可以与 HttpOnly 标志集一起使用(但该标志是多余的)。
简而言之,是的,设置flag。
There is very little reason why JavaScript should access the session cookie. The only one I've come across is one where flash had to have access to the cookie because it had to make its own requests that were authorised via the same cookies. And to give flash the cookies I had to print the cookies onto the page (which made them available to JS).
That still would have worked with HttpOnly flag set (but that flag would have been redundant).
In short, yes, set the flag.
如果您只想通过 HTTP(而不是 JavaScript)访问它,那么可以。
一些较旧的浏览器允许您通过 XHR 挖掘 cookie 的标头。我相信这已在新版本中得到修复。
If you only ever want to access it via HTTP (not JavaScript), then yes.
Some older browsers allowed you to dig in the headers via XHR for the cookie. I believe this has been fixed in newer versions.