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

Proof of concept for #614 resolving #615

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

skarbovskiy
Copy link

No description provided.

Copy link
Contributor

@dougwilson dougwilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also ideally we can add a test 👍

package.json Outdated Show resolved Hide resolved
@skarbovskiy
Copy link
Author

@dougwilson done

test/session.js Outdated Show resolved Hide resolved
@skarbovskiy
Copy link
Author

@dougwilson

@skarbovskiy
Copy link
Author

anybody?)

@dougwilson
Copy link
Contributor

Sorry, I will take a look today.

@dougwilson
Copy link
Contributor

So I threw this PR into a couple of apps this morning and one of them threw an error. I reduced it down to the following test case:

var express = require('express')
var expressSession = require('./index')

var app = express()

app.use(expressSession({
  saveUninitialized: false,
  secret: 'keyboard cat',
  resave: false
}))

app.get('/', function (req, res) {
  req.session.visitor = new String('username')
  res.end()
})

app.listen(3000)
$ node app.js &
$ curl -i http://127.0.0.1:3000/
TypeError: Data must be a string or a buffer
    at Hash.update (crypto.js:99:16)
    at write (project/node_modules/express-session/node_modules/object-hash/index.js:167:22)
    at Object._string (project/node_modules/express-session/node_modules/object-hash/index.js:301:7)
    at Object._object (project/node_modules/express-session/node_modules/object-hash/index.js:214:30)
    at Object.dispatch (project/node_modules/express-session/node_modules/object-hash/index.js:185:30)
    at project/node_modules/express-session/node_modules/object-hash/index.js:246:18
    at Array.forEach (<anonymous>)
    at Object._object (project/node_modules/express-session/node_modules/object-hash/index.js:242:21)
    at Object.dispatch (project/node_modules/express-session/node_modules/object-hash/index.js:185:30)
    at hash (project/node_modules/express-session/node_modules/object-hash/index.js:128:10)

This same app works in the current versions of express-session, so this would be breaking. I took a look and it seems to really just be a bug in the object-hash module and doesn't seem to be intended to throw like this. We could probably get a fix into object-hash. I can do this if you like, or would you like to to this?

But this now has me a bit worried. I wonder what other types will have this issue?

@skarbovskiy
Copy link
Author

@dougwilson, finally I got my PR fixing this issue merged in object-hash repo.

@skarbovskiy
Copy link
Author

@dougwilson ?)

@dougwilson
Copy link
Contributor

Hi @skarbovskiy I apologize, I thought I responded. I used a fuzzer and found that library has false positives, as in it will falsely think two different objects are the same. Ideally it should never have a false positive, only maybe false negatives. It's always better to accidentally resave the same thing to the database than to accidentally not save an actual change that was made.

Here is a simplified version of two objects that object-hash produces identical hashes for:

> require('object-hash')({a:Buffer.from('foo,string:1:b:buffer:bar'),b:Buffer.from('bar')}, {respectType:false})
'a94b097bcb4e5a3753f871b1bdd4364e5c4b816c'
> require('object-hash')({a:Buffer.from('foo'),b:Buffer.from('bar,string:1:b:buffer:bar')}, {respectType:false})
'a94b097bcb4e5a3753f871b1bdd4364e5c4b816c'

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

Successfully merging this pull request may close these issues.

None yet

2 participants