node.js客户端 - 大型无法盖的字符串



我有一个node.js web服务器,并将会话cookie牢固地存储在我使用的客户端的客户端上。

要设置cookie,可以设置一些属性,例如cookiename和一个秘密,"应该是一个大的弦乐"。但是,该字符串应该如何,如何创建这样的字符串,并在程序中正确使用它?使用环境变量或从文件中读取它?

在启动时使用随机字符串在我眼中不是很聪明,因为如果网络服务器崩溃,则它会创建一个新的秘密,并且无法阅读所有先前发行的cookies,我对吗?

app.use(sessions({
  cookieName: 'mySession', // cookie name dictates the key name added to the request object
  secret: 'blargadeeblargblarg', // should be a large unguessable string
  duration: 24 * 60 * 60 * 1000, // how long the session will stay valid in ms
  activeDuration: 1000 * 60 * 5 // if expiresIn < activeDuration, the session will be extended by activeDuration milliseconds
}));

我将生成UUID或使用密码管理程序来生成大型随机字符串。然后将其存储在系统环境变量中,以使其在您的代码中不进行。

最新更新