- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我通过使用 iisnode 将 Node 与 IIS 一起使用我在设置 CookieSession 选项 secure:true
时遇到问题。
我在 IIS 上使用 HTTPS,并将任何 HTTP 重定向到 HTTPS。但即便如此,如果我设置 CookieSession选项secure:true
,登录后 session 将没有任何内容。
secure: a boolean indicating whether the cookie is only to be sent over HTTPS (false by default for HTTP, true by default for HTTPS).
我不得不使用 secure:false
来让它工作。这是为什么?
最佳答案
原因
iisnode 将来自 IIS 的请求代理到运行 express 的 Node 应用程序。 SSL 连接在 IIS 处终止,您的 Node 应用程序收到一个 http 请求。当应用程序需要通过安全连接使用 cookie 时,cookieSession和 express-session不会设置 cookie。
决议
当 x-forwarded-proto
header 设置为“https”时,您需要告诉 Express 它可以信任代理。
你可以通过添加代理来做到这一点:真正的配置
app.use(express.session({
proxy : true,
secret: 'your-secret-key',
cookie: {
secure: true
}
}));
或者你可以告诉 Express 全局信任代理:
app.set('trust proxy', 1)
同时在您的 web.config 中将 enableXFF
设置为 true。它使 iisnode 将 x-forwarded-proto
(和 x-forwarded-for
)请求 header 添加到 express 应用程序。
<configuration>
<system.webServer>
<!-- ... -->
<iisnode enableXFF="true" />
</system.webServer>
</configuration>
先决条件
iisnode 至少需要版本 0.2.11 才能让 enableXFF
配置添加 x-forwarded-proto
请求 HTTP header 。您可以通过查看可能安装在 C:\Program Files\iisnode
中的 iisnode.dll
文件的属性来检查您拥有的 iisnode 版本。如果它是 < 0.2.11,只需从任何下载链接下载最新版本 here .安装后它会告诉你需要重启服务器。我可以告诉您,iisreset
命令(在提升的 cmd 框中)就足够了。
关于node.js - 使用 iisnode 时保护 CookieSession,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33871133/
在我的 node.js 服务器上(运行 express 和 socket.io),当有人连接时,我将他们添加到一个数组中并保存他们在数组中的位置进入他们的 session ,这样每个连接都可以访问他们
我对 session 有很好的基本了解。 有 2 个选项可以将 session 与 Express 和 Node.js 结合使用。 express.session express.cookieSess
cookieSession和express中的cookie有什么区别? 最佳答案 cookieParser middleware解析 HTTP Cookie: header 以填充 req.cooki
我通过使用 iisnode 将 Node 与 IIS 一起使用我在设置 CookieSession 选项 secure:true 时遇到问题。 我在 IIS 上使用 HTTPS,并将任何 HTTP 重
cookieParser() 为我们提供了使用密文对 cookie 进行签名的选项,这对于防止篡改非常有用。我知道 cookie 是用特殊值签名的,以防止篡改。 我刚刚发现 cookieSession
我正在尝试使用 connect 的内置 cookieSession 对象,但我无法让它与 express 一起正常工作。 我有这个应用程序: var express = require('expres
我正在尝试解决访问 socket.io 中的 session 变量的臭名昭著的问题。我基本上已经阅读了 Google 上有关该主题的所有链接,但我仍然在苦苦挣扎。 在我完成所有路由之后,我有这个: i
** 已解决 ** 我已经为这个问题苦苦挣扎了一段时间。那里有很多类似的帖子,但所提出的解决方案都不适合我。 我正在使用带有 cookie session 的 Express 和 Passport。当
我正在使用 cookieSession 尝试使用未经身份验证的用户的 cookie 填充 req.session 对象。但是,在向 cookieSession 传递一个 key 后,req.sessi
我正在研究 facebook 授权,发现护照不能与 cookieSession() 一起使用,只能与 session() 一起使用。在第一种情况下,req.user 始终未定义。有可能让它发挥作用吗?
我想在 Passport 中使用 cookie session 存储,因为内存存储不是为生产而设计的: Warning: connection.session() MemoryStore is not
我正在使用socket.io的authorize方法(详细来说here)通过检查与用户关联的cookie来检查用户是否有权使用我的应用程序。 上面的博客文章相当简单,但我使用 cookieSessio
我正在使用 Connect 的 cookieSession() 设置 cookie。这似乎加密了 cookie 的 secret 值,返回类似 's:j:{}.8gxCu7lVJHVs1gYRPFDA
website没有为使用 app.use(express.cookieSession()); 指定任何“ secret ”要求,但是当在 express 中使用相同内容时,它要求“需要 secret
有两个与 session 相关的中间件与 Connect/Express 捆绑在一起。有什么区别?我该如何选择? 我假设 session中间件同cookieSession中间件,但具有额外的存储机制。
我正在尝试使用 Connect/Express cookieSession() 将我的 node.js session 存储在 cookie 中(从而避免服务器端 session 存储)。这将帮助我在
创建新用户帐户时,我创建 newUser,这是一个 Mongoose 模型实例,如下所示: _events: Object errors: undefined isNew: false save: f
创建新用户帐户时,我会创建 newUser,它是一个 Mongoose 模型实例,如下所示: _events: Object errors: undefined isNew: false save:
我是一名优秀的程序员,十分优秀!