Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions packages/fxa-auth-server/lib/routes/password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,8 +999,15 @@ module.exports = function (
request.validateMetricsContext();

const account = await db.accountRecord(email);
if (!emailsMatch(account.primaryEmail.normalizedEmail, email)) {
throw error.cannotResetPasswordWithSecondaryEmail();

const isPrimaryOrVerifiedEmail =
emailsMatch(account.primaryEmail.normalizedEmail, email) ||
account.emails.some(
(e) => e.isVerified && emailsMatch(e.normalizedEmail, email)
);

if (!isPrimaryOrVerifiedEmail) {
throw error.unknownAccount();
}

let flowCompleteSignal;
Expand Down Expand Up @@ -1193,8 +1200,14 @@ module.exports = function (
]);
const accountRecord = await db.accountRecord(email);

if (!emailsMatch(accountRecord.primaryEmail.normalizedEmail, email)) {
throw error.cannotResetPasswordWithSecondaryEmail();
const isPrimaryOrVerifiedEmail =
emailsMatch(accountRecord.primaryEmail.normalizedEmail, email) ||
accountRecord.emails.some(
(e) => e.isVerified && emailsMatch(e.normalizedEmail, email)
);

if (!isPrimaryOrVerifiedEmail) {
throw error.unknownAccount();
}
// The token constructor sets createdAt from its argument.
// Clobber the timestamp to prevent prematurely expired tokens.
Expand Down
27 changes: 24 additions & 3 deletions packages/fxa-auth-server/test/remote/recovery_email_emails.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ const password = 'allyourbasearebelongtous';
});
});

describe("shouldn't be able to initiate account reset from secondary email", () => {
describe('should be able to initiate account reset from verified secondary email', () => {
let secondEmail;
beforeEach(() => {
secondEmail = server.uniqueEmail();
Expand All @@ -716,7 +716,28 @@ const password = 'allyourbasearebelongtous';
});
});

it('fails to initiate account reset with known secondary email', () => {
it('can initiate account reset with verified secondary email', () => {
client.email = secondEmail;
return client.forgotPassword().then(() => {
assert.ok(
client.passwordForgotToken,
'was able to initiate reset password'
);
});
});
});

describe("shouldn't be able to initiate account reset from secondary email", () => {
let secondEmail;
beforeEach(() => {
secondEmail = server.uniqueEmail();
return client.createEmail(secondEmail).then((res) => {
assert.ok(res, 'ok response');
return server.mailbox.waitForEmail(secondEmail);
});
});

it('fails to initiate account reset with unverified secondary email', () => {
client.email = secondEmail;
return client
.forgotPassword()
Expand All @@ -727,7 +748,7 @@ const password = 'allyourbasearebelongtous';
})
.catch((err) => {
assert.equal(err.code, 400, 'correct error code');
assert.equal(err.errno, 145, 'correct errno code');
assert.equal(err.errno, 102, 'correct errno code');
});
});

Expand Down