Skip to content

The capability to supply a serializer (parse, stringify) for the req.sessionID in setcookie & getcookie (due to privacy & security concerns) #468

Open
@pascalvree

Description

@pascalvree

Due to privacy/security concerns, we have to encrypt the sessionID that's stored within a cookie. It would be great, if we could set a cookie value/sessionID serializer within the session options so we can keep using your excellent module. I am aware of the reasons for 'signing' a cookie values and being able to 'encrypt' the sessionID should not replace 'signing' the cookie. It should be in addition to 'signing' the cookie value.

If I would supply you with a pullrequest (from a fork) that implements the following change, the option to supply your own sessionID/value serializer using options.serializer; would you be willing to consider it?

   function session(options) {
      var opts = options || {};

      // get/set the cookie value serializer
      var serializer = opts.serializer || { parse: value => value, stringify: value => value };
      ...
   }

   // set cookie
   setcookie(res, name, serializer.stringify(req.sessionID), secrets[0], req.session.cookie.data);

   function getcookie(req, name, secrets) {
     ...
     return serializer.parse(val);
   }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions