-
Notifications
You must be signed in to change notification settings - Fork 385
Labels
apiRelates to the Modrinth API for developersRelates to the Modrinth API for developersbackendInvolves work from the backend teamInvolves work from the backend team
Description
Please confirm the following.
- I checked the existing issues for duplicate problems
- I have tried resolving the issue using the support portal
Describe the bug
Sessions expire after 14 days (DB default), but a refresh mechanism exists with a 60-day window. This refresh endpoint is broken, because it attempts to fetch the user data from the session token, but this attempt fails due to session expiry.
This results in every 14 days, you're signed out.
If the original intention was that sessions should be refreshed when the session is still in-date. The fault is the frontend, which only attempts to refresh the session when a fetch has failed.
Code analysis
- When issuing a new session, the DB defaults are used for
expiresandsession_expires, which are 14 days and 60 days respectively (session_item.rs#L37, 20230628180115_kill-ory.sql) - The frontend calls
/session/refreshinevitably when the 14-day window ends - The route handler attempts to get the user information from the Authorization header (the mra token) using
get_user_with_headers - This call fails, because
get_user_record_from_bearer_tokenfails, as it checks if the session has expired - Session refresh is never successful. User is forced to sign back in and generate a new session.
Additional observations
- Even if the refresh was successful and a new session is issued. The
refresh_expiresis issued with the same database default of 60 days fromCURRENT_TIMESTAMP. This effectively makes this refresh expiry pointless, as it is always reset. Instead, therefresh_expiresof the new session should match that of the old session.
I am completely happy to, and in fact would love to, contribute this fix myself via a PR. Please let me know if that is something you would accept!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
apiRelates to the Modrinth API for developersRelates to the Modrinth API for developersbackendInvolves work from the backend teamInvolves work from the backend team