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

update_password should check password validity #1630

Merged
merged 4 commits into from Apr 27, 2023

Conversation

tschorr
Copy link
Contributor

@tschorr tschorr commented Apr 26, 2023

p.restapi is using PasswordResetTool.resetPassword for updating passwords, however this method doesn't check for password validity (https://github.com/plone/Products.CMFPlone/blame/master/Products/CMFPlone/PasswordResetTool.py#L103).
This results in Volto bypassing the default password policy. Although the minimum password length has been updated to 8 characters (plone/Products.PlonePAS#69), Volto still mentions a minimum of 5 characters (https://github.com/plone/volto/blob/master/src/components/theme/PasswordReset/PasswordReset.jsx#L54) and Plone lets you get away with this. I actually could use a 3 letter password.

@tschorr tschorr self-assigned this Apr 26, 2023
@mister-roboto
Copy link

@tschorr thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

@netlify
Copy link

netlify bot commented Apr 26, 2023

Deploy Preview for plone-restapi canceled.

Name Link
🔨 Latest commit d08753a
🔍 Latest deploy log https://app.netlify.com/sites/plone-restapi/deploys/644a1adc07891d00084a4fe6

@tschorr
Copy link
Contributor Author

tschorr commented Apr 26, 2023

@pbauer this PR will allow to use P.PasswordStrength with Volto.

@tschorr
Copy link
Contributor Author

tschorr commented Apr 26, 2023

@jenkins-plone-org please run jobs

@tschorr
Copy link
Contributor Author

tschorr commented Apr 26, 2023

Jenkins test failures look unrelated, but I might be missing something.

return self._error(
400,
"Invalid password",
_(err),
Copy link
Member

Choose a reason for hiding this comment

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

It seems that sometimes testPasswordValidity returns an already translated string, sometimes it returns a msgid. Then you need to do a test to see what is returned. This should be fixed in Plone.

Copy link
Member

Choose a reason for hiding this comment

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

uhnn but you are not passing the confirm parameter. Shouldn't you pass it here?

Copy link
Member

Choose a reason for hiding this comment

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

Another weird thing is we have an update_password in add.py. Shouldn't this be on update.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that sometimes testPasswordValidity returns an already translated string, sometimes it returns a msgid. Then you need to do a test to see what is returned. This should be fixed in Plone.

I would expect _(...) to do the right thing in any case? +1 for fixing this in the RegistrationTool.

uhnn but you are not passing the confirm parameter. Shouldn't you pass it here?

There's a sensible default and we do not have a password confirmation in this case.

Another weird thing is we have an update_password in add.py. Shouldn't this be on update.py?

Maybe, but imho that's for another ticket.

Copy link
Member

Choose a reason for hiding this comment

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

I would expect _(...) to do the right thing in any case?

It would not be as expected. RegistrationTool's _() is from the plone domain. The _() here is from the plone.restapi domain. So if testPasswordValidity returned a msgid, you would be putting a msgid from the plone domain inside a msgid from the plone.restapi domain. I don't know if that would work. Even if it didn't give an error, the domains would be different and the translation would not occur. As long as you passed the msgid received from testPasswordValidity directly to the _error method, the translation would take place. But since you are not passing the confirm, this possibility does not exist. So it's fine to stay as it is.

+1 for fixing this in the RegistrationTool

Could you please open an issue about this in Plone?

There's a sensible default and we do not have a password confirmation in this case.

In the Volto form you mentioned, we have the passwordRepeat. Is it not passed to plone.restapi? Does Volto validate if the password confirmation is ok?

Maybe, but imho that's for another ticket.

Could you please open an issue about this here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wesleybl I suggest you open the tickets yourself.

@tschorr tschorr changed the title WIP: update_password should check password validity update_password should check password validity Apr 27, 2023
@tschorr
Copy link
Contributor Author

tschorr commented Apr 27, 2023

@jenkins-plone-org please run jobs

@jensens jensens merged commit deb6770 into master Apr 27, 2023
16 of 17 checks passed
@jensens jensens deleted the tschorr_test_password_validity branch April 27, 2023 07:07
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.

None yet

4 participants