6128aeaa89
fix(security): prevent TOTP reuse ( #12616 )
...
# Which Problems Are Solved
TOTP codes could be reused, violating [RFC 6238, section
5.2](https://datatracker.ietf.org/doc/html/rfc6238#section-5.2 ).
# How the Problems Are Solved
Transmitted codes are now recorded in each success event. As the codes
amount to secrets, they are not stored verbatim but as a randomly salted
HMAC-SHA256 (`crypto.HMACValue`). Each value gets a fresh random salt,
so an equal code always produces a different stored value and two
entries can never be recognized as being derived from the same code.
This is deliberately not a replacement for proper secret storage: with
the salt stored alongside the hash and a 6 digit payload, anyone with
event access can brute-force the code in milliseconds. That is
acceptable here because a code is worthless once its window has passed.
The `HMACValue` doc comment states the same.
TOTP codes are low-entropy (6 digits), pseudo random codes. Therefore it
is possible for the same code to be generated more than once over the
lifetime of a user. In order to prevent the (unlikely) case where users
login with large time intervalls and a generated code may be equal to
the one last used a long time ago, we only check for codes used within
the recent period window.
A simpler implementation would be simply storing the latest consumed
step, but the TOTP library does not return this value. Because of the
allowed skew there are always 3 steps within the validation window, so
we can't calculate the current step based on time alone. The retained
history spans one period more than the validation window: validity is
decided by the app server's clock, while the stored events carry the
database clock, and the extra period absorbs the drift between them.
**Note:** a reused code pushes a distinct
`user.human.mfa.otp.check.reused` event, not a failed check event. A
replay therefore stays observable through the Events API without
counting towards the lockout policy. Otherwise anyone who captured a
code could replay it to lock the user out.
# Additional Changes
- Read only the latest events in recheck query
# Additional Context
- Closes https://github.com/zitadel/zitadel/issues/6452
---------
Co-authored-by: Livio Spring <[email protected] >
Co-authored-by: Copilot Autofix powered by AI <[email protected] >
Co-authored-by: copilot-swe-agent[bot] <[email protected] >
Co-authored-by: muhlemmer <[email protected] >
2026-08-27 07:17:39 +02:00
..
2025-01-29 10:29:00 +00:00
2023-12-08 15:30:55 +01:00
2024-05-04 11:55:57 +02:00
2024-07-31 14:42:12 +02:00
2025-12-29 13:35:53 +00:00
2024-07-31 14:42:12 +02:00
2025-12-29 13:35:53 +00:00
2025-12-29 13:35:53 +00:00
2025-12-29 13:35:53 +00:00
2025-12-29 13:35:53 +00:00
2025-12-29 13:35:53 +00:00
2026-06-15 15:36:14 +02:00
2026-06-15 15:36:14 +02:00
2023-12-08 15:30:55 +01:00
2026-03-17 12:54:27 +01:00
2026-03-17 12:54:27 +01:00
2026-03-17 12:54:27 +01:00
2024-11-04 10:44:51 +00:00
2026-02-13 13:06:56 +00:00
2026-07-29 05:46:27 +02:00
2025-02-26 16:06:50 +00:00
2026-08-14 06:11:39 +02:00
2024-09-26 09:14:33 +02:00
2024-08-28 05:33:20 +00:00
2024-08-28 05:33:20 +00:00
2022-12-01 13:31:46 +01:00
2024-09-11 08:24:00 +00:00
2024-09-11 08:24:00 +00:00
2024-09-11 08:24:00 +00:00
2022-04-26 23:01:45 +00:00
2026-03-17 12:54:27 +01:00
2026-08-14 06:12:45 +02:00
2026-06-16 15:19:56 +02:00
2024-09-11 10:53:55 +00:00
2022-04-26 23:01:45 +00:00
2026-06-15 11:24:37 +02:00
2025-10-21 11:18:21 +02:00
2025-10-28 13:23:54 +00:00
2025-10-28 13:23:54 +00:00
2025-10-28 13:23:54 +00:00
2025-06-18 13:24:39 +02:00
2025-06-18 13:24:39 +02:00
2025-06-18 13:24:39 +02:00
2022-04-26 23:01:45 +00:00
2022-10-17 19:19:15 +00:00
2026-02-19 06:06:30 +00:00
2026-06-11 19:52:11 +02:00
2026-06-15 15:36:14 +02:00
2026-07-17 13:24:18 +02:00
2026-07-17 13:24:18 +02:00
2026-06-15 15:27:47 +02:00
2024-05-13 16:01:50 +02:00
2024-04-03 10:43:43 +00:00
2024-08-28 05:33:20 +00:00
2026-02-10 20:25:39 +01:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2024-06-17 12:47:38 +00:00
2023-10-19 12:19:10 +02:00
2024-08-12 22:32:01 +02:00
2026-02-10 20:25:39 +01:00
2023-10-19 12:19:10 +02:00
2024-11-22 17:25:28 +01:00
2026-02-10 20:25:39 +01:00
2023-10-19 15:21:31 +00:00
2026-08-12 08:04:27 +02:00
2026-01-26 14:52:15 +00:00
2026-02-27 09:43:11 +01:00
2026-02-27 09:43:11 +01:00
2026-02-02 09:47:56 +00:00
2026-03-30 15:59:57 +00:00
2024-04-03 10:43:43 +00:00
2023-12-08 15:30:55 +01:00
2026-02-10 20:25:39 +01:00
2024-04-03 10:43:43 +00:00
2023-12-08 15:30:55 +01:00
2026-02-10 20:25:39 +01:00
2026-07-13 09:22:31 +02:00
2024-04-05 09:35:49 +00:00
2023-12-08 15:30:55 +01:00
2026-02-10 20:25:39 +01:00
2026-07-10 09:17:49 +02:00
2026-07-06 10:18:35 +02:00
2025-07-04 18:12:59 +02:00
2026-07-28 15:20:46 +02:00
2026-07-28 15:20:46 +02:00
2024-04-11 09:16:10 +02:00
2022-04-26 23:01:45 +00:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2026-02-10 20:25:39 +01:00
2025-09-08 13:58:14 +00:00
2026-02-10 20:25:39 +01:00
2023-10-26 05:54:09 +00:00
2024-08-12 22:32:01 +02:00
2026-02-10 20:25:39 +01:00
2022-04-26 23:01:45 +00:00
2023-10-19 12:19:10 +02:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2026-02-10 20:25:39 +01:00
2024-04-03 10:43:43 +00:00
2024-04-03 10:43:43 +00:00
2026-02-10 20:25:39 +01:00
2023-01-25 09:49:41 +01:00
2024-08-12 22:32:01 +02:00
2026-02-10 20:25:39 +01:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2026-02-10 20:25:39 +01:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2026-02-10 20:25:39 +01:00
2024-04-10 09:14:55 +00:00
2024-08-12 22:32:01 +02:00
2026-02-10 20:25:39 +01:00
2024-05-13 16:01:50 +02:00
2024-08-12 22:32:01 +02:00
2026-02-10 20:25:39 +01:00
2026-07-30 14:43:47 +00:00
2026-07-30 14:43:47 +00:00
2025-02-26 16:06:50 +00:00
2025-02-26 16:06:50 +00:00
2025-04-02 16:53:06 +02:00
2023-10-19 12:19:10 +02:00
2026-07-01 04:53:16 +00:00
2026-07-01 04:53:16 +00:00
2026-01-27 15:11:56 +01:00
2026-08-12 08:04:27 +02:00
2025-12-17 12:01:09 +01:00
2026-02-23 06:06:33 +00:00
2024-07-31 18:00:38 +03:00
2026-07-01 04:53:16 +00:00
2022-04-26 23:01:45 +00:00
2024-08-14 14:18:14 +00:00
2025-06-26 19:17:45 +03:00
2024-01-17 10:16:48 +00:00
2024-01-17 10:16:48 +00:00
2024-08-12 22:32:01 +02:00
2024-01-17 10:16:48 +00:00
2024-10-31 15:57:17 +01:00
2024-10-31 15:57:17 +01:00
2026-08-14 06:12:45 +02:00
2022-04-26 23:01:45 +00:00
2026-06-15 11:24:37 +02:00
2024-10-28 08:29:34 +00:00
2026-01-26 14:52:15 +00:00
2026-01-26 14:52:15 +00:00
2026-04-08 08:48:05 +02:00
2022-04-26 23:01:45 +00:00
2026-08-14 06:12:45 +02:00
2026-08-14 06:12:45 +02:00
2026-08-14 06:12:45 +02:00
2026-06-15 11:24:37 +02:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2026-08-14 06:12:45 +02:00
2024-05-13 16:01:50 +02:00
2022-04-26 23:01:45 +00:00
2024-08-28 05:33:20 +00:00
2024-06-19 12:56:33 +02:00
2022-04-26 23:01:45 +00:00
2026-03-03 10:24:44 +00:00
2024-06-19 12:56:33 +02:00
2026-06-15 11:24:37 +02:00
2026-03-31 09:58:42 +02:00
2026-03-31 09:58:42 +02:00
2022-04-26 23:01:45 +00:00
2024-08-12 22:32:01 +02:00
2024-11-14 14:04:39 +00:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2024-04-03 10:43:43 +00:00
2023-12-08 15:30:55 +01:00
2023-12-08 15:30:55 +01:00
2026-07-13 09:22:31 +02:00
2024-04-05 09:35:49 +00:00
2023-12-08 15:30:55 +01:00
2023-12-08 15:30:55 +01:00
2026-07-28 15:20:46 +02:00
2026-07-28 15:20:46 +02:00
2022-04-26 23:01:45 +00:00
2025-07-04 18:12:59 +02:00
2026-02-10 20:25:39 +01:00
2026-06-15 11:24:37 +02:00
2026-03-10 10:09:51 +00:00
2026-03-10 10:09:51 +00:00
2025-07-04 18:12:59 +02:00
2023-12-08 15:30:55 +01:00
2025-07-29 15:56:21 +02:00
2025-07-29 15:56:21 +02:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2026-02-10 20:25:39 +01:00
2024-04-10 09:14:55 +00:00
2024-04-10 09:14:55 +00:00
2024-06-19 12:56:33 +02:00
2022-11-30 17:01:17 +01:00
2022-04-26 23:01:45 +00:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2024-04-03 10:43:43 +00:00
2023-12-08 15:30:55 +01:00
2023-12-08 15:30:55 +01:00
2023-01-25 09:49:41 +01:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2024-05-13 16:01:50 +02:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2026-04-13 10:59:50 +00:00
2026-04-13 10:59:50 +00:00
2025-07-29 15:56:21 +02:00
2025-07-29 15:56:21 +02:00
2025-07-29 15:56:21 +02:00
2025-09-16 12:26:21 +00:00
2026-08-14 06:11:39 +02:00
2023-12-08 15:30:55 +01:00
2025-01-27 13:36:07 +01:00
2023-10-26 05:54:09 +00:00
2022-04-26 23:01:45 +00:00
2023-07-20 04:06:16 +00:00
2022-04-26 23:01:45 +00:00
2023-01-25 09:49:41 +01:00
2025-07-29 15:56:21 +02:00
2022-04-26 23:01:45 +00:00
2023-12-08 15:30:55 +01:00
2024-04-10 09:14:55 +00:00
2024-05-13 16:01:50 +02:00
2024-08-12 22:32:01 +02:00
2026-06-15 11:24:37 +02:00
2025-06-27 17:25:44 +02:00
2025-10-17 10:12:20 +02:00
2026-06-15 11:24:37 +02:00
2025-07-02 07:34:19 +00:00
2025-07-02 07:34:19 +00:00
2026-06-15 11:24:37 +02:00
2026-08-12 08:04:27 +02:00
2026-08-03 08:37:59 +00:00
2026-08-12 08:04:27 +02:00
2026-08-12 08:04:27 +02:00
2026-08-12 08:04:27 +02:00
2026-08-12 08:04:27 +02:00
2026-06-15 11:24:37 +02:00
2025-06-27 17:25:44 +02:00
2025-06-27 17:25:44 +02:00
2026-06-15 11:24:37 +02:00
2026-08-12 08:04:27 +02:00
2025-10-17 10:12:20 +02:00
2025-06-27 17:25:44 +02:00
2025-06-27 17:25:44 +02:00
2026-08-12 08:04:27 +02:00
2026-06-15 11:24:37 +02:00
2025-09-21 14:04:25 +00:00
2026-03-03 10:24:44 +00:00
2026-06-15 11:24:37 +02:00
2025-09-21 14:04:25 +00:00
2025-09-21 14:04:25 +00:00
2025-01-17 16:16:26 +01:00
2025-07-04 18:12:59 +02:00
2025-07-04 18:12:59 +02:00
2026-06-15 11:24:37 +02:00
2025-06-04 11:46:10 +00:00
2026-06-15 11:24:37 +02:00
2025-05-21 14:40:47 +02:00
2026-07-09 13:28:09 +02:00
2025-05-21 14:40:47 +02:00
2025-08-15 11:35:43 +02:00
2023-12-08 15:30:55 +01:00
2023-12-08 15:30:55 +01:00
2023-10-19 12:19:10 +02:00
2023-09-15 16:58:45 +02:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2025-06-04 07:17:23 +00:00
2023-12-05 11:12:01 +00:00
2024-08-12 22:32:01 +02:00
2024-04-08 08:15:44 +00:00
2025-03-26 17:08:13 +00:00
2025-07-15 13:38:00 +02:00
2025-07-15 13:38:00 +02:00
2024-12-19 11:11:40 +00:00
2026-08-14 06:12:45 +02:00
2026-08-14 06:12:45 +02:00
2025-11-24 06:44:48 +00:00
2025-11-24 06:44:48 +00:00
2025-10-29 10:07:35 +01:00
2025-10-29 10:07:35 +01:00
2025-11-24 06:44:48 +00:00
2026-08-27 07:17:39 +02:00
2026-03-27 12:38:40 +01:00
2023-12-08 15:30:55 +01:00
2026-04-13 10:59:50 +00:00
2025-09-08 11:00:04 +00:00
2026-06-15 15:36:14 +02:00
2026-06-15 15:36:14 +02:00
2026-06-15 15:36:14 +02:00
2026-06-15 15:36:14 +02:00
2025-03-24 06:03:24 +00:00
2026-02-05 10:51:09 +00:00
2026-02-05 10:51:09 +00:00
2026-02-05 10:51:09 +00:00
2026-01-26 14:52:15 +00:00
2024-01-02 14:26:31 +00:00
2026-08-14 06:12:45 +02:00
2026-08-14 06:12:45 +02:00
2026-03-11 08:25:21 +01:00
2023-12-08 15:30:55 +01:00
2024-06-19 12:56:33 +02:00
2022-04-26 23:01:45 +00:00
2026-06-15 11:24:37 +02:00
2026-07-09 13:28:09 +02:00
2026-07-09 13:28:09 +02:00
2026-06-15 11:24:37 +02:00
2026-06-15 11:24:37 +02:00
2023-12-08 15:30:55 +01:00
2023-12-08 15:30:55 +01:00
2024-08-12 22:32:01 +02:00
2023-12-08 15:30:55 +01:00
2026-06-15 11:24:37 +02:00
2026-02-13 13:06:56 +00:00
2026-02-13 13:06:56 +00:00
2026-06-15 11:24:37 +02:00
2024-08-12 22:32:01 +02:00
2024-05-02 11:50:13 +02:00
2026-06-15 11:24:37 +02:00
2026-08-27 07:17:39 +02:00
2026-08-27 07:17:39 +02:00
2025-10-29 10:07:35 +01:00
2026-08-27 07:17:39 +02:00
2026-06-15 11:24:37 +02:00
2025-10-29 10:07:35 +01:00
2026-06-05 14:48:35 +02:00
2026-06-15 11:24:37 +02:00
2024-09-26 09:14:33 +02:00
2024-09-26 09:14:33 +02:00
2026-06-15 11:24:37 +02:00
2023-12-08 15:30:55 +01:00
2023-12-08 15:30:55 +01:00
2026-06-15 11:24:37 +02:00
2026-06-15 11:24:37 +02:00
2026-02-26 19:22:37 +01:00
2026-02-26 19:22:37 +01:00
2026-06-15 11:24:37 +02:00
2024-08-12 22:32:01 +02:00
2024-05-16 07:07:56 +02:00
2026-06-05 14:48:35 +02:00
2026-06-15 11:24:37 +02:00
2026-08-14 06:11:39 +02:00
2026-03-11 08:25:21 +01:00
2026-08-14 06:11:39 +02:00
2026-06-05 14:48:35 +02:00
2026-06-15 11:24:37 +02:00
2024-08-14 13:04:26 +00:00
2025-07-04 18:12:59 +02:00
2026-06-15 11:24:37 +02:00
2024-08-12 22:32:01 +02:00
2025-06-04 07:17:23 +00:00
2026-06-15 11:24:37 +02:00
2025-08-19 15:22:34 +02:00
2025-08-19 15:22:34 +02:00
2026-03-16 13:12:21 +01:00
2026-03-16 13:12:21 +01:00
2022-07-06 14:09:49 +02:00
2026-06-15 11:24:37 +02:00
2026-03-09 10:47:32 +01:00
2026-03-10 10:09:51 +00:00
2026-06-15 11:24:37 +02:00
2023-12-08 15:30:55 +01:00
2023-12-08 15:30:55 +01:00
2024-04-03 10:43:43 +00:00
2026-04-13 10:59:50 +00:00
2026-04-13 10:59:50 +00:00
2025-03-25 07:01:29 +00:00
2024-08-28 19:46:45 +00:00
2024-09-17 08:27:48 +00:00
2025-10-28 13:23:54 +00:00
2026-06-08 16:41:08 +02:00
2026-06-08 16:41:08 +02:00
2026-06-08 16:41:08 +02:00
2026-06-08 16:41:08 +02:00
2026-08-12 06:24:28 +00:00
2026-08-12 06:24:28 +00:00
2026-02-20 12:34:07 +00:00
2026-03-09 10:47:32 +01:00
2026-03-09 10:47:32 +01:00
2026-06-15 11:24:37 +02:00
2026-06-15 11:24:37 +02:00
2026-08-14 06:11:39 +02:00
2026-08-14 06:11:39 +02:00
2026-08-14 06:11:39 +02:00
2026-02-13 13:06:56 +00:00
2026-02-13 13:06:56 +00:00
2026-06-08 16:41:08 +02:00
2026-06-08 16:41:08 +02:00
2025-10-28 13:23:54 +00:00
2024-05-14 09:20:31 +02:00
2024-05-07 05:38:26 +00:00
2024-07-31 18:00:38 +03:00
2024-05-07 05:38:26 +00:00
2025-07-29 15:56:21 +02:00
2025-10-28 13:23:54 +00:00
2024-09-25 13:31:31 +00:00
2024-09-25 13:31:31 +00:00
2024-09-26 09:14:33 +02:00
2024-09-26 09:14:33 +02:00
2024-09-26 09:14:33 +02:00
2024-09-26 09:14:33 +02:00
2024-09-26 09:14:33 +02:00
2026-02-13 13:06:56 +00:00
2024-08-14 14:18:14 +00:00
2025-04-02 16:53:06 +02:00
2025-04-02 16:53:06 +02:00