Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(keys): Update key stretching to optionally use session token on password change #18317

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

vbudhram
Copy link
Contributor

@vbudhram vbudhram commented Feb 5, 2025

Because

  • Users and playwright tests might be running into the rate limit in stage and production
  • We use the customs.check request (much stricter rate limit) in password change
    • This is used in key stretching upgrades, createing recovery key, so could in theory get trigger a lot

This pull request

  • Updates the /password/change/start route to optionally use a session token and call customs.checkAuthenticated

Issue that this pull request solves

Closes: https://mozilla-hub.atlassian.net/browse/FXA-11060

Checklist

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).

Other information (Optional)

@dschom I ended up making the session token optional in the backend, but updated all the front end bits to use session token. This seems like a reasonable approach since it won't require the FxA Python client to ugrade yet. I will file some tickets with what I found while working on this.

@vbudhram vbudhram force-pushed the fxa-11060 branch 3 times, most recently from d0c140f to 929802b Compare February 6, 2025 15:27
@vbudhram vbudhram changed the title feat(keys): Update key stretching to use session token on password ch… feat(keys): Update key stretching to use session token on password change Feb 6, 2025
@vbudhram vbudhram changed the title feat(keys): Update key stretching to use session token on password change feat(keys): Update key stretching to optionally use session token on password change Feb 6, 2025
@vbudhram vbudhram self-assigned this Feb 6, 2025
@vbudhram vbudhram marked this pull request as ready for review February 6, 2025 15:35
@vbudhram vbudhram requested a review from a team as a code owner February 6, 2025 15:35
@vbudhram vbudhram requested a review from dschom February 6, 2025 17:50
@@ -95,7 +100,16 @@ module.exports = function (
const form = request.payload as { email: string; oldAuthPW: string };
const { oldAuthPW, email } = form;

await customs.check(request, email, 'passwordChange');
const sessionToken = request.auth.credentials;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be interested in recording a metric here to monitor when this endpoint is called without a sessionToken.

const mockMailer = mocks.mockMailer();
const mockLog = mocks.mockLog();
const mockRequest = mocks.mockRequest({
credentials: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't a sessionToken be passed in here? Is it getting added in some way that's not obvious? I see the customs check below, and apparently this passes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea it isn't obvious, the credentials object will exist if there is a valid session token. Normally, Hapi populates it from the authorization header, but that gets skipped when doing unit tests.

@@ -40,7 +44,7 @@ async function printMatchingKeys(startUp = false) {
}
}
} catch (error) {
console.error('Failed to retrieve keys:', error);
// Ignore errors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to suppress this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my testing it could fail to retrieve keys if not yet connected to redis. It would get called again on after the setTimeout. Figured this was fine since its only test code.

Copy link
Contributor

@dschom dschom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I like this better!

@vbudhram vbudhram merged commit 70c6ae1 into main Feb 11, 2025
24 checks passed
@vbudhram vbudhram deleted the fxa-11060 branch February 11, 2025 19:04
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants