[18.0][FIX] password_security: enforce configured per-character-class count#952
Open
kwoychesko wants to merge 1 commit into
Open
[18.0][FIX] password_security: enforce configured per-character-class count#952kwoychesko wants to merge 1 commit into
kwoychesko wants to merge 1 commit into
Conversation
The per-class requirements were built as e.g. `(?=.*?[A-Z]){N,}`, which
applies the `{N,}` quantifier to a zero-width lookahead -- a no-op -- so any
value >= 1 only ever required a single matching character. Setting e.g.
Uppercase = 2 still accepted a password with one uppercase letter (same for
lowercase, numeric and special).
Move the quantifier inside the lookahead group -- `(?=(?:.*?[A-Z]){N,})` --
so the configured count is actually enforced.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
The per-character-class requirements (number of lowercase / uppercase / numeric / special characters) are not enforced beyond a single character.
_check_password_rulesbuilds the policy regex from fragments like:i.e.
(?=.*?[A-Z]){2,}. The{2,}quantifier is applied to a zero-width lookahead, which is a no-op — the engine only needs the assertion to hold once — so any configured value ≥ 1 collapses to "at least one". Setting e.g. Uppercase = 2 still accepts a password with a single uppercase letter (same for lowercase, numeric and special).Minimum length is unaffected, because there the quantifier is applied to a real character (
.{N,}$).Fix
Move the quantifier inside the lookahead group so it repeats the match:
i.e.
(?=(?:.*?[A-Z]){2,}), which actually requires 2 occurrences.Adds a regression test (
test_check_password_enforces_class_count).