Skip to content

Allow disabling 2FA with a backup/recovery code (#5451)#5700

Open
TowyTowy wants to merge 1 commit into
NginxProxyManager:developfrom
TowyTowy:fix/5451-2fa-disable-recovery-code
Open

Allow disabling 2FA with a backup/recovery code (#5451)#5700
TowyTowy wants to merge 1 commit into
NginxProxyManager:developfrom
TowyTowy:fix/5451-2fa-disable-recovery-code

Conversation

@TowyTowy

Copy link
Copy Markdown

Why

Fixes #5451.

The 2FA disable endpoint (DELETE /api/users/:id/2fa) passed the submitted code straight to otplib's verify(), which only accepts 6-digit numeric TOTP tokens. A backup/recovery code (8 hex characters, e.g. A1B2C3D4) makes verify() throw (Token must be 6 digits / Token must contain only digits), which is returned to the client as a generic 500 "Internal error". disable() also never fell back to matching the code against the stored backup codes.

The practical impact: a user who lost their authenticator and logged in with a recovery code cannot disable 2FA at all — the recovery code is the only credential they have, and it is rejected. Multiple users reported this on #5451.

What

Reuse the existing verifyForLogin() path in disable(). It already accepts both a TOTP code and a backup code, guards the TOTP check by length so non-numeric codes don't throw, and relaxes the secret-length guardrails for legacy secrets. Disabling 2FA now works with either a TOTP code or a recovery code, matching login behaviour. No API shape change.

Verified with a standalone reproduction against the bundled otplib v13 + bcryptjs: the old path throws TokenLengthError on an 8-char recovery code (→ 500), the new path accepts a recovery code and a valid TOTP and rejects wrong codes without throwing. biome lint clean. (No backend unit-test harness exists — the test/ suite is Cypress integration needing a full Docker stack; reviewer steps below.)

To verify manually: enable 2FA, log out, log back in using a recovery code, then Account → Two-Factor Auth → Disable and enter a recovery code — it should now succeed instead of "Internal error".

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

AI Usage

  • AI was used to write this

This PR was authored with AI assistance (Claude); every line was reviewed and the fix reproduced/verified before submission.

The 2FA disable endpoint passed the submitted code straight to otplib's
verify(), which only accepts 6-digit numeric TOTP tokens. A backup/recovery
code (8 hex characters) makes verify() throw ("Token must be 6 digits" /
"Token must contain only digits"), which is returned to the client as a
generic 500 "Internal error".

As a result, a user who lost their authenticator and logged in with a
recovery code could not disable 2FA at all, since the recovery code is the
only credential they have.

Reuse the existing verifyForLogin() path, which already accepts both a TOTP
code and a backup code (and relaxes the secret-length guardrails for legacy
secrets), so disabling 2FA works with either, matching login behaviour.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@nginxproxymanagerci

Copy link
Copy Markdown

Docker Image for build 1 is available on DockerHub:

nginxproxymanager/nginx-proxy-manager-dev:pr-5700

Note

Ensure you backup your NPM instance before testing this image! Especially if there are database changes.
This is a different docker image namespace than the official image.

Warning

Changes and additions to DNS Providers require verification by at least 2 members of the community!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disabling 2FA with recovery codes fails because NPM expects only digits

1 participant