Your analysis is correct, I can reproduce it.
The problem is caused by this line in the cookieSession (in some context: options.secret is the key passed to cookieSession , req.secret is the key passed to cookieParser ): if you pass both middleware with a secret key, cookieSession assumes that he will find the raw cookie in req.cookies .
But since cookieParser also took the signed cookie (and it was run before cookieSession ), it analyzed the cookie itself (and since the signing keys were the same, it succeeded), saved it in req.signedCookies and deleted it from req.cookies . Regarding cookieSession , cookie is simply not set.
The object you see is the contents of the default session (which is a cookie property in the cookieSession configuration):
app.use(express.cookieSession({ cookie : { // <-- this object ... } });
As for the solution: either use a different key for each middleware, or just pass one of them your secret key, but not both (on the understanding that if you pass it to cookieParser , all your cookies will be signed).
FWIW: I'm not quite sure that this is a real mistake. This is a consequence of using the same signing mechanism for both cookieParser and cookieSession , without distinguishing between cookies signed by one or the other. Although this can be fixed, always checking if the cookie is in req.signedCookies .
source share