7

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}
}));

So any suggestion for setting HttpOnly Flag in express.js is most welcome.

MSU_Bulldog
  • 3,503
  • 5
  • 35
  • 73
arjun kori
  • 1,010
  • 2
  • 14
  • 32

1 Answers1

7

I think you could try this!

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
}));
Wayne Chiu
  • 5,265
  • 2
  • 19
  • 18
  • i already got my answer chao,httpOnly works on server when we deploy the code. – arjun kori Sep 30 '16 at 13:28
  • 1
    This answer is wrong -- that's how you use sessions but does not answer the actual question of how to set the flag -- sessions don't work on lambda for example. – SebastianG Aug 23 '19 at 10:07