parse-community / parse-community/parse-server
Make passwordPolicy validatorCallback asynchronous
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 21.4k
- Forks
- 4.8k
- Avg merge
- 7h 45m
- Merged PRs (30d)
- 11
Description
New Feature / Enhancement Checklist
- Report security issues confidentially.
- Any contribution is under this license.
- Before posting search existing issues.
Current Limitation
Custom validation on passwords may include asynchronous operations, such as hitting an special endpoint. The current validator only runs synchronously.
Feature / Enhancement Description
RestWrite.js should wrap the validatorCallback invocation with await Promise.resolve(...) so that both synchronous (boolean) and asynchronous (Promise) callbacks are supported. The type declaration for validatorCallback in PasswordPolicyOptions should be updated accordingly to (password: string) => boolean | Promise<boolean>.
Also worth mentioning the typing issue in https://github.com/parse-community/parse-server/issues/10471
// Before
if (
this.config.passwordPolicy.validatorCallback &&
!this.config.passwordPolicy.validatorCallback(this.data.password)
) { ... }
// After
if (this.config.passwordPolicy.validatorCallback) {
const isValid = await Promise.resolve(
this.config.passwordPolicy.validatorCallback(this.data.password)
);
if (!isValid) {
return Promise.reject(new Parse.Error(Parse.Error.VALIDATION_ERROR, policyError));
}
}
Example Use Case
- Send a login/sign up request with a password
- Expect an asynchronous operation to happen inside the validation
Alternatives / Workarounds
Custom logic in beforePasswordResetRequest, beforeLogin and beforeSave for _User
3rd Party References
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading RestWrite.js and the PasswordPolicyOptions type declaration to trace the validatorCallback invocation and its typing. Verify that synchronous and asynchronous callbacks are both supported and that the declaration accepts Promise; check the related password-policy behavior before considering the work done.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- authentication, backend, security
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100