Skip to content

Set Expiry Date for JWT Tokens to Improve Security #275

@mkrenzke

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!

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