Skip to content

Commit

Permalink
fix(crypto): address insecurities with AEAD AAD data
Browse files Browse the repository at this point in the history
  • Loading branch information
jas- committed Jul 18, 2020
1 parent 1d0c21a commit 5a16684
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 198 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -23,6 +23,7 @@
"url": "https://github.com/jdesboeufs/connect-mongo/issues"
},
"dependencies": {
"kruptein": "^2.1.0",
"mongodb": "^3.1.0"
},
"devDependencies": {
Expand Down
154 changes: 0 additions & 154 deletions src/crypto.js

This file was deleted.

24 changes: 15 additions & 9 deletions src/index.js
Expand Up @@ -71,9 +71,7 @@ module.exports = function(connect) {
/* Use crypto? */
if (options.secret) {
try {
this.Crypto = require('./crypto.js')
this.Crypto.init(options)
delete options.secret
this.Crypto = require('kruptein')(options)
} catch (error) {
throw error
}
Expand Down Expand Up @@ -238,7 +236,15 @@ module.exports = function(connect) {
const tmpSession = this.transformFunctions.unserialize(
session.session
)
session.session = this.Crypto.get(tmpSession)
this.Crypto.get(
this.options.secret,
tmpSession,
(err, session) => {
if (err) throw err

session.session = session
}
)
}
const s = this.transformFunctions.unserialize(session.session)
if (this.options.touchAfter > 0 && session.lastModified) {
Expand All @@ -261,11 +267,11 @@ module.exports = function(connect) {
let s

if (this.Crypto) {
try {
session = this.Crypto.set(session)
} catch (error) {
return withCallback(Promise.reject(error), callback)
}
this.Crypto.set(this.options.secret, session, (err, data) => {
if (err) return withCallback(Promise.reject(err), callback)

session = data
})
}

try {
Expand Down

0 comments on commit 5a16684

Please sign in to comment.