How to set HttpOnly flag In Node.js ,Express.js application?

arj*_*ori 7 javascript node.js express

Hi I have a project in node.js and I want to set the HttpOnly flag: true for header response.

I have written the following code in app.js but it make no effect in response header .

app.use(session({
 secret: "notagoodsecretnoreallydontusethisone",
 resave: false,
 saveUninitialized: true,
 cookie: {httpOnly: true, secure: true}
}));
Run Code Online (Sandbox Code Playgroud)

因此,对于设置任何建议的HttpOnly标志express.js深受欢迎。

Way*_*hiu 7

我想你可以试试这个!

app.use(session({
   cookieName: 'sessionName',
   secret: "notagoodsecretnoreallydontusethisone",
   resave: false,
   saveUninitialized: true,
   httpOnly: true,  // dont let browser javascript access cookie ever
   secure: true, // only use cookie over https
   ephemeral: true // delete this cookie while browser close
}));
Run Code Online (Sandbox Code Playgroud)

  • 这个答案是错误的——这就是你使用会话的方式,但没有回答如何设置标志的实际问题——例如,会话不适用于 lambda。 (2认同)