Skip to content

Remove session id and encrypted session id round 3#121

Closed
rclmenezes wants to merge 5 commits intofastify:masterfrom
rclmenezes:remove-session-id-and-encrypted-session-id-round-3
Closed

Remove session id and encrypted session id round 3#121
rclmenezes wants to merge 5 commits intofastify:masterfrom
rclmenezes:remove-session-id-and-encrypted-session-id-round-3

Conversation

@rclmenezes
Copy link
Copy Markdown
Contributor

@rclmenezes rclmenezes commented Aug 12, 2022

Replaces: #114

Depends on a few other PRs being merged.

Checklist

@rclmenezes rclmenezes force-pushed the remove-session-id-and-encrypted-session-id-round-3 branch 4 times, most recently from b2b84c3 to 4cca4b9 Compare August 12, 2022 17:42
Comment thread lib/cookie.js
Comment on lines +39 to +43
if (cookieOpts.maxAge) {
return new Date(Date.now() + cookieOpts.maxAge)
}
if (cookieOpts.expires) {
expires = cookieOpts.expires
} else if (cookieOpts.maxAge) {
expires = new Date(Date.now() + cookieOpts.maxAge)
return cookieOpts.expires
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maxAge has priority over expires, according to the docs.

However, because Session was calling touch in its constructor, it was still doing the right behavior.

I removed that touch() because it is unnecessary, so I had to fix this

Comment thread lib/session.js Outdated
Comment on lines +31 to +32
this.sessionId = sessionId
this.encryptedSessionId = cookieSignature.sign(sessionId, secret)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't make a sessionId or encryptedSessionid symbol because fastifySession.ts needs access to it anyway.

Comment thread lib/session.js
Comment thread lib/session.js
Comment on lines +162 to +175
if (prevSession.cookie.expires) {
// Need to parse as Date
restoredCookie.expires = new Date(prevSession.cookie.expires)
}
Copy link
Copy Markdown
Contributor Author

@rclmenezes rclmenezes Aug 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bugfix! Otherwise Session.restore() will set expires, even when it's not set.

I discovered this bug as a result of the new test.

Comment thread test/base.test.js
Comment thread test/base.test.js
request.sessionStore.set(sessionId, {
sessionId,
encryptedSessionId: sessionIdSignedWithOldSecret
test: {}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For accuracy -- sessionId / encryptedSessionId should never be in the session store anymore

Comment thread test/session.test.js
Comment thread test/session.test.js
@rclmenezes rclmenezes force-pushed the remove-session-id-and-encrypted-session-id-round-3 branch from b71415b to 6cac322 Compare August 13, 2022 21:02
@rclmenezes
Copy link
Copy Markdown
Contributor Author

@Uzlopak -- do you want me to fix this up for merging? Or are you still doing other work that you want to merge first?

@Uzlopak
Copy link
Copy Markdown
Contributor

Uzlopak commented Aug 20, 2022

Can you first create a PR which removes the sessionId from the stored session + unit tests?
If that is merged, we can then remove the encryptedSessionId.

There is imho currently no tests for what is actually got stored. So I would really like to have atleast the sessionId issue solved with unit tests. Then we can assess how we can remove the encryptedSessionId issue.

@Uzlopak
Copy link
Copy Markdown
Contributor

Uzlopak commented Aug 22, 2022

@rclmenezes

#52 (comment)

@Uzlopak Uzlopak mentioned this pull request Aug 24, 2022
4 tasks
@rclmenezes rclmenezes closed this Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants