An invalid TOTP secret key is usually one of two things: a character base32 does not have, or a key that was cut short when it was copied. The first can be refused the moment it is typed. The second is quieter, because a truncated key can decode perfectly and then make six wrong digits for ever. Mosaic's authenticator accepted both kinds for a while, because it checked the key only when it was asked for a code. Since 29 September 2026 it checks when the key is saved.
What makes a TOTP secret key invalid
The key a site shows beside its QR code is base32. RFC 4648 defines the alphabet as the letters A to Z and the digits 2 to 7, with = only as padding. A 0, 1, 8 or 9 cannot appear, which is why keys typed from a screen so often fail: an O read as a zero, an I read as a one.
The code itself comes from RFC 6238: an HMAC over the current 30-second step, truncated to six digits. The key is the only secret in that sum, so a key that is wrong by one character gives codes that are wrong every time, with nothing to say why. (The TOTP glossary entry has the rest of the mechanism.)
Each profile keeps its own passwords and its own 2FA codesIn Mosaic: Logins and 2FA codes. A password vault and TOTP codes for each profile. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.
Mosaic is a desktop app
Email yourself the link and open it on your computer.
How it works: Logins and 2FA codes
How ours went wrong
Building the Auth panel in the companion, the extension inside each profile, we pasted not a key!! into it to see what happened. The panel said "Saved to this profile." The row then showed --- --- for ever.
The decoder did refuse the key. It threw "!" is not valid base32, but only when something asked for a code, and the code route is not one anyone presses twice. The key had already been accepted, encrypted and stored by then. From outside, a stored bad key and a stored good key looked the same until a login failed.
That is a rule we now write down in one line: a value checked only where it is read is not checked. The check goes where the value is written.
Where the check went
The fix is assertUsableTotpSecret in store/credentials.ts, which runs when a login is created and when its key is changed. It lives in the store because the window, the REST API and MCP all save logins through that one method. A check in the window alone would have left the other two accepting the same bad key.
It first tidies what people actually paste. Spaces and hyphens are removed, letters are upper-cased, and an otpauth:// link has its secret parameter read out. Then it decodes, and refuses with a 400 that names the field:
totpSecret is empty — paste the setup key the site shows beside its QR code.
totpSecret is not a valid setup key: "0" is not valid base32 — check the secret.
totpSecret is too short to be a setup key — 12 characters decode to 7 bytes,
and the shortest key any site issues is 13.
Why the floor is 64 bits
The last message is the one that catches a paste that stopped halfway. The floor is 8 bytes, 64 bits, which is 13 base32 characters.
That is deliberately below the standard. RFC 4226, which TOTP builds on, says the shared secret must be at least 128 bits. Some sites still issue 13- and 14-character keys, and refusing a key a real site gave you is worse than accepting a short one that works. Anything under 64 bits is not a short key. It is a fragment of one, and a fragment decodes fine and then produces wrong codes with no symptom at the moment the mistake is made.
How the check is held
check:totp runs in every build. It starts from one known-good key, JBSWY3DPEHPK3PXP, and breaks it one way at a time: a 1 swapped in for one letter, punctuation, an empty string, nothing but separators, half the key, a twelve-character fragment, a single character, and an otpauth:// link whose secret is not base32. All eight have to be refused with a 400 that names totpSecret. Five pasted shapes of the same good key have to be accepted: with spaces as Google prints it, with hyphens, in lower case, inside an otpauth:// link, and with padding. Writing the bad cases by breaking a good one means a new rule cannot leave an old case out of date.
If your own authenticator rejects a key, the fix is nearly always to copy the full key again from the site's two-factor setup page, not to retype it. If it accepts the key and the codes are still wrong, suspect a partial copy first and the computer's clock second.
How the Auth panel reads keys from QR codes, and the three other faults found while building it, are in an authenticator inside the profile. The per-profile vault itself is on logins and 2FA.
Sources
- RFC 4648: The Base16, Base32, and Base64 Data Encodings, read November 2, 2026
- RFC 4226: HOTP, an HMAC-based one-time password algorithm, read November 2, 2026
- RFC 6238: TOTP, a time-based one-time password algorithm, read November 2, 2026






