-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Bugfix: when there are multiple secrets, we should re-sign with latest #118
Conversation
Benchmark:
|
0ee908b
to
aaf5a03
Compare
lib/session.js
Outdated
@@ -71,7 +71,7 @@ module.exports = class Session { | |||
|
|||
[addDataToSession] (prevSession) { | |||
for (const key in prevSession) { | |||
if (!['expires', 'cookie'].includes(key)) { | |||
if (!['expires', 'cookie', 'encryptedSessionId'].includes(key)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original PR had this change, which is why this bug came up
Anyway, no point in copying encryptedSessionId
over if we're going to replace it immediately.
aaf5a03
to
8e5b8a0
Compare
this[secretKey] = secret | ||
this[addDataToSession](prevSession) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is extremely unreadable and buried. It caused me a lot of confusion earlier, so I decided to put in the function itself
const plugin = fastifyPlugin(async (fastify, opts) => { | ||
fastify.addHook('onRequest', (request, reply, done) => { | ||
request.sessionStore.set(DEFAULT_SESSION_ID, { | ||
expires: Date.now() + 1000, | ||
sessionId: DEFAULT_SESSION_ID, | ||
cookie: { secure: true, httpOnly: true, path: '/' } | ||
}, done) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly unrelated to the PR. This is unnecessary set-up for this test.
8e5b8a0
to
f5e9205
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please dont merge yet. i want to review this more.
When #125 is merged, the cookie signing will be handled by @fastify/cookie, so we will not need to handled it in @fastify/session again... |
This PR is dependent on:
#120
Only the last commit is relevant for review for now.
Turns out, we were re-signing cookies with the new secret.
Checklist
npm run test
andnpm run benchmark
and the Code of conduct