Skip to content

fix: pass collection password field minLength/maxLength to reset-password validator - #18826

Closed
okxint wants to merge 1 commit into
payloadcms:mainfrom
okxint:fix/reset-password-field-validation
Closed

okxint wants to merge 1 commit into
payloadcms:mainfrom
okxint:fix/reset-password-field-validation

Conversation

@okxint

@okxint okxint commented Oct 19, 2026 •

Copy link
Copy Markdown

resetPassword hashes the new password through generatePasswordSaltHash, which validates against a hardcoded field with no minLength. The default of 3 applies, ignoring any minLength set on the collection's password field override.

create/update hit the normal collection write path so field validation runs there. resetPassword calls payload.db.updateOne directly after hashing, so it never does. The result: a user can reset to abc even if the collection requires 8+ characters.

Fix: look up the password TextField in collection.flattenedFields and pass its minLength/maxLength to the validator call in generatePasswordSaltHash.ts.

Fixes #18823

…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
@okxint okxint changed the title fix(auth): pass collection password field minLength/maxLength to reset-password validator fix: pass collection password field minLength/maxLength to reset-password validator Oct 19, 2026
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: payloadcms/payload/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dc9bbf12-6ecc-4d5f-a6d5-b2854c9b8e7e
📥 Commits

Reviewing files that changed from the base of the PR and between d5b01b4 and 299f57e.

📒 Files selected for processing: 1
  • packages/payload/src/auth/strategies/local/generatePasswordSaltHash.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

Unauthenticated password validation now uses the minLength and maxLength settings from the collection’s text field named password. Missing fields or limits remain undefined. Existing validation error handling is unchanged.

Changes: Password validation

Layer / File(s) Summary
Apply collection password length limits
packages/payload/src/auth/strategies/local/generatePasswordSaltHash.ts
The function finds the collection’s text field named password and passes its minLength and maxLength settings to the existing validator.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 299f5

Password resets now use the collection’s configured password length limits, while unspecified limits retain the validator’s defaults. No merge-blocking risk is established by the supplied context.

### Architecture Summary

Architecture risk: 🔵 Low · up to 299f5

The change affects 1 system.

Changed systems: packages/payload

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — packages/payload (library) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in packages/payload/src/auth/strategies/local/generatePasswordSaltHash.ts: Adds the TextField type import used to narrow the collection field when looking up password constraints.
  • observed — Modified behavior in packages/payload/src/auth/strategies/local/generatePasswordSaltHash.ts: Before validating an unauthenticated password, the function now finds the collection’s text field named password and supplies its minLength and maxLength to the existing validator. The previous validation call omitted both limits.
Pre-merge checks: Passed 5
Check name Status Explanation
Linked Issues check Passed Issue #18823 requires reset-password to enforce the collection password field's configured minimum length. The PR changes generatePasswordSaltHash to read the collection's flattened password `TextFi…
Out of Scope Changes check Passed The reported change is limited to password validation in generatePasswordSaltHash. It directly supports issue #18823 and does not indicate unrelated behavior or files.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Title check Passed The title clearly and concisely identifies the main change: passing the collection password field length limits to the reset-password validator.
Description check Passed The description directly explains the reset-password validation gap, the cause, and the implemented fix.
Full details: Linked Issues check

Explanation

Issue #18823 requires reset-password to enforce the collection password field's configured minimum length. The PR changes generatePasswordSaltHash to read the collection's flattened password TextField and pass its minLength and maxLength to password validation. This addresses the direct reset path that bypasses normal collection validation.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1 files.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use path_filters to narrow the review scope.

Comment @coderabbitai help to get the list of available commands.

@nathanlentz nathanlentz left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@okxint

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.

@nathanlentz

Copy link
Copy Markdown
Collaborator

Closing in favor of #19006

nathanlentz added a commit that referenced this pull request Oct 23, 2026
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
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.

reset-password skips the password field's validation

2 participants