Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'get_encoded':function(data) {
var pickled = JSON.stringify(data),
md5 = crypto.createHash('md5').update(pickled + settings.SECRET_KEY).digest('hex'),
result = new Buffer(pickled + md5, 'utf8').toString('base64');
return result;
},
'get_decoded':function() {
SessionStore.prototype.encode = function(data) {
var pickled = JSON.stringify(data),
md5 = crypto.createHash('md5').update(pickled + settings.SECRET_KEY).digest('hex'),
result = new Buffer(pickled + md5, 'utf8').toString('base64');
return result;
};
'get_decoded':function() {
var encodedData = (new Buffer(this.session_data, 'base64')).toString('utf8'),
pickled = encodedData.slice(0, -32),
tamperCheck = encodedData.slice(-32),
md5sum = crypto.createHash('md5').update(pickled + settings.SECRET_KEY).digest('hex');
if(md5sum !== tamperCheck) {
throw new Error("User tampered with session cookie.");
} else {
try {
return JSON.parse(pickled);
} catch(err) {
return {};
}
}
}
});
SessionStore.prototype.getNewSessionKey = function() {
return crypto.createHash('md5').update([
random(0, MAX_SESSION_KEY)
, parseInt(new Date())
, settings.SECRET_KEY].join('')).digest('hex');
};