[GH-ISSUE #838] Security: Tokens get deleted in certain cases. #590

Closed
opened 2026-05-07 00:25:39 +02:00 by BreizhHardware · 1 comment

Originally created by @binwiederhier on GitHub (Aug 17, 2023).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/838

The excess query deletion logic is incorrect and can lead to tokens being deleted erroneously.

Issue

ntfy only allows 20 access tokens to be created per user. Since access tokens are also used by the browser session, excess tokens (> 20) are deleted when the 21st token is created. This excess deletion logic is meant to only delete tokens from the user creating the 21st token. Instead, it accidentally deleted all tokens of all other users, thereby logging everyone out of their ntfy web app sessions, and deleting all other access tokens.

This was a denial-of-service-type security issue, since it effectively allowed a single user to deny access to all other users of a ntfy instance. Please note that while tokens were erroneously deleted, nobody but the token owner ever had access to it.

Details

Original delete query:

DELETE FROM user_token
WHERE (user_id, token) NOT IN (
	SELECT user_id, token
	FROM user_token
	WHERE user_id = ?
	ORDER BY expires DESC
	LIMIT ?
)

Fixed query:

DELETE FROM user_token
WHERE user_id = ?
  AND (user_id, token) NOT IN (
	SELECT user_id, token
	FROM user_token
	WHERE user_id = ?
	ORDER BY expires DESC
	LIMIT ?
)

What to do

If you run a multi-user public system, please update your instances to ntfy v2.7.0

Originally created by @binwiederhier on GitHub (Aug 17, 2023). Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/838 The excess query deletion logic is incorrect and can lead to tokens being deleted erroneously. ## Issue ntfy only allows 20 access tokens to be created per user. Since access tokens are also used by the browser session, excess tokens (> 20) are deleted when the 21st token is created. This excess deletion logic is meant to only delete tokens from the user creating the 21st token. Instead, it accidentally deleted _all tokens_ of _all other users_, thereby logging everyone out of their ntfy web app sessions, and deleting all other access tokens. This was a denial-of-service-type security issue, since **it effectively allowed a single user to deny access to all other users of a ntfy instance**. Please note that while tokens were erroneously deleted, **nobody but the token owner ever had access to it.** ## Details Original delete query: ```sql DELETE FROM user_token WHERE (user_id, token) NOT IN ( SELECT user_id, token FROM user_token WHERE user_id = ? ORDER BY expires DESC LIMIT ? ) ``` Fixed query: ```sql DELETE FROM user_token WHERE user_id = ? AND (user_id, token) NOT IN ( SELECT user_id, token FROM user_token WHERE user_id = ? ORDER BY expires DESC LIMIT ? ) ``` ## What to do If you run a multi-user public system, please update your instances to ntfy v2.7.0
Author
Owner

@binwiederhier commented on GitHub (Aug 17, 2023):

Fixed in github.com/binwiederhier/ntfy@3e3b556108

<!-- gh-comment-id:1682929377 --> @binwiederhier commented on GitHub (Aug 17, 2023): Fixed in https://github.com/binwiederhier/ntfy/commit/3e3b556108209eeab3410188e6f6cc14d425a4d8
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ntfy#590
No description provided.