Skip to content

Why doesn't this module store the raw session ID in the cookie directly? #176

@bookercodes

Description

@bookercodes

I am posting in relation to this Information Security question that reads:

I am learning about session middleware.

You have to supply a secret or 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 secret is.

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions