Skip to content

log users out periodically for security reasons #3737

Closed

Description

@jaeyun0503

Summary

As we were discussing about the design of jwt token's refresh and expiration interval, we found that Texera does not have a security measure to reduce the risk of account hijacking. We want to add a security mechanism to enforce users to re-login periodically to avoid unauthorized access to users' data.

Context

Our current design of the system allows users to have fresh token by setting the token refresh interval to token expiration time - 1, which means that when a user's session is about to end, the browser will invoke the backend to issue a fresh token to keep the user authenticated (PR #3703 ). And when a user is not interacting with Texera for a certain amount of time that exceeds the token expiration time, the token will become invalid and the user will have to login again.
In PR #3731 we are separating the configurable variables and setting the expiration time to be 7 days. But considering security of the system, we should make sure that users should not always be logged in even if they are constantly active on the system -- A mechanism needs to be introduced so that users are periodically logged out no matter of the token's state.

Proposed Mechanism

We decided to implement re-authentication to the system. Many apps use this mechanism to ensure users are not always logged in. For example, Gmail logs users out every few days to let users re-authenticate. We want to use the same mechanism to forcefully log users out when the system hits the re-authentication time interval. Adding this mechanism will make sure that every user is logged out if they hit the re-authentication time, even if their tokens are valid. We came up with two designs:

Design 1

Introduce a new configurable variable to control the re-authentication time interval. The proposed configurable variable is different from the active threshold and token expiration time variables (see PR #3731) and should be added to auth.conf.

Design 2

Remove the token refresh interval. Since the token refresh interval is set to token expiration time - 1, we can simply set the token expiration time to 7 days and remove the token refresh interval. That way users will always need to re-authenticate after 7 days as there is no more token refresh mechanism.

Activity

  1. chenlica commented on Sep 16, 2025

    @chenlica
    Contributor

    Between these two designs, I prefer the first one. Any objections?

  2. aicam commented on Sep 16, 2025

    @aicam
    Contributor

    Between these two designs, I prefer the first one. Any objections?

    I believe Design 1 is redundant

  3. Sentiaus commented on Sep 23, 2025

    @Sentiaus
    Contributor

    Between these two designs, I prefer the first one. Any objections?

    I believe Design 1 is redundant

    I don't think Design 1 is necessarily redundant. If you have users who are constantly active, it would probably be better to keep them logged in, and force a sign out once every 2 weeks to a month for security reasons.

    I do think it's less effective if the token refresh is long. So would probably want to change the refresh to a shorter interval (24 or 48 hours) in this case.

    I do think it's effective if the re-auth is dynamic. For example, with a token refresh of 24 hours, setting admin re-auth to 72 hours, while user re-auth is 168 hours.

    Would be a bit complicated though logic wise, will try to create a pr for design 1.

  4. chenlica commented on Sep 23, 2025

    @chenlica
    Contributor

    @Sentiaus Thanks for the comments. We had an internal discussion about the two designs and came up with a solution. @jaeyun0503 : please chime in with our decision. It will be good for @Sentiaus to verify our decision.

  5. jaeyun0503 commented on Sep 24, 2025

    @jaeyun0503
    ContributorAuthor

    @Sentiaus Thanks for the comments. We had an internal discussion about the two designs and came up with a solution. @jaeyun0503 : please chime in with our decision. It will be good for @Sentiaus to verify our decision.

    Yes. We had an internal discussion on this Issue and we decided to go with Design 2 and use three PRs to address this and Issue #3738:

    1. Keep the token expiration parameter, remove the refresh logic (token expiration time - 1): We wanted to implement design 2 to get rid of the token refresh interval, and use the token expiration parameter to define a user's expiration token interval (the proposed interval is 7 days).
    2. When user talk to backend with an expired token, backend should return 401 and frontend should always clear cache:
    3. (Design not finalized) When frontend talks to the backend (preferably the time it gets the token), ask for the expiration date of the token and set a timer, when the timer expires clear up the frontend cache

    For the context of Bullet points 2 and 3, you can take a look at #3738 as we explained the reason behind the issue.

  6. Sentiaus commented on Sep 24, 2025

    @Sentiaus
    Contributor

    Yes. We had an internal discussion on this Issue and we decided to go with Design 2 and use three PRs to address this and Issue #3738:

    1. Keep the token expiration parameter, remove the refresh logic (token expiration time - 1): We wanted to implement design 2 to get rid of the token refresh interval, and use the token expiration parameter to define a user's expiration token interval (the proposed interval is 7 days).
    2. When user talk to backend with an expired token, backend should return 401 and frontend should always clear cache:
    3. (Design not finalized) When frontend talks to the backend (preferably the time it gets the token), ask for the expiration date of the token and set a timer, when the timer expires clear up the frontend cache

    For the context of Bullet points 2 and 3, you can take a look at #3738 as we explained the reason behind the issue.

    Sounds good! Think the second design sounds better for the scope, and will simplify the approach to PRs 2 and 3.

  7. Sentiaus commented on Sep 24, 2025

    @Sentiaus
    Contributor

    One thing I noticed, is that the logout function in auth.service.ts properly deletes the user token and unsubscribes the expiration time, but does not trigger userChange like the comment says it does.

      /**
       * this method will clear the saved user account and trigger userChangeEvent
       */
      public logout(): undefined {
        AuthService.removeAccessToken();
        this.tokenExpirationSubscription?.unsubscribe();
        return undefined;
      }
    

    Additionally the changeUser function that does exist in user.service.ts does not navigate the user away but actually only happens in user-icon.component.ts:

    /**
       * handle the event when user click on the logout button
       */
      public onClickLogout(): void {
        this.userService.logout();
        document.cookie = "flarum_remember=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
        this.router.navigate([DASHBOARD_ABOUT]);
      }
    

    I believe this is fine, but definitely a negative UX when the user has been signed out due to token expiration, as they are not actually able to tell that they have been signed out.

  8. jaeyun0503 commented on Sep 24, 2025

    @jaeyun0503
    ContributorAuthor

    One thing I noticed, is that the logout function in auth.service.ts properly deletes the user token and unsubscribes the expiration time, but does not trigger userChange like the comment says it does.

      /**
       * this method will clear the saved user account and trigger userChangeEvent
       */
      public logout(): undefined {
        AuthService.removeAccessToken();
        this.tokenExpirationSubscription?.unsubscribe();
        return undefined;
      }
    

    Additionally the changeUser function that does exist in user.service.ts does not navigate the user away but actually only happens in user-icon.component.ts:

    /**
       * handle the event when user click on the logout button
       */
      public onClickLogout(): void {
        this.userService.logout();
        document.cookie = "flarum_remember=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
        this.router.navigate([DASHBOARD_ABOUT]);
      }
    

    I believe this is fine, but definitely a negative UX when the user has been signed out due to token expiration, as they are not actually able to tell that they have been signed out.

    Thanks for the comment. We will take a look into the code and address your comments.

  9. Yicong-Huang commented on Jul 30, 2026

    @Yicong-Huang
    Contributor

    Revisiting this topic, I’m curious about the specific security concern with the refresh-token approach. If a new access token is issued only when the user’s account is still active in the system, wouldn’t this allow us to immediately stop token renewal after the account is disabled or revoked?

    This would preserve long-running sessions for active users while still allowing the system to terminate access centrally when necessary. Is the remaining concern that a stolen refresh token could continue to be used indefinitely as long as the account remains active? If so, could refresh-token rotation, revocation, and an absolute session lifetime address that risk without requiring every user to log in again periodically?

  10. chenlica commented on Aug 2, 2026

    @chenlica
    Contributor

    @Neilk1021 @aglinxinyuan : as you two are extending user authentication, can you revisit this old topic?

  11. aglinxinyuan commented on Aug 2, 2026

    @aglinxinyuan
    Contributor

    @Neilk1021 @aglinxinyuan : as you two are extending user authentication, can you revisit this old topic?

    I think current design is good enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions