Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix(csrf): Send csrf token for the /change-password path #535

Merged
merged 2 commits into from
Oct 5, 2024

Conversation

Zen-cronic
Copy link
Contributor

For #534.

A csrf-token already exists on ctx.session. But we need to pass it to validateCsrf().

Comment on lines 23 to 25
if (!safeMethods.includes(ctx.method) && !safePaths.includes(ctx.path)) {
ctx.validateCsrf();
if(ctx.path === '/change-password'){
ctx.validateCsrf(await ctx.getCsrf());
Copy link
Member

Choose a reason for hiding this comment

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

This change unfortunately doesn't really make sense. getCsrf() returns the current CSRF token, so this will always be valid.

The point of validateCsrf is to validate a token that was submitted with the request. The solution here would be to ensure that the HTML form has an <input type="hidden" name="csrf-token" value"..." /> included.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha. B/c the current form doesn't have the csrf-token value, I'll try this:

  1. Send csrf-token from the /change-password mw.
  2. Attach csrf-token in changepassword.hbs.
  3. Validate the token back in the server.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Member

Choose a reason for hiding this comment

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

Excellent!

@evert evert merged commit 683d489 into curveball:main Oct 5, 2024
12 checks passed
@evert
Copy link
Member

evert commented Oct 5, 2024

Thank you so much for this!

@Zen-cronic
Copy link
Contributor Author

no problem!

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.

2 participants