Skip to content

Commit b0ee148

Browse files
dougfabrisricardogarim
authored andcommitted
fix: Unable to change password when 2FA is enabled (#37745)
1 parent fb49d16 commit b0ee148

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

.changeset/cold-chairs-taste.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rocket.chat/meteor': patch
3+
---
4+
5+
Fixes an issue where its not being possible to change the password in account security page

apps/meteor/app/2fa/server/code/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { EmailCheck } from './EmailCheck';
99
import type { ICodeCheck } from './ICodeCheck';
1010
import { PasswordCheckFallback } from './PasswordCheckFallback';
1111
import { TOTPCheck } from './TOTPCheck';
12+
import { normalizeHeaders } from '../../../lib/server/functions/getModifiedHttpHeaders';
1213
import { settings } from '../../../settings/server';
1314

1415
export interface ITwoFactorOptions {
@@ -184,9 +185,11 @@ export async function checkCodeForUser({ user, code, method, options = {}, conne
184185
throw new Meteor.Error('totp-user-not-found', 'TOTP User not found');
185186
}
186187

187-
if (!code && !method && connection?.httpHeaders?.['x-2fa-code'] && connection.httpHeaders['x-2fa-method']) {
188-
code = connection.httpHeaders['x-2fa-code'];
189-
method = connection.httpHeaders['x-2fa-method'];
188+
const headers = normalizeHeaders(connection?.httpHeaders);
189+
190+
if (!code && !method && headers?.['x-2fa-code'] && headers['x-2fa-method']) {
191+
code = headers['x-2fa-code'];
192+
method = headers['x-2fa-method'];
190193
}
191194

192195
if (connection && isAuthorizedForToken(connection, existingUser, options)) {

apps/meteor/app/lib/server/functions/getModifiedHttpHeaders.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
export const getModifiedHttpHeaders = (httpHeaders: Headers | Record<string, string>) => {
2-
let modifiedHttpHeaders: { [k: string]: string };
3-
1+
export const normalizeHeaders = (httpHeaders?: Headers | Record<string, string>) => {
42
if (httpHeaders instanceof Headers) {
5-
modifiedHttpHeaders = { ...Object.fromEntries(httpHeaders.entries()) };
6-
} else {
7-
modifiedHttpHeaders = { ...httpHeaders };
3+
return { ...Object.fromEntries(httpHeaders.entries()) };
84
}
95

6+
return { ...httpHeaders };
7+
};
8+
9+
export const getModifiedHttpHeaders = (httpHeaders: Headers | Record<string, string>) => {
10+
const modifiedHttpHeaders = normalizeHeaders(httpHeaders);
11+
1012
if ('x-auth-token' in modifiedHttpHeaders) {
1113
modifiedHttpHeaders['x-auth-token'] = '[redacted]';
1214
}

apps/meteor/tests/e2e/account-security.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ test.describe.serial('account-security', () => {
3838
await poAccountSecurity.toastMessage.waitForDisplay();
3939
});
4040

41-
// FIXME: This test should pass as soon as we provide the fix
42-
test.skip('should be able to change password', async ({ api }) => {
41+
test('should be able to change password', async ({ api }) => {
4342
await test.step('change password', async () => {
4443
await poAccountSecurity.changePassword(RANDOM_PASSWORD, RANDOM_PASSWORD, ADMIN_CREDENTIALS.password);
4544
await expect(poAccountSecurity.inputNewPassword).toHaveValue('');

0 commit comments

Comments
 (0)