Skip to content

Set Expiry Date for JWT Tokens to Improve Security #275

Open

Description

@mkrenzke

The Problem:

I've noticed that the JWT generated in auth/__init__.py#L31 does not have an expiration date set. In my opinion, this is not a good practice because JWT tokens that never expire pose a security risk. If such a token is lost or exposed, it cannot be revoked server-side, potentially leading to permanent unauthorized access.

The Proposed Solution:

According to RFC 7519, the "exp" claim can be used to specify the token's lifetime. I suggest setting an expiration time to mitigate this risk. Since there is no refresh-token mechanism in place yet, we should choose a balanced expiration time - not too short to disrupt user experience, but not too long for security reasons. I recommend starting with an 8-hour validity period.

Suggested Changes:

  • Set the "exp" claim when generating the JWT, with a default lifespan of 8 hours.
  • Validate the expiration date when decoding the JWT to ensure expired tokens are rejected.

Would love to hear any thoughts or alternative suggestions!

Activity

  1. b-rowan commented on Mar 21, 2025

    @b-rowan
    Member

    I think the long term solution to this is a user settings page where this can be set up, and other settings can be modified by users with sufficient access. I think it's also maybe not a bad idea to set up an api.foo.bar style permission, where users could use paths of the API only with the correct permissions.

  2. mkrenzke commented on Mar 21, 2025

    @mkrenzke
    Author

    That makes sense as a long-term solution! A user settings page where expiration times (and potentially other security-related settings) can be configured would definitely provide more flexibility.

    That said, I think setting a default expiration time now is still a necessary security improvement. Even if we later allow customization, having a reasonable default (e.g., 8 hours) ensures we don't have indefinitely valid tokens in the meantime.

    I also like the idea of API path-based permissions - it could add an extra layer of control. Maybe that’s something we could explore in a separate issue?

  3. b-rowan commented on Mar 24, 2025

    @b-rowan
    Member

    Not a direct fix yet, but once the PR for the related issue is merged we may be able to create a "per-user" settings page where they can manage their API tokens.

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