Repository navigation
fix(auth): delete auth tokens past their expiration date - #66625
Open
SKroman108 wants to merge 1 commit into
Open
SKroman108 wants to merge 1 commit into
SKroman108 wants to merge 1 commit into
Conversation
Tokens with an explicit expiration date are rejected once it has passed, but invalidateOldTokens() only looks at last_activity, so a permanent token with an expiry stays in oc_authtoken and in Devices & sessions for a year. Apps that create short-lived tokens (e.g. Passwords web UI sessions) pile up hundreds of dead entries. Delete them in the hourly clean-up once they expired more than token_auth_expired_token_retention seconds ago (default 7 days). The grace period keeps the existing behaviour that a client still sending an expired token is rejected quietly instead of counting as a failed login. Remote wipe tokens keep their own retention. Fixes nextcloud#61833 Signed-off-by: SKroman108 <138336203+SKroman108@users.noreply.github.com>
SKroman108
requested review from
artonge,
come-nc and
provokateurin
and removed request for
a team
November 14, 2026 23:07
This branch has not been deployed
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
Fixes #61833.
Auth tokens with an explicit
expirestimestamp are rejected byPublicKeyTokenProvider::getToken()once it has passed, butinvalidateOldTokens()only looks atlast_activity. APERMANENT_TOKENwith an expiry therefore stays inoc_authtoken, and in Settings → Security → Devices & sessions, fortoken_auth_token_retention(one year by default).The Passwords app creates such a token for every web UI session. On my instance (Nextcloud 35.0.2) this left 310 "Passwords Session …" entries for one user, all expired. 306 of them expired more than a week ago.
Change
PublicKeyTokenMapper::invalidateExpired(int $expiredBefore)deletes tokens withexpires > 0that expired before the given time. It skipsWIPE_TOKEN, which already has its own retention (token_auth_wipe_token_retention).invalidateOldTokens(), which already runs from the hourly clean-up job, calls it with a grace period from the new system configtoken_auth_expired_token_retention(default 7 days). The grace period keeps the current behaviour fromSession::isTokenPassword(): a client still sending a recently expired token gets a quiet rejection, not a failed login for brute-force protection.expiresNULL/0) are not affected.TODO
token_auth_expired_token_retentionnext to the othertoken_auth_*options in the admin docs, if wantedChecklist
I only checked syntax locally (
php -l) and ran the delete condition as a read-only SELECT on a real instance. The unit tests will run in CI.🤖 Generated with Claude Code