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 for #99 #100

Merged
merged 3 commits into from
Oct 5, 2021
Merged

Fix for #99 #100

merged 3 commits into from
Oct 5, 2021

Conversation

gkydev
Copy link
Contributor

@gkydev gkydev commented Oct 4, 2021

Fix #99

Always return code 200 for preventing email guessing.

Copy link
Member

@razvanilin razvanilin left a comment

Choose a reason for hiding this comment

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

Please check my comment on the code and have a think on how to change the code. Also, let me know if you don't have time to make the changes as I'd like to have this fixed asap and I know how to write the code haha

@@ -317,7 +317,7 @@ module.exports = (app) => {
})
.catch((error) => {
if (error.message === "404") {
return res.status(404).send(error);
return res.status(200).send(error);
Copy link
Member

Choose a reason for hiding this comment

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

Returning a 200 is not enough. The email can still be guessed in two ways:

  1. The data that is returned to the client differs. Look at result on line 316 and error on line 320
  2. The request will finish faster or slower depending on whether there is an error or not

So how to deal with these?

  1. Always return the same message. Something like { success: true } will do
  2. Respond to the request right away and don't wait for the userController.requestPasswordReset() promise

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for it, i understand and fixing right away

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did what you asked for but if i dont wait promises how can i return 400 in real error ?

Copy link
Member

Choose a reason for hiding this comment

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

There is no need to return an error here because this will tell the user if the email is in the system or not. So basically, someone could try out random emails to see if they have a Chartbrew account. This is a security issue.

Returning the same message all the time will stop attackers from finding valid email addresses.

Copy link
Member

@razvanilin razvanilin left a comment

Choose a reason for hiding this comment

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

Check comment

return res.status(400).send(error);
});
userController.requestPasswordReset(req.body.email)
return res.status(200).send({"success": true});
Copy link
Member

Choose a reason for hiding this comment

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

Always recommended to use a code editor that supports linting highlighting. This way you can check wether your code is respecting the guidelines of the project.

In the first line, you're missing a semicolon and the second one is missing spaces around the curly brackets.

https://app.codacy.com/gh/chartbrew/chartbrew/pullRequest?bid=25774484&prid=8190654

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Saw it and fixed thank you for explanation and your patience

Copy link
Member

@razvanilin razvanilin left a comment

Choose a reason for hiding this comment

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

Nice! looks good

Thanks for the PR

@razvanilin razvanilin merged commit 8f6712c into chartbrew:master Oct 5, 2021
@gkydev
Copy link
Contributor Author

gkydev commented Oct 5, 2021

Nice! looks good

Thanks for the PR

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Always return a generic 200 when requesting a password reset
2 participants