-
-
Notifications
You must be signed in to change notification settings - Fork 994
Description
I am posting in relation to this Information Security question that reads:
I am learning about session middleware.
You have to supply a
secretor the middleware complains:app.use(session({ secret: "abc", resave: false, saveUninitialized: false, store: new MongoStore({ mongooseConnection: mongoose.connection }) }));I did some investigation and the actual session ID is
eKeYlF1DR6AtVkeFZK9vEIHSZT8e0jqZ
But according to the cookie, the session ID is
s%3AeKeYlF1DR6AtVkeFZK9vEIHSZT8e0jqZ.on5ifVE079C4ctKNdkNiJSh8NkQMckjd5fn%2FsxIQWCk
I am confused. Why is it insecure to store the session ID in the cookie directly?
As I understand it, if an attacker can attain this cookie, maybe via XSS or social engineering, the attacker can still hijack the session. I am not sure what the point of the
secretis.
An authoritative member commented on this question:
Hi, welcome to Information Security. I'm not sure what makes you think that it is at all insecure to store the user's sessionid in his cookie (as long as you do it right). From what I can tell, you found that some halfbaked js library does something unintuitive. That doesn't mean it is insecure, or that that is the reason for it. You shouldn't be surprised if this is a halfbaked idea...
There is even more context in the comments of this answer.
Can someone here please shed some light on the issue?
Many thanks.