20cbfcf552
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 <9405495+livio-a@users.noreply.github.com >
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com >
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com >
Co-authored-by: muhlemmer <5411563+muhlemmer@users.noreply.github.com >
(cherry picked from commit 6128aeaa89 )
2026-08-27 14:49:12 +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-30 08:26:20 +01:00
2024-07-31 14:42:12 +02:00
2025-12-30 09:13:05 +01:00
2025-12-30 09:13:05 +01:00
2025-12-30 09:13:05 +01:00
2025-12-30 08:26:20 +01:00
2025-12-30 08:26:20 +01:00
2026-06-15 16:08:00 +02:00
2026-06-15 16:08:00 +02:00
2023-12-08 15:30:55 +01:00
2026-03-17 13:04:01 +01:00
2026-03-17 13:04:01 +01:00
2026-03-17 13:04:01 +01:00
2024-11-04 10:44:51 +00:00
2026-02-27 10:09:02 +01:00
2026-07-29 06:13:57 +02:00
2025-02-26 16:06:50 +00:00
2026-08-14 06:23:05 +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 13:04:01 +01:00
2026-08-14 07:00:05 +02:00
2026-06-17 06:05:51 +02:00
2024-09-11 10:53:55 +00:00
2022-04-26 23:01:45 +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-27 10:17:19 +01:00
2026-06-15 15:42:31 +02:00
2026-06-15 16:08:00 +02:00
2026-08-12 06:33:00 +02:00
2026-08-12 06:33:00 +02:00
2026-08-12 06:31:49 +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-27 09:42:24 +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-27 09:42:24 +01:00
2023-10-19 12:19:10 +02:00
2024-11-22 17:25:28 +01:00
2026-02-27 09:42:24 +01:00
2023-10-19 15:21:31 +00:00
2026-08-12 10:05:01 +02:00
2026-02-27 07:29:26 +01:00
2026-03-02 08:23:30 +01:00
2026-02-27 07:29:26 +01:00
2026-04-01 08:57:30 +02:00
2024-04-03 10:43:43 +00:00
2023-12-08 15:30:55 +01:00
2026-02-27 09:42:24 +01:00
2024-04-03 10:43:43 +00:00
2023-12-08 15:30:55 +01:00
2026-02-27 09:42:24 +01:00
2026-08-12 06:31:52 +02:00
2024-04-05 09:35:49 +00:00
2023-12-08 15:30:55 +01:00
2026-02-27 09:42:24 +01:00
2026-08-12 06:31:52 +02:00
2026-08-12 06:31:51 +02:00
2025-07-04 18:12:59 +02:00
2026-08-12 06:33:00 +02:00
2026-08-12 06:33:00 +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-27 09:42:24 +01:00
2024-08-12 22:32:01 +02:00
2026-02-27 09:42:24 +01:00
2023-10-26 05:54:09 +00:00
2024-08-12 22:32:01 +02:00
2026-02-27 09:42:24 +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-27 09:42:24 +01:00
2024-04-03 10:43:43 +00:00
2024-04-03 10:43:43 +00:00
2026-02-27 09:42:24 +01:00
2023-01-25 09:49:41 +01:00
2024-08-12 22:32:01 +02:00
2026-02-27 09:42:24 +01:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2026-02-27 09:42:24 +01:00
2024-04-03 10:43:43 +00:00
2024-08-12 22:32:01 +02:00
2026-02-27 09:42:24 +01:00
2024-04-10 09:14:55 +00:00
2024-08-12 22:32:01 +02:00
2026-02-27 09:42:24 +01:00
2024-05-13 16:01:50 +02:00
2024-08-12 22:32:01 +02:00
2026-02-27 09:42:24 +01:00
2026-08-12 06:33:11 +02:00
2026-08-12 06:33:11 +02: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-10 07:34:08 +02:00
2026-07-10 07:34:08 +02:00
2026-02-09 14:24:58 +01:00
2026-08-12 10:05:01 +02:00
2025-05-21 10:50:44 +02:00
2026-02-27 10:21:46 +01:00
2024-07-31 18:00:38 +03:00
2026-07-10 07:34:08 +02: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 07:00:05 +02:00
2022-04-26 23:01:45 +00:00
2026-06-15 16:03:39 +02:00
2024-10-28 08:29:34 +00:00
2026-02-27 07:29:26 +01:00
2026-02-27 07:29:26 +01:00
2026-04-24 06:55:24 +02:00
2022-04-26 23:01:45 +00:00
2026-08-14 07:00:05 +02:00
2026-08-14 07:00:05 +02:00
2026-08-14 07:00:05 +02:00
2026-06-15 16:03:39 +02:00
2024-08-12 22:32:01 +02:00
2024-06-19 12:56:33 +02:00
2026-08-14 07:00:05 +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-23 07:01:32 +01:00
2024-06-19 12:56:33 +02:00
2026-06-15 16:03:39 +02:00
2026-04-01 09:03:12 +02:00
2026-04-01 09:03:12 +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-08-12 06:31:52 +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-08-12 06:33:00 +02:00
2026-08-12 06:33:00 +02:00
2022-04-26 23:01:45 +00:00
2025-07-04 18:12:59 +02:00
2026-02-27 09:42:24 +01:00
2026-06-15 16:03:39 +02:00
2026-03-23 07:01:34 +01:00
2026-03-23 07:01:34 +01:00
2025-07-04 18:12:59 +02:00
2023-12-08 15:30:55 +01: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
2024-08-12 22:32:01 +02:00
2026-02-27 09:42:24 +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-24 06:55:26 +02:00
2026-04-24 06:55:26 +02:00
2025-09-30 07:09:03 +02:00
2026-08-14 06:23:05 +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
2022-12-08 08:11:49 +01: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 16:03:39 +02:00
2025-06-27 17:25:44 +02:00
2025-10-27 08:56:27 +01:00
2026-06-15 16:03:39 +02:00
2025-07-02 07:34:19 +00:00
2025-07-02 07:34:19 +00:00
2026-06-15 16:03:39 +02:00
2026-08-12 10:05:01 +02:00
2026-08-12 06:33:12 +02:00
2026-08-12 10:05:01 +02:00
2026-08-12 10:05:01 +02:00
2026-08-12 10:05:01 +02:00
2026-08-12 10:05:01 +02:00
2026-06-15 16:03:39 +02:00
2025-06-27 17:25:44 +02:00
2025-06-27 17:25:44 +02:00
2026-06-15 16:03:39 +02:00
2026-08-12 10:05:01 +02:00
2025-10-27 08:56:27 +01:00
2025-06-27 17:25:44 +02:00
2025-06-27 17:25:44 +02:00
2026-08-12 10:05:01 +02:00
2026-06-15 16:03:39 +02:00
2025-09-30 07:11:19 +02:00
2026-03-23 07:01:32 +01:00
2026-06-15 16:03:39 +02:00
2025-09-30 07:11:19 +02:00
2025-09-30 07:11:19 +02: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 16:03:39 +02:00
2025-06-04 11:46:10 +00:00
2026-06-15 16:03:39 +02:00
2025-05-21 14:40:47 +02:00
2026-07-10 07:37:22 +02:00
2025-09-12 09:16:49 +00:00
2025-09-12 09:16:49 +00: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 07:00:05 +02:00
2026-08-14 07:00:05 +02:00
2026-01-06 10:54:41 +01:00
2026-01-06 10:54:41 +01:00
2025-10-29 10:10:36 +01:00
2025-10-29 10:10:36 +01:00
2026-01-06 10:54:41 +01:00
2026-08-27 14:49:12 +02:00
2024-05-30 22:08:48 +00:00
2023-12-08 15:30:55 +01:00
2026-04-24 06:55:26 +02:00
2025-09-15 08:26:41 +02:00
2026-06-15 16:08:00 +02:00
2026-06-15 16:08:00 +02:00
2026-06-15 16:08:00 +02:00
2026-06-15 16:08:00 +02:00
2025-03-24 06:03:24 +00:00
2026-02-09 14:25:14 +01:00
2026-02-09 14:24:54 +01:00
2026-02-09 14:25:14 +01:00
2026-02-27 07:29:26 +01:00
2024-01-02 14:26:31 +00:00
2026-08-14 07:00:05 +02:00
2026-08-14 07:00:05 +02:00
2026-03-11 08:29:40 +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 16:03:39 +02:00
2026-07-10 07:37:22 +02:00
2026-07-10 07:37:22 +02:00
2026-06-15 16:03:39 +02:00
2026-06-15 16:03:39 +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 16:03:39 +02:00
2026-02-27 10:09:02 +01:00
2026-02-27 10:09:02 +01:00
2026-06-15 16:03:39 +02:00
2024-08-12 22:32:01 +02:00
2024-05-02 11:50:13 +02:00
2026-06-15 16:03:39 +02:00
2026-08-27 14:49:12 +02:00
2026-08-27 14:49:12 +02:00
2025-10-29 10:10:36 +01:00
2026-08-27 14:49:12 +02:00
2026-06-15 16:03:39 +02:00
2025-10-29 10:10:36 +01:00
2026-06-08 16:46:12 +02:00
2026-06-15 16:03:39 +02:00
2024-09-26 09:14:33 +02:00
2024-09-26 09:14:33 +02:00
2026-06-15 16:03:39 +02:00
2023-12-08 15:30:55 +01:00
2023-12-08 15:30:55 +01:00
2026-06-15 16:03:39 +02:00
2026-06-15 16:03:39 +02:00
2026-01-06 10:54:41 +01:00
2026-01-06 10:54:41 +01:00
2026-06-15 16:03:39 +02:00
2024-08-12 22:32:01 +02:00
2024-05-16 07:07:56 +02:00
2026-06-08 16:46:12 +02:00
2026-06-15 16:03:39 +02:00
2026-08-14 06:23:05 +02:00
2026-03-11 08:29:40 +01:00
2026-08-14 06:23:05 +02:00
2026-06-08 16:46:12 +02:00
2026-06-15 16:03:39 +02:00
2024-08-14 13:04:26 +00:00
2025-07-04 18:12:59 +02:00
2026-06-15 16:03:39 +02:00
2024-08-12 22:32:01 +02:00
2025-06-04 07:17:23 +00:00
2026-06-15 16:03:39 +02:00
2025-08-21 09:24:03 +02:00
2025-08-21 09:24:03 +02:00
2026-03-23 07:01:49 +01:00
2026-03-23 07:01:49 +01:00
2022-07-06 14:09:49 +02:00
2026-06-15 16:03:39 +02:00
2026-03-23 07:01:34 +01:00
2026-03-23 07:01:34 +01:00
2026-06-15 16:03:39 +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-24 06:55:26 +02:00
2026-04-24 06:55:26 +02: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-06-04 07:17:23 +00:00
2026-06-08 16:51:22 +02:00
2026-06-08 16:51:22 +02:00
2026-06-08 16:51:22 +02:00
2026-06-08 16:51:22 +02:00
2026-08-12 10:05:01 +02:00
2026-08-12 10:05:01 +02:00
2026-02-27 10:19:25 +01:00
2026-03-23 07:01:34 +01:00
2026-03-23 07:01:34 +01:00
2026-06-15 16:03:39 +02:00
2026-06-15 16:03:39 +02:00
2026-08-14 06:23:05 +02:00
2026-08-14 06:23:05 +02:00
2026-08-14 06:23:05 +02:00
2026-02-27 10:09:02 +01:00
2026-02-27 10:09:02 +01:00
2026-06-08 16:51:22 +02:00
2026-06-08 16:51:22 +02:00
2025-09-30 07:09:03 +02: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
2024-07-05 09:36:00 +02:00
2025-09-30 07:09:03 +02: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-27 10:09:02 +01: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