【发布时间】:2014-06-27 15:21:27
【问题描述】:
假设我已经在域boo.com 中授权并拥有此会话:
s:x2GYrvxGgmsfFwx7gDbKXmwB.4BDXLpMaSqD9hgeTkBDx3z4TeczJeC50gnrH5bc+kWU
我想要的是将脚本标签添加到域foo.com,指向boo.com:
<script src='http://boo.com/blah.js'></script>
在包括 Safari 和 Google Chrome 在内的所有浏览器中,脚本标签在 HTTP 标头中设置 cookie 值,但在 Firefox 中不起作用。
Firefox 没有设置 cookie 标头,所以我从服务器收到 Unauthorized 错误。问题是什么?
更新:
我在服务器端启用了 CORS,但问题在 Firefox 中仍然存在:
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', 'http://foo.com');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'Cookie');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
【问题讨论】:
-
我重现了你描述的情况,但是could not reproduce the problem。
-
@Quentin 我能知道你的 Firefox 版本吗?
-
@Quentin 你能告诉我你的 Firefox 的
network.cookie.thirdparty.sessionOnly值吗?是true还是false? -
它是
false,但这是默认值。虽然 cookie 是一个会话 cookie,所以要求会话 cookie 不会有什么不同。 -
@Quentin 在我的情况下这是一个会话 cookie。好,谢谢。请让我知道用屏幕截图更新问题。
标签: javascript firefox cookies cross-domain