Repository navigation
fix(totp): allow /totp add when the server name contains a colon - #3160
Merged
Merged
Conversation
The server name is passed to googleauth as the TOTP issuer. The library throws "Issuer cannot contain the ':' character." for such a name, so /totp add failed with an unexpected error for every player. The otpauth label has the form "issuer:account", so a colon cannot be part of the issuer. Replace it with a hyphen when building the URL. The configured server name itself is not changed. Fixes AuthMe#3158
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
/totp addfails with "An unexpected error occurred trying to execute that command" whensettings.serverNamecontains a colon, for exampleUT:Rebirthin #3158.TotpAuthenticator.generateTotpKeypasses the server name toGoogleAuthenticatorQRGenerator.getOtpAuthTotpURLas the issuer, and googleauth 1.5.0 throwsIllegalArgumentException: Issuer cannot contain the ':' character.for it. The command then fails for every player on that server.The otpauth label has the form
issuer:account, and the Key URI format does not allow a colon inside the issuer (a percent-encoded%3Acounts as the separator too), so the colon cannot be kept by encoding it. This change replaces:with-in the issuer only when the URL is built, soUT:Rebirthis shown asUT-Rebirthin the authenticator app. I picked a hyphen over a space because it is written unescaped in both the label and theissuerparameter, while a space ends up as%20in one and+in the other. The configured server name is not changed and is still used as is everywhere else (welcome message, emails).The colon is the only character googleauth rejects in the issuer. The account name (the player name) is only checked for being non-empty, so nothing changes there.
Testing:
TotpAuthenticatorTest.shouldGenerateTotpKeyForServerNameWithColon. It fails on master with the exception from the issue and passes with the change.mvn test -pl authme-core(JDK 21): 1444 tests, 0 failures.mvn -V -B clean package(the CI command, JDK 21): all modules build and pass.PurgeServiceTest.shouldRunAutoPurgefailed in two earlier runs of that command on a heavily loaded machine (it compares wall-clock timestamps with a 100 ms tolerance and was 132 ms off); it is unrelated to this change and passed in the other runs.settings.serverName: 'A:B'and an offline-mode bot that registers, logs out, logs in and runs/totp add:AuthMe-*-Paper.jar(bot on 1.21.4 through ViaVersion/ViaBackwards): master logs the same stack trace as the issue and the player gets the error message. With the change the player gets the secret and the QR code link, whosedataparameter decodes tootpauth://totp/A-B:TotpBot?secret=...&issuer=A-B&algorithm=SHA1&digits=6&period=30, and/totp confirmwith a code computed from that secret is accepted.AuthMe-*-Spigot-Legacy.jar: same results, also withserverName: 'UT:Rebirth'(issuerUT-Rebirth).Not tested: scanning the generated QR code with a real authenticator app, and a run under JDK 17 (authme-core is compiled with
--release 17, the tests ran on JDK 21).This touches the same lines as #3128 in
TotpAuthenticator.generateTotpKey, so whichever is merged second needs a small conflict resolution there.Fixes #3158