-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: extendSessionOnUse
to automatically renew Parse Sessions
#8505
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
Conversation
Thanks for opening this pull request! |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## alpha #8505 +/- ##
==========================================
- Coverage 94.31% 94.31% -0.01%
==========================================
Files 183 183
Lines 14520 14547 +27
==========================================
+ Hits 13695 13720 +25
- Misses 825 827 +2
☔ View full report in Codecov by Sentry. |
Thanks @dblythy for looking into this, Parse Server has been really missing this functionality. Looking at the code it is pretty clear, however from the test case I am not sure what is expected to happen when you use expired sessionToken? The test is written in a way that your session expires |
No client side changes happen here, and if expiresAt is in the past, invalid session token will still return. The change is that using a valid token changes its expiry. The test is just a way to edit the raw session object to emulate a valid token that hasn't expired but hasn't been used in a while (updatedAt). The session expiring now was just to check that the new expiry was updated. The test didn't fail with "invalid session token" because the session tokens are cached for a short period. |
Thanks @dblythy for addressing my question. The test code now makes it clear that expired token should 209, while valid token will extend. I had very similar implementation in my mind as well. |
It seems that all Postgres jobs fail with:
|
renewSessions
to automatically renew Parse SessionsextendSessionOnUse
to automatically renew Parse Sessions
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.
Looks good!
# [6.1.0-alpha.11](6.1.0-alpha.10...6.1.0-alpha.11) (2023-05-17) ### Features * `extendSessionOnUse` to automatically renew Parse Sessions ([#8505](#8505)) ([6f885d3](6f885d3))
🎉 This change has been released in version 6.1.0-alpha.11 |
# [6.3.0-beta.1](6.2.0...6.3.0-beta.1) (2023-06-10) ### Bug Fixes * Cloud Code Trigger `afterSave` executes even if not set ([#8520](#8520)) ([afd0515](afd0515)) * GridFS file storage doesn't work with certain `enableSchemaHooks` settings ([#8467](#8467)) ([d4cda4b](d4cda4b)) * Inaccurate table total row count for PostgreSQL ([#8511](#8511)) ([0823a02](0823a02)) * LiveQuery server is not shut down properly when `handleShutdown` is called ([#8491](#8491)) ([967700b](967700b)) * Rate limit feature is incompatible with Node 14 ([#8578](#8578)) ([f911f2c](f911f2c)) * Unnecessary log entries by `extendSessionOnUse` ([#8562](#8562)) ([fd6a007](fd6a007)) ### Features * `extendSessionOnUse` to automatically renew Parse Sessions ([#8505](#8505)) ([6f885d3](6f885d3)) * Add new Parse Server option `preventSignupWithUnverifiedEmail` to prevent returning a user without session token on sign-up with unverified email address ([#8451](#8451)) ([82da308](82da308)) * Add option to change the log level of logs emitted by Cloud Functions ([#8530](#8530)) ([2caea31](2caea31)) * Add support for `$eq` query constraint in LiveQuery ([#8614](#8614)) ([656d673](656d673)) * Add zones for rate limiting by `ip`, `user`, `session`, `global` ([#8508](#8508)) ([03fba97](03fba97)) * Allow `Parse.Object` pointers in Cloud Code arguments ([#8490](#8490)) ([28aeda3](28aeda3)) ### Reverts * fix: Inaccurate table total row count for PostgreSQL ([6722110](6722110))
🎉 This change has been released in version 6.3.0-beta.1 |
# [6.3.0-alpha.1](6.2.0...6.3.0-alpha.1) (2023-06-18) ### Bug Fixes * Cloud Code Trigger `afterSave` executes even if not set ([#8520](#8520)) ([afd0515](afd0515)) * GridFS file storage doesn't work with certain `enableSchemaHooks` settings ([#8467](#8467)) ([d4cda4b](d4cda4b)) * Inaccurate table total row count for PostgreSQL ([#8511](#8511)) ([0823a02](0823a02)) * LiveQuery server is not shut down properly when `handleShutdown` is called ([#8491](#8491)) ([967700b](967700b)) * Rate limit feature is incompatible with Node 14 ([#8578](#8578)) ([f911f2c](f911f2c)) * Unnecessary log entries by `extendSessionOnUse` ([#8562](#8562)) ([fd6a007](fd6a007)) ### Features * `extendSessionOnUse` to automatically renew Parse Sessions ([#8505](#8505)) ([6f885d3](6f885d3)) * Add new Parse Server option `preventSignupWithUnverifiedEmail` to prevent returning a user without session token on sign-up with unverified email address ([#8451](#8451)) ([82da308](82da308)) * Add option to change the log level of logs emitted by Cloud Functions ([#8530](#8530)) ([2caea31](2caea31)) * Add support for `$eq` query constraint in LiveQuery ([#8614](#8614)) ([656d673](656d673)) * Add zones for rate limiting by `ip`, `user`, `session`, `global` ([#8508](#8508)) ([03fba97](03fba97)) * Allow `Parse.Object` pointers in Cloud Code arguments ([#8490](#8490)) ([28aeda3](28aeda3)) ### Reverts * fix: Inaccurate table total row count for PostgreSQL ([6722110](6722110))
🎉 This change has been released in version 6.3.0-alpha.1 |
{ sessionToken }, | ||
{ limit: 1 } | ||
).execute(); | ||
console.log({ results }); |
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.
console.log() here
return; | ||
} | ||
clearTimeout(throttle[sessionToken]); | ||
throttle[sessionToken] = setTimeout(async () => { |
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.
throttle seems to be a simple object never cleared, and it's not an LRU, memory is exposed to DDOS issues (since it seems that every token will be stored in memory), and the memory will grow infinitely
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 checked also clearTimeout function do not unset in the record on the throttle object. So the timeout instance is cancelled but still there in memory
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.
Good point, I’ll open a new issue and fix
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 checked also clearTimeout function do not unset in the record on the throttle object. So the timeout instance is cancelled but still there in memory
Hi there, i was just reviewing this feature from a merge on my fork. I just want to add a comment to help may be other developers landing here, if i understand correctly the system here: Context:
User:
Limitations:
Security concerns:
Suggested futur improvements:
Some doc from Internet Task Force: https://mailarchive.ietf.org/arch/msg/oauth/vSmJ0zjQzZFjeFbRz_qpvjfpAeU/ |
Btw @dblythy , this feature is okay, and it will help many developers to have shorter session length, but we should not advertise this feature as a true renewal mechanism. I think the issue should be reopened waiting a proper PR with a full Oauth2 mechanism using refresh tokens. What do you think ? |
Hmmm, perhaps we should try to have full JWT support for Parse Server 7 |
i think a new Oauth 2 standard system with token renewal, access token and refresh token seems a good idea :) But it need also a important amount of work i think @dblythy |
I agree that JWT support would be nice. Should we open a new issue and put a bounty on it? I'd like to throw in that, a self-extending token comes with similar risks as a long-living token. So this feature bears a similar risk as setting the option
I don't think that has been the premise or that it's being promoted as such (it's off by default). It's a feature that may have its use cases in certain applications, just like a long-living session. There may be clients who do not support a refresh token mechanism (IoT). For them it may be more secure to have a session token that expires after not using it for a while than issuing a session token that never expires. I can also imagine that this feature be extended in the future to conditionally extend the session, allowing for even more use cases. In any case, I wouldn't swap a refresh token mechanism for the current extend session feature, just like we don't limit the max session length a developer can set. We have the API docs and a Best Practice section in the docs to add any supplementary warning note about the implications of setting Parse Server options, so these can always be amended if we feel something is underdocumented. |
btw don't forget about refresh token rotation :) |
@formatCvt Could you open a new issue for adding JWT with refresh token and add your comment? This PR is closed and related to a different solution and won't be tracked. |
# [6.3.0](6.2.2...6.3.0) (2023-09-16) ### Bug Fixes * Cloud Code Trigger `afterSave` executes even if not set ([#8520](#8520)) ([afd0515](afd0515)) * GridFS file storage doesn't work with certain `enableSchemaHooks` settings ([#8467](#8467)) ([d4cda4b](d4cda4b)) * Inaccurate table total row count for PostgreSQL ([#8511](#8511)) ([0823a02](0823a02)) * LiveQuery server is not shut down properly when `handleShutdown` is called ([#8491](#8491)) ([967700b](967700b)) * Rate limit feature is incompatible with Node 14 ([#8578](#8578)) ([f911f2c](f911f2c)) * Unnecessary log entries by `extendSessionOnUse` ([#8562](#8562)) ([fd6a007](fd6a007)) ### Features * `extendSessionOnUse` to automatically renew Parse Sessions ([#8505](#8505)) ([6f885d3](6f885d3)) * Add new Parse Server option `preventSignupWithUnverifiedEmail` to prevent returning a user without session token on sign-up with unverified email address ([#8451](#8451)) ([82da308](82da308)) * Add option to change the log level of logs emitted by Cloud Functions ([#8530](#8530)) ([2caea31](2caea31)) * Add support for `$eq` query constraint in LiveQuery ([#8614](#8614)) ([656d673](656d673)) * Add zones for rate limiting by `ip`, `user`, `session`, `global` ([#8508](#8508)) ([03fba97](03fba97)) * Allow `Parse.Object` pointers in Cloud Code arguments ([#8490](#8490)) ([28aeda3](28aeda3)) ### Reverts * fix: Inaccurate table total row count for PostgreSQL ([6722110](6722110))
🎉 This change has been released in version 6.3.0 |
@mtrezza I don't understand how this feature works.
But looking at this piece of code it takes lastUpdated and yesterday and if lastUpdated is greater than yesterday it returns. So if I've doing 60 minute sessions, well this will never actually extend the session. So for this to work a session needs to be at least 24 hours. This isn't documented anywhere and it's counterintuitive. Am I missing something. |
Not sure why this is not simply comparing the date timestamp. Looks odd. Would you open an issue? It seems, the fix could be quite simple as well by comparing the dates instead of introducing a |
Pull Request
Issue
Currently, there is no mechanism to renew sessions. Expires at is immutable.
Closes: #7248
Approach
Introduces a server parameter
renewSessions
. This feature will extend the session expiry date to thesessionLength
when the session is used by a client.With this feature,
sessionLength
is more or less the "inactive period", rather than a flat expiry date. This could allow for a lower defaultsessionLength
instead of 1 year.Tasks