Repository navigation
Conversation
…t-password validator resetPassword hashes the new password through generatePasswordSaltHash, which ran the password validator with hardcoded defaults (minLength=3) — ignoring any minLength override on the collection's password field. A user could therefore reset to a password shorter than the configured minimum. Fix: look up the password TextField in collection.flattenedFields and forward its minLength and maxLength to the validator call, so reset-password enforces the same constraints as create/update. Fixes payloadcms#18823
There was a problem hiding this comment.
Thanks for picking this up! This fix currently fixes the minLength issue from the issue which is great but there is a gap.
Since we only copy minLength or maxLength from the override any other rule set still gets skipped on reset.
Every field has a validate function we can call directly instead of copying all the properties. I think a fuller solution would be to move that check into the resetPassword method before the password hash is generated.
We also need to add a regression test.
I went ahead and implemented a backport for 3.x here if you want to use that as a reference: #18980
I'll give you a small amount of time to make this fix yourself if you'd like, otherwise the patch is important enough for me to move a fix along in main separately.
|
Closing in favor of #19006 |
Same fix as #18980 (3.x), ported to `main`. Reset password now runs the collection's `password` field validation, the same as create and update do. Before this change, a `password` field override (such as `minLength: 8` or a custom `validate`) did not apply to resets, so a user could reset their password to `abc`. This is the preferred solution over #18826. That PR only passes `minLength`/`maxLength` through to the hardcoded validator, so a custom `validate` on the `password` field is still skipped. This change runs the field's own `validate` function, which covers both. Fixes #18823
resetPasswordhashes the new password throughgeneratePasswordSaltHash, which validates against a hardcoded field with nominLength. The default of 3 applies, ignoring anyminLengthset on the collection's password field override.create/updatehit the normal collection write path so field validation runs there.resetPasswordcallspayload.db.updateOnedirectly after hashing, so it never does. The result: a user can reset toabceven if the collection requires 8+ characters.Fix: look up the
passwordTextField incollection.flattenedFieldsand pass itsminLength/maxLengthto the validator call ingeneratePasswordSaltHash.ts.Fixes #18823