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 8807917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:29:13+00:00 2026-06-14T02:29:13+00:00

I have a good start on a technique similar to this in Express 3

  • 0

I have a good start on a technique similar to this in Express 3
http://notjustburritos.tumblr.com/post/22682186189/socket-io-and-express-3

the idea being to let me grab the session object from within a socket.io connection callback, storing sessions via connect-redis in this case.

So, in app.configure we have

var db = require('connect-redis')(express)
....
app.configure(function(){
     ....
     app.use(express.cookieParser(SITE_SECRET));                                                                                                      
     app.use(express.session({ store: new db }));                                   

And in the app code there is

var redis_client = require('redis').createClient()

 io.set('authorization', function(data, accept) {
     if (!data.headers.cookie) {
         return accept('Sesssion cookie required.', false)
     }

     data.cookie = require('cookie').parse(data.headers.cookie);
     /* verify the signature of the session cookie. */
     //data.cookie = require('cookie').parse(data.cookie, SITE_SECRET);
     data.sessionID = data.cookie['connect.sid']

     redis_client.get(data.sessionID, function(err, session) {
         if (err) {
             return accept('Error in session store.', false)
         } else if (!session) {
             return accept('Session not found.', false)
         }
         // success! we're authenticated with a known session.
         data.session = session
         return accept(null, true)
     })
 })

The sessions are being saved to redis, the keys look like this:

redis 127.0.0.1:6379> KEYS *
1) "sess:lpeNPnHmQ2f442rE87Y6X28C"
2) "sess:qsWvzubzparNHNoPyNN/CdVw"

and the values are unencrypted JSON. So far so good.

The cookie header, however, contains something like

{ 'connect.sid': 's:lpeNPnHmQ2f442rE87Y6X28C.obCv2x2NT05ieqkmzHnE0VZKDNnqGkcxeQAEVoeoeiU' }

So now the SessionStore and the connect.sid don’t match, because the signature part (after the .) is stripped from the SessionStore version.

Question is, is is safe to just truncate out the SID part of the cookie (lpeNPnHmQ2f442rE87Y6X28C) and match based on that, or should the signature part be verified? If so, how?

  • 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-14T02:29:16+00:00Added an answer on June 14, 2026 at 2:29 am

    rather than hacking around with private methods and internals of Connect, that were NOT meant to be used this way, this NPM does a good job of wrapping socket.on in a method that pulls in the session, and parses and verifies
    https://github.com/functioncallback/session.socket.io

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

Sidebar

Related Questions

I don't have good idea about where to start. Any way, most of us
I have an idea and maybe you guys can give me a good start
On my research regarding this navigation technique, I've found this post by Nick Harris
I don't understand PHP very well... not good start I know. I'm using http://detectmobilebrowsers.mobi/
I hope you have had a good start into the new year, over the
Anyone have good book / article recommendation for procedural generation of background music? (No
Does JQueryMobile have good support for entering credit card information. Users have a really
Does gwt have (good) support for effects, moving around elements, and resizing them? Are
Can I have good example or code about how to use Ajax Datepicker in
(Let's assume that I have good reasons not to remove my NSAssert() checks in

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.