Repository navigation
Return REQUIRED_SECOND_FACTOR regardless of the password when the TOTP code is missing - #125823
Conversation
…P code is missing For an account with a time-based one-time password, the server returned `REQUIRED_SECOND_FACTOR` only when the password was right and the code was missing, and `AUTHENTICATION_FAILED` otherwise. The two responses let an attacker brute-force the password without ever knowing a code. Now the missing code is reported before the password is looked at, so a right and a wrong password without a code get the same error, and the password is verified only together with the code. When a code is present both factors are evaluated unconditionally, so the timing does not tell which one failed. `REQUIRED_SECOND_FACTOR` maps to HTTP 403 like the other authentication errors instead of 500. `clickhouse-client` now gets `REQUIRED_SECOND_FACTOR` already for the first attempt without any password, so on that error it asks for the password alone first (it may contain the code as `password+code`) and asks for the code only if the server asks again. Users with a password see the same prompts as before; users with `no_password` plus TOTP get a password prompt (press Enter) before the code prompt. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Workflow [PR], commit [710913f] Summary: ✅
AI ReviewSummaryThe PR makes missing TOTP codes independent of password correctness for basic authentication, maps Findings❌ Blockers
Tests
Missing context / blind spots
Final Verdict❌ Block — close the password-only MySQL path for TOTP accounts and add the focused regression case. |
# Conflicts: # src/Access/Authentication.cpp
Build profile diff (arm_release)Commit See the job log for details. |
| /// for a right and a wrong password: otherwise an attacker could confirm a guessed password without the code. | ||
| if (otp_secret && one_time_password.empty()) | ||
| return Authentication::CredentialsCheckResult::NeedSecondFactor; |
There was a problem hiding this comment.
[P1] Cover MySQL native password proofs in the missing-code protection
This guard only runs for BasicCredentials. With mysql_port enabled, a user configured with <password> or <password_double_sha1_hex> plus time_based_one_time_password can still authenticate using only the primary password: MySQLProtocol::Authentication::Native41::authenticate constructs MySQLNative41Credentials, and Authentication::areCredentialsValid dispatches those directly to checkMySQLAuthentication, which never checks getOneTimePassword. consumeOneTimePassword then returns true for these non-basic credentials. For example, the existing totuser fixture can authenticate over MySQL with just aa+bb.
This is a pre-existing alternate path left open by the fix: password guesses still produce success versus failure without a code, and a correct guess bypasses TOTP entirely. Please reject native MySQL proofs when the authentication method has a second factor, as checkScramSHA256Authentication already does, or route these accounts through an exchange that verifies both factors. Add a negative MySQL case proving that the correct primary password alone cannot authenticate.
There was a problem hiding this comment.
Yes. #117407 (merged as 927e545) closes this path in three places: checkMySQLAuthentication returns false when the method has a one-time password, IAccessStorage::authenticateImpl rejects MySQLNative41Credentials when any of the user's methods has one, and MySQLHandler switches such users to the sha256_password plugin, so the password with the code appended arrives as BasicCredentials. Its test_mysql_protocol_requires_totp is the negative case asked for here (correct password alone gets 767); it passes on master at 927e545.
I also checked a master build at 927e545 with the totuser fixture over the MySQL port: aa+bb alone gets 767, aa+bb+<code> logs in.
This PR's head (710913f) does not include #117407 yet, but the two merge without conflicts. On master a wrong password alone over MySQL still gets 516 instead of 767; after the merge that login goes through checkBasicAuthentication, so the guard in this PR covers it too (from the code, I did not run the merged tree).
Cherry pick #125823 to 26.7: Return `REQUIRED_SECOND_FACTOR` regardless of the password when the TOTP code is missing
…of the password when the TOTP code is missing
Backport #125823 to 26.10: Return `REQUIRED_SECOND_FACTOR` regardless of the password when the TOTP code is missing
Backport #125823 to 26.9: Return `REQUIRED_SECOND_FACTOR` regardless of the password when the TOTP code is missing
Backport #125823 to 26.8: Return `REQUIRED_SECOND_FACTOR` regardless of the password when the TOTP code is missing
…egardless of the password when the TOTP code is missing
…of the password when the TOTP code is missing
Backport #125823 to 26.3: Return `REQUIRED_SECOND_FACTOR` regardless of the password when the TOTP code is missing
…of the password when the TOTP code is missing
Motivation
For an account with a time-based one-time password, the server replied with
REQUIRED_SECOND_FACTOR(767) only when the password was right and the code was missing; a wrong password gotAUTHENTICATION_FAILED(516). Over HTTP the two were also told apart by the status: 500 for the former, 403 for the latter. An attacker could therefore brute-force the password without knowing a code, because 767 confirmed a guess. Found by the internal security review of the TOTP implementation.Changes
checkBasicAuthentication): a right, a wrong and an empty password without a code now give the same error, and the password is verified only together with the code. When a code is present, both factors are evaluated unconditionally, so the timing does not tell which one failed. A code suffix of a wrong length counts as no code, as before.REQUIRED_SECOND_FACTORmaps to HTTP 403 like the other authentication errors, instead of falling through to 500.clickhouse-clientgetsREQUIRED_SECOND_FACTORalready for the first attempt without any password, so on that error it asks for the password alone first (it may contain the code aspassword+code) and asks for the code only if the server asks again. Users with a password see the same prompts as before. Users withno_passwordplus TOTP now get a password prompt (press Enter) before the code prompt, because the client cannot tell the two kinds of accounts apart anymore.AUTHENTICATION_FAILED.The error still reveals that the account exists and has a second factor configured; it no longer says anything about the password.
Related: #125664
Related: #125785
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
For users with a time-based one-time password, the error
REQUIRED_SECOND_FACTORis now returned whenever the code is missing, regardless of whether the password is correct. Previously a wrong password without a code returnedAUTHENTICATION_FAILED, which allowed guessing the password without the second factor. The password is verified only together with the code. The error maps to HTTP status 403 instead of 500.clickhouse-clientprompts for the password before the code when neither is given, so users withno_passwordand TOTP now press Enter at the password prompt.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/125823]
Version info
26.11.1.430-master(included in26.11and later)26.10.2.63,26.9.24.14,26.8.34.5,26.3.61.14