Repository navigation
Use constant-time comparison for TOTP codes and plaintext passwords - #125785
Conversation
|
Workflow [PR], commit [5d44c34] Summary: ✅
AI ReviewSummaryThis PR replaces prefix-sensitive comparisons for TOTP codes and basic Findings
Missing context / blind spots
Tests
Final Verdict |
| if (matched && !result.has_value()) | ||
| result = static_cast<Int64>(current_time / secret.params.period) + delta; |
There was a problem hiding this comment.
❌ Matched-window selection still has data-dependent control flow
constantTimeEquals removes prefix-dependent exits, but this condition still branches on each comparison result and computes the time step only for the first match. With the same secret and server time, codes matching delta = 0 and delta = 1 take different paths despite both being accepted. This also runs through checkOneTimePassword before the ordinary password check, so the distinction is observable even when the ordinary password is wrong.
In an isolated build of the unchanged helper and its callers with Clang 21, -O3, and AArch64, the match results retain cbz/cbnz/tbnz branches and conditionally executed udiv. Computing all three candidates therefore does not establish the changelog's promised independence from the matching window.
Please compute candidate steps unconditionally and use audited constant-time selection of the first match, preserving the 0, -1, 1 priority. Construct the optional result after selection, and verify the optimized code in supported release configurations; the existing authentication tests do not prove this property.
Backport #125785 to 26.9: Use constant-time comparison for TOTP codes and plaintext passwords
Backport #125785 to 26.8: Use constant-time comparison for TOTP codes and plaintext passwords
Cherry-pick of #125785 onto 26.3: add only the two constantTimeEquals overloads (and the <span> include) to StringUtils.h; the ASCII case helpers next to them in the conflict are separate master changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry-pick of #125785 onto 26.7: add only the two constantTimeEquals overloads (and the <span> include) to StringUtils.h; the ASCII case helpers next to them in the conflict are separate master changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… and plaintext passwords
… and plaintext passwords
Backport #125785 to 26.7: Use constant-time comparison for TOTP codes and plaintext passwords
Backport #125785 to 26.3: Use constant-time comparison for TOTP codes and plaintext passwords
Backport #125785 to 26.10: Use constant-time comparison for TOTP codes and plaintext passwords
…TOTP codes and plaintext passwords
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Compare TOTP codes and
plaintext_passwordpasswords in constant time, so that the response time does not depend on how many leading characters are correct or on which time window matched.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/125785]
Version info
26.11.1.91-master(included in26.11and later)26.10.2.31,26.9.21.5,26.8.30.4,26.7.35.5,26.3.57.12