nodeSolidServer / node-solid-server

Solid server on top of the file-system in NodeJS
https://solidproject.org/for-developers/pod-server
Other
1.77k stars 297 forks source link

Username leakage from password recovery when no email service setup or no useremail #1774

Closed bourgeoa closed 3 months ago

bourgeoa commented 3 months ago

This is a follow on issue#1771 We need to have allways same response when user exists/notExists

Adding (in username if (!exists)) a call to verifyEmailDependencies () https://github.com/nodeSolidServer/node-solid-server/blob/88d3a8625a590f9dfc20dc00562b886caeb03817/lib/models/account-manager.js#L535-L543

Also replacing throw error with success https://github.com/nodeSolidServer/node-solid-server/blob/88d3a8625a590f9dfc20dc00562b886caeb03817/lib/models/account-manager.js#L540-L542

with

if (userAccount && !userAccount.email) {
  return resetLinkMessage ()

fix branch created fix/issue#1774

zg009 commented 3 months ago

Also replacing throw error with success

https://github.com/nodeSolidServer/node-solid-server/blob/88d3a8625a590f9dfc20dc00562b886caeb03817/lib/models/account-manager.js#L540-L542

with

if (userAccount && !userAccount.email) {
  return resetLinkMessage ()

fix branch created fix/issue#1774

The only ways to get the resetLinkMessage() call into the AccountManager class is to either make it static from the PasswordResetEmailRequest class, copy it into the AccountManager class, or to pass the instance of PasswordResetEmailRequest class into the AccountManager class. I currently have where if it throws the Error in verifyEmailDependencies with specific message, do renderSuccess() in PasswordResetEmailRequest.loadUser if !exists

bourgeoa commented 3 months ago

Thank you for looking at this

if (userAccount && !userAccount.email) {
 return resetLinkMessage ()

This was an error You should keep the throw Error, with the check on userAccount the function will not return an Error when the username do not exist So we should have

 if (userAccount && !userAccount.email) { 
   throw new Error('Account recovery email has not been provided')
 }

And you will have simply something like

  if(!exist) {
   this.accountManager.verifyEmailDependencies() // without userAccount, this will only throw Error on `email service not setup`
   return this.resetLinkMessage() // this is the expected email sent message
  }
bourgeoa commented 3 months ago

Well there is alsoa logic issue with the 2 PRs you will have a conflict with the last merged one.

So you have the choice to keep only one PR for both issues.

Or a bit more complex

zg009 commented 3 months ago

I took the changes I made from 1770 and integrated them with this fix/issue#1774 request, so fix/issue#1770 pull request can be closed without merge as all changes are incorporated into the PR which fixes 1774, as it fixes both 1770 and 1774.