Skip to content

[18.0][FIX] password_security: enforce configured per-character-class count#952

Open
kwoychesko wants to merge 1 commit into
OCA:18.0from
bpmi:18.0-fix-password_security-counts
Open

[18.0][FIX] password_security: enforce configured per-character-class count#952
kwoychesko wants to merge 1 commit into
OCA:18.0from
bpmi:18.0-fix-password_security-counts

Conversation

@kwoychesko

Copy link
Copy Markdown

Bug

The per-character-class requirements (number of lowercase / uppercase / numeric / special characters) are not enforced beyond a single character.

_check_password_rules builds the policy regex from fragments like:

"(?=.*?[A-Z]){" + str(pwd_params["upper"]) + ",}"

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:

"(?=(?:.*?[A-Z]){" + str(pwd_params["upper"]) + ",})"

i.e. (?=(?:.*?[A-Z]){2,}), which actually requires 2 occurrences.

Adds a regression test (test_check_password_enforces_class_count).

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:password_security Module password_security series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants