Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not possible to set cookie encode option #883

Open
thomasmarr opened this issue Apr 12, 2022 · 1 comment
Open

Not possible to set cookie encode option #883

thomasmarr opened this issue Apr 12, 2022 · 1 comment

Comments

@thomasmarr
Copy link

thomasmarr commented Apr 12, 2022

One of the options which can be set on cookie.serialize is encode see here

In express-session it is not possible to set this option:

  • req.session.cookie = new Cookie(cookieOptions);
  • setcookie(res, name, req.sessionID, secrets[0], req.session.cookie.data);
  • var data = cookie.serialize(name, signed, options);
  • session/session/cookie.js

    Lines 117 to 127 in 5df613c

    get data() {
    return {
    originalMaxAge: this.originalMaxAge
    , expires: this._expires
    , secure: this.secure
    , httpOnly: this.httpOnly
    , domain: this.domain
    , path: this.path
    , sameSite: this.sameSite
    }
    },

I believe express-session should expose this, as the default encodeUriComponent is not always the desired behaviour. I would be willing to try and put a PR together for this if it was likely to be merged promptly.

@FlinthDevs
Copy link

FlinthDevs commented Sep 15, 2023

I agree, in my context, cookies are urlEncoded once more by a mechanism I have no control on and I had to patch the module to allow encode to be modified same as other ones.

diff --git a/node_modules/express-session/session/cookie.js b/node_modules/express-session/session/cookie.js
index a8b4e57..5fa4553 100644
--- a/node_modules/express-session/session/cookie.js
+++ b/node_modules/express-session/session/cookie.js
@@ -73,6 +73,28 @@ Cookie.prototype = {
     return this._expires;
   },
   
+  /**
+  * Set encode `callback`.
+  *
+  * @param {CallableFunction} callback
+  * @api public
+  */
+
+ set encode(callback) {
+   this.callback = callback;
+ },
+
+ /**
+  * Get encode `callback`.
+  *
+  * @return {CallableFunction} callback
+  * @api public
+  */
+
+ get encode() {
+   return this.callback;
+ },
+
   /**
    * Set expires via max-age in `ms`.
    *
@@ -123,6 +145,7 @@ Cookie.prototype = {
       , domain: this.domain
       , path: this.path
       , sameSite: this.sameSite
+      , encode: this.callback
     }
   },
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants