From 663391ef50692f384bd4067960c077725de4c19f Mon Sep 17 00:00:00 2001 From: Steve Cassidy Date: Mon, 20 May 2024 21:41:44 +1000 Subject: [PATCH 1/2] remove debug output Signed-off-by: Steve Cassidy --- src/couchdb/notebooks.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/couchdb/notebooks.ts b/src/couchdb/notebooks.ts index 919bad05..c4ba08e8 100644 --- a/src/couchdb/notebooks.ts +++ b/src/couchdb/notebooks.ts @@ -846,7 +846,6 @@ export const streamNotebookFilesAsZip = async ( } const stream = Stream.Readable.from(chunks); const filename = generateFilename(file, key, hrid, fileNames); - console.log('adding to zip: ', filename); fileNames.push(filename); await archive.append(stream, { name: filename, From fee26d4a7dac520e262d03e8c051d0529f879a6a Mon Sep 17 00:00:00 2001 From: Steve Cassidy Date: Mon, 20 May 2024 22:11:49 +1000 Subject: [PATCH 2/2] upgrade passport to 0.7.0 and add fix for cookie-session Signed-off-by: Steve Cassidy --- package-lock.json | 34 ++++++++++++++++++---------------- package.json | 4 ++-- src/core.ts | 19 +++++++++++++++++++ src/routes.ts | 8 ++++++-- 4 files changed, 45 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index 21d73a21..72577578 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,7 @@ "nodemailer": "^6.9.9", "nyc": "^15.1.0", "oauth": "0.10.0", - "passport": "0.5.3", + "passport": "^0.7.0", "passport-google-oauth20": "2.0.0", "passport-local": "^1.0.0", "passport-oauth2": "1.7.0", @@ -56,7 +56,7 @@ "@types/multer": "^1.4.7", "@types/node": "20.11.19", "@types/nodemailer": "^6.4.13", - "@types/passport": "1.0.7", + "@types/passport": "^1.0.16", "@types/passport-google-oauth20": "2.0.13", "@types/passport-local": "^1.0.35", "@types/passport-oauth2": "1.4.15", @@ -1667,9 +1667,9 @@ } }, "node_modules/@types/passport": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/@types/passport/-/passport-1.0.7.tgz", - "integrity": "sha512-JtswU8N3kxBYgo+n9of7C97YQBT+AYPP2aBfNGTzABqPAZnK/WOAaKfh3XesUYMZRrXFuoPc2Hv0/G/nQFveHw==", + "version": "1.0.16", + "resolved": "https://registry.npmjs.org/@types/passport/-/passport-1.0.16.tgz", + "integrity": "sha512-FD0qD5hbPWQzaM0wHUnJ/T0BBCJBxCeemtnCwc/ThhTg3x9jfrAcRUmj5Dopza+MfFS9acTe3wk7rcVnRIp/0A==", "dev": true, "dependencies": { "@types/express": "*" @@ -8476,12 +8476,13 @@ } }, "node_modules/passport": { - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/passport/-/passport-0.5.3.tgz", - "integrity": "sha512-gGc+70h4gGdBWNsR3FuV3byLDY6KBTJAIExGFXTpQaYfbbcHCBlRRKx7RBQSpqEqc5Hh2qVzRs7ssvSfOpkUEA==", + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/passport/-/passport-0.7.0.tgz", + "integrity": "sha512-cPLl+qZpSc+ireUvt+IzqbED1cHHkDoVYMo30jbJIdOOjQ1MQYZBPiNvmi8UM6lJuOpTPXJGZQk0DtC4y61MYQ==", "dependencies": { "passport-strategy": "1.x.x", - "pause": "0.0.1" + "pause": "0.0.1", + "utils-merge": "^1.0.1" }, "engines": { "node": ">= 0.4.0" @@ -12670,9 +12671,9 @@ } }, "@types/passport": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/@types/passport/-/passport-1.0.7.tgz", - "integrity": "sha512-JtswU8N3kxBYgo+n9of7C97YQBT+AYPP2aBfNGTzABqPAZnK/WOAaKfh3XesUYMZRrXFuoPc2Hv0/G/nQFveHw==", + "version": "1.0.16", + "resolved": "https://registry.npmjs.org/@types/passport/-/passport-1.0.16.tgz", + "integrity": "sha512-FD0qD5hbPWQzaM0wHUnJ/T0BBCJBxCeemtnCwc/ThhTg3x9jfrAcRUmj5Dopza+MfFS9acTe3wk7rcVnRIp/0A==", "dev": true, "requires": { "@types/express": "*" @@ -17761,12 +17762,13 @@ "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" }, "passport": { - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/passport/-/passport-0.5.3.tgz", - "integrity": "sha512-gGc+70h4gGdBWNsR3FuV3byLDY6KBTJAIExGFXTpQaYfbbcHCBlRRKx7RBQSpqEqc5Hh2qVzRs7ssvSfOpkUEA==", + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/passport/-/passport-0.7.0.tgz", + "integrity": "sha512-cPLl+qZpSc+ireUvt+IzqbED1cHHkDoVYMo30jbJIdOOjQ1MQYZBPiNvmi8UM6lJuOpTPXJGZQk0DtC4y61MYQ==", "requires": { "passport-strategy": "1.x.x", - "pause": "0.0.1" + "pause": "0.0.1", + "utils-merge": "^1.0.1" } }, "passport-google-oauth20": { diff --git a/package.json b/package.json index ce41233f..7980eaa8 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "nodemailer": "^6.9.9", "nyc": "^15.1.0", "oauth": "0.10.0", - "passport": "0.5.3", + "passport": "^0.7.0", "passport-google-oauth20": "2.0.0", "passport-local": "^1.0.0", "passport-oauth2": "1.7.0", @@ -67,7 +67,7 @@ "@types/multer": "^1.4.7", "@types/node": "20.11.19", "@types/nodemailer": "^6.4.13", - "@types/passport": "1.0.7", + "@types/passport": "^1.0.16", "@types/passport-google-oauth20": "2.0.13", "@types/passport-local": "^1.0.35", "@types/passport-oauth2": "1.4.15", diff --git a/src/core.ts b/src/core.ts index 87d2bcb1..4de05b3e 100644 --- a/src/core.ts +++ b/src/core.ts @@ -71,6 +71,25 @@ app.use( maxAge: 24 * 60 * 60 * 1000 * 365, // BBS 20220831 changed to 1 year }) ); +// https://github.com/jaredhanson/passport/issues/904 +// register regenerate & save after the cookieSession middleware initialization +// fix for bug in passport 0.7.0 and compatibility with cookie-session +app.use((request, response, next) => { + if (request.session && !request.session.regenerate) { + request.session.regenerate = cb => { + if (cb) cb(''); + return request.session; + }; + } + if (request.session && !request.session.save) { + request.session.save = cb => { + if (cb) cb(''); + return request.session; + }; + } + next(); +}); + app.use(express.urlencoded({extended: true})); // allow large JSON objects to be posted app.use(express.json({limit: '200mb'})); diff --git a/src/routes.ts b/src/routes.ts index e29f4524..474afa4d 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -233,9 +233,13 @@ app.get('/', async (req, res) => { } }); -app.get('/logout/', (req, res) => { +app.get('/logout/', (req, res, next) => { if (req.user) { - req.logout(); + req.logout(err => { + if (err) { + return next(err); + } + }); } res.redirect('/'); });