Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8295371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:33:42+00:00 2026-06-08T14:33:42+00:00

I am setting a cookie using Connect’s cookieSession() . This seems to encrypt the

  • 0

I am setting a cookie using Connect’s cookieSession(). This seems to encrypt the cookie’s secret value, returning something like ‘s:j:{}.8gxCu7lVJHVs1gYRPFDAodK3+qPihh9G3BcXIIoQBhM’

How do I decrypt the cookie’s value?

Example code:

app.use(express.bodyParser());
app.use(express.cookieParser());

app.get('/setcookie', function(req, res, next){
    res.app.use(express.cookieSession({ key: "test", secret: "test" }));
    console.log(req.cookies.test);
    res.end();
});

app.get('/', function(req, res, next){
    console.log(req.cookies.test);
    res.end();
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:33:44+00:00Added an answer on June 8, 2026 at 2:33 pm

    Hmmm… you seem to be a bit confused about the use of cookie sessions.

    1. Your /setcookie path doesn’t set any cookie/session values. To use a cookie session, you need to set some values on req.session, for example req.session.message = "Hi there!" These values are now stored in the cookie.

    2. You can’t res.app.use() in just one callback, the request session won’t work anywhere else this way. To read those cookies in another request, put the app.use(express.cookieSession({ key: "test", secret: "test" })); at the application level.

    Edit: Actually I’ve thought about your res.app.use() call and it could break your app / cause memory to leak by adding more and more middleware layers (cookieSession) to your app, each time someone requests /setcookie. If you want to only add the cookieSession middleware in specific requests, you need to do the following:

    yourParser = express.cookieSession({ key: "test", secret: "test" });
    app.get('/', yourParser, ...);
    app.get('/setcookie', yourParser, ...);
    

    Solution

    This is the actual fixed source:

    app.use(express.bodyParser());
    app.use(express.cookieParser());
    app.use(express.cookieSession({ key: "test", secret: "test" }));
    
    app.get('/setcookie', function(req, res, next){
        req.session.message = "Hellau there";
        res.end();
    });
    

    Now to inspect those values, in app.get('/',...) try this:

    app.get('/', function(req, res, next){
        console.log(req.session); //Yay, this will be available in all requests!
        res.end();
    });
    

    Debugging

    And to answer the question of how to manually decode what’s stored in a cookie, look in connect/lib/middleware/cookieSession.js:

    // cookieParser secret
    if (!options.secret && req.secret) {
      req.session = req.signedCookies[key] || {};
    } else {
      // TODO: refactor
      var rawCookie = req.cookies[key];
      if (rawCookie) {
        var unsigned = utils.parseSignedCookie(rawCookie, secret);
        if (unsigned) {
          var originalHash = crc16(unsigned);
          req.session = utils.parseJSONCookie(unsigned) || {};
        }
      }
    }
    

    It takes req.cookies[key] (basically what you’ve been doing already (req.cookies.test)), pops it into utils.parseSignedCookie and pops that into utils.parseJSONCookie.

    I put your raw cookie string into the utils.js file at the end:

    var signed = exports.parseSignedCookie(
        's:j:{}.8gxCu7lVJHVs1gYRPFDAodK3+qPihh9G3BcXIIoQBhM'
      , 'test');
    var parsed = exports.parseJSONCookie(signed);
    console.log(parsed);
    

    and ran that. Guess what I got:

    {}
    

    Why? Because you never set anything on the req.session object. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My problem is this. I'm setting a cookie using java script, which contains value
i'm setting a cookie using this code: setcookie(Blah,user,time()+86400); i'm then checking that cookie on
I am setting a value in the cookie using JavaScript and getting the contents
I am setting a cookie in jquery like this(works fine and the cookie is
I am getting problem while setting up Session cookie using jersey. is there any
I am using Jquery Cookie but am having difficulty setting and retrieving the info.
I am using aspx and c# for a setting a authentication cookie for a
So this is my first time using cookies and i'm having some trouble setting
I'm seeing something of an oddity when setting a cookie... Action: string cookieName =
I'm using Firefox 3.6.8 for these tests. I'm setting a cookie within the response

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.