RocketChat / RocketChat/Rocket.Chat
fix(password-policies): sanitize and validate forbidRepeatingCharactersCount before constructing RegExp
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 46.1k
- Forks
- 13.9k
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 130
Description
Summary
In @rocket.chat/password-policies, forbidRepeatingCharactersCount is directly interpolated into a RegExp string constructor without input validation or type sanitization.
Location
packages/password-policies/src/PasswordPolicy.ts (lines 80-95)
Problem Description
If forbidRepeatingCharactersCount receives an invalid option (e.g., negative values like -1, NaN, or non-integer inputs passed via settings/configuration), new RegExp('(.)\\1{-1,}') throws an uncaught SyntaxError: Invalid regular expression.
// Current Implementation:
this.regex = {
forbiddingRepeatingCharacters: new RegExp(`(.)\\1{${forbidRepeatingCharactersCount},}`),
};
Proposed Fix
Sanitize forbidRepeatingCharactersCount before constructing the regex to ensure it is a valid integer >= 1, falling back gracefully to the default count (3) if invalid:
const safeForbidRepeatingCharactersCount =
typeof forbidRepeatingCharactersCount === 'number' && Number.isInteger(forbidRepeatingCharactersCount) && forbidRepeatingCharactersCount >= 1
? forbidRepeatingCharactersCount
: 3;
this.regex = {
forbiddingRepeatingCharacters: new RegExp(`(.)\\1{${safeForbidRepeatingCharactersCount},}`),
// ...
};
Pull Request
A fix has been created locally on branch fix/password-policy-regex-validation with full unit test coverage.
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 in packages/password-policies/src/PasswordPolicy.ts at lines 80-95 and inspect how forbidRepeatingCharactersCount reaches the RegExp constructor. Validate invalid values with the stated fallback of 3, then run the package’s unit tests and confirm coverage for negative, NaN, and non-integer inputs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- security
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100