-
Notifications
You must be signed in to change notification settings - Fork 342
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
Existing encrypted v3.2.0 sessions are not decrypted correctly by v4.4.1 (Cannot read property 'expires' of undefined) #420
Comments
@pauldwaite I think we have few options here
|
@pauldwaite if you normalize the encrypted sessions then convert the session manually to ASN.1 using the private function available from the kruptein module... |
Cool cool — so, as I understand it, the issue is caused by 3.2.0's session encryption, which only causes a problem after updating to 4.x, if there are existing sessions encrypted by 3.2.0. On the app I'm working on, I think our other security measures are robust enough, and our user base small enough, that we could disable session encryption for 3.2.0, wait for all encrypted sessions to expire, update to 4.x, then re-enable session encryption; and thus avoid having to write any code to deal with the issue. I totally understand not wanting to add code to 4.x to handle this migration issue. I'm not sure how many people encrypt sessions, and would also need to preserve existing sessions across an update to connect-mongo, maybe it's hardly anyone. It would be great to note this as a known issue in the v4 migration guide though. |
@pauldwaite You could always convert them all... (pseudo code) prior to a go live event. let secret = "squirrel", opts = {};
let mongoose = require('mongoose');
let kruptein = require('kruptein')(opts);
const uri = 'mongodb://localhost';
mongoose.connect(uri);
mongoose.connection.once('open', () => {
console.log(`Connected to ${uri}`);
});
let Schema = mongoose.Schema;
let sessions = new Schema({
id: String,
session: String
});
sessions.aggregate({
$group:{
id: $id,
session: $session
}, function(err, obj) {
if (err) throw err;
// Test obj to ensure we don't mangle valid ASN.1 encoded sessions
if (obj.session.match(/hmac/)) {
// simple fix, hopefully it doesn't need more than this
try {
obj.session = JSON.parse(obj.session);
} catch(e) {
console.log("Unable to parse");
}
// Generate a new value
// this one will be base64 encoded ASN.1 value if using v3.0.0 of the kruptein module
kruptein.set(secret, obj.session, function(e, ct) {
if (e) return e;
obj.session = ct;
});
// Make sure obj.session is ok then save
console.log(obj);
}
}
}) |
Added doc in commit 9c1d0b5 |
I'm submitting a ...
[X] bug report
[ ] feature request
[ ] question about the decisions made in the repository
[ ] question about how to use this project
Summary
Existing encrypted session objects from connect-mongo v3.2.0 remain over-stringified when decrypted by v4.4.1, as described in #393.
Other information
Steps to reproduce:
(Minimal docker-compose project to reproduce the issue: https://github.com/pauldwaite/connect-mongo-issue-420)
Expected behaviour
The session still exists, and works correctly.
Actual behaviour
connect-mongo throws an error:
Additional information
I added a breakpoint in the
get
method in kruptein, and thecipher text
variable started like this:Which I thought looked a bit like the over-stringified session object referred to in issue #393.
The text was updated successfully, but these errors were encountered: