fix: expire authentication tokens#37
Open
moldach wants to merge 1 commit into
Open
Conversation
Add configurable auth token expiration to TokenAuthentication. Tokens expire after 30 days by default, can be disabled with SIMPLE_LOGIN_TOKEN_EXPIRY = None, and integer settings are treated as seconds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add configurable expiration for authentication tokens issued by
simple_login.Tokens now expire after 30 days by default when authenticated through
TokenAuthentication. Projects can customize this with:SIMPLE_LOGIN_TOKEN_EXPIRY = timedelta(...)SIMPLE_LOGIN_TOKEN_EXPIRY = <seconds as int>SIMPLE_LOGIN_TOKEN_EXPIRY = Noneto disable expirationExpired tokens are deleted and rejected with
AuthenticationFailed.Closes #25.
Security relevance
Issue #25 notes that tokens should not have an unlimited lifetime. Enforcing a token TTL reduces the usefulness window of leaked, forgotten, or otherwise exposed credentials and forces periodic re-authentication.
Evidence
The existing
Tokensmodel already storescreated, so expiration can be enforced without a schema migration.Tests
Added unit tests for:
Locally run:
I also attempted to run the Django test command, but full execution is currently blocked in this environment by existing dependency compatibility issues unrelated to this patch:
~/sample_config.inidjango.conf.urls.urlTokens.keyfield clash with the base token modelRisk
Low. The change only affects token authentication. It defaults to expiring old tokens, while projects that need legacy indefinite tokens can explicitly set
SIMPLE_LOGIN_TOKEN_EXPIRY = None.