Skip to content

reset-password skips the password field's validation #18823

Closed

Description

@scottybrown

Describe the Bug

A password minimum set with the documented password field override ({ name: 'password', type: 'text', hidden: true, minLength: 8 }) is enforced when creating or updating a user, but not on reset password: through Forgot password, a user can set their password to abc and log in with it.

resetPassword (payload/dist/auth/operations/resetPassword.js) hashes the new password with generatePasswordSaltHash. That runs the password validator against a hardcoded field with no minLength, so the default of 3 applies. It then writes with payload.db.updateOne, so the collection's field validation never runs. The beforeValidate hook approach suggested in #11982 doesn't help either: on reset it runs after hashing, and data holds salt and hash but no password.

We've worked around this by patching the password validator's default minLength in payload/dist/fields/validations.js, since the reset path falls back to it.

Related: #7582 (closed). It fixed the hook running at all, but not this.

Link to the code that reproduces this issue

https://github.com/scottybrown/payload-repros/tree/repro/reset-password-skips-validation

Reproduction Steps

Copy .env.example to .env and point DATABASE_URL at an empty Postgres database.

The repro's config includes a minimal email adapter that writes each email to the server log, so the reset link can be followed.

  1. pnpm dev, open /admin, and create the first user with password longenough1.
  2. Users > Create New, with any email and password abc, then Save. It's refused with "minimum length of 8 characters", as expected ✅
  3. Log out, choose "Forgot password?", enter the first user's email and submit.
  4. Open the reset link from the email in the server log, on http://localhost:3000. The link is relative because no serverURL is set.
  5. Enter abc as the new password, confirm it, and press Reset Password.

Expected: step 5 is refused with "minimum length of 8 characters", as step 2 is.

Actual: "Password reset successfully." The user is signed in, and can log in again with abc.

Which area(s) are affected?

area: core

Environment Info

Binaries:
  Node: 22.18.0
  npm: 10.9.3
  Yarn: N/A
  pnpm: 10.14.0
Relevant Packages:
  payload: 3.91.0
  next: 16.4.0
  @payloadcms/db-postgres: 3.91.0
  @payloadcms/drizzle: 3.91.0
  @payloadcms/graphql: 3.91.0
  @payloadcms/next/utilities: 3.91.0
  @payloadcms/richtext-lexical: 3.91.0
  @payloadcms/translations: 3.91.0
  @payloadcms/ui/shared: 3.91.0
  react: 19.2.6
  react-dom: 19.2.6
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 27.0.0: Tue Aug 11 21:06:24 PDT 2026; root:xnu-13432.1.9~1/RELEASE_ARM64_T6030
  Available memory (MB): 36864
  Available CPU cores: 11

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Oct 18, 2026
  2. added
    area: core
    and removed
    validate-reproduction
    on Oct 18, 2026
  3. akshatshahh commented on Oct 19, 2026

    @akshatshahh

    I can take this. I'll validate the new password against the collection's actual password field (including its minLength override) before hashing in the reset-password path, mirroring create/update validation.

  4. lazerg commented on Oct 19, 2026

    @lazerg
    Contributor

    It is a bug, and your read of the source matches 3.x today. The reset path hashes through generatePasswordSaltHash, which validates against a bare password field, then writes with payload.db.updateOne, so your minLength never gets a say. main has the same code, so v4 doesn't fix it either.

    Until it's fixed, you can drop the dist patch and use a beforeOperation hook instead. It runs before the hashing step and still has the plain password in args.data.password:

    import { ValidationError, type CollectionBeforeOperationHook } from 'payload'
    
    export const resetPasswordMinLength: CollectionBeforeOperationHook = (hookArgs) => {
      if (hookArgs.operation === 'resetPassword' && hookArgs.args.data.password.length < 8) {
        throw new ValidationError({
          collection: hookArgs.collection.slug,
          errors: [{ message: 'Password must be at least 8 characters.', path: 'password' }],
        })
      }
    }

    Add it to hooks.beforeOperation on the users collection. Throwing there rolls back before anything is written.

  5. self-assigned this
    on Oct 22, 2026
  6. removed
    status: needs-triage
    on Oct 22, 2026
  7. added a commit that references this issue on Oct 23, 2026
    779f06f
  8. added a commit that references this issue on Oct 23, 2026
    0c74c77
  9. github-actions commented on Oct 27, 2026

    @github-actions
    Contributor

    🚀 This is included in version v4.0.0-beta.5

  10. github-actions commented on Oct 27, 2026

    @github-actions
    Contributor

    🚀 This is included in version v3.92.1

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

Metadata

Metadata

Assignees

Labels

Bugarea: corev3

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions