Problem/Motivation
Using multibyte characters in a password results in a miscalculated length, potentially leading to passwords not meeting length constraints.
E.g. for the password abc£, strlen() returns the length 5. If the minimum password length was 5 then this password would pass even though it is only 4 characters long.
Steps to reproduce
- Set up a password policy with a length constraint.
- Use one multibyte character in a password that appears to be one character shorter than the constraint.
- Password is allowed when it shouldn't be.
Proposed resolution
- Replace
strlen()withmb_strlen()
Remaining tasks
Create test for this scenarioCreate patch implementing fix
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Issue fork password_policy-3366875
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
justanothermark commentedAdded patch which:
\Drupal\Tests\password_policy_length\Unit\PasswordLengthTest::lengthDataProvider()strlen()withmb_strlen()in\Drupal\password_policy_length\Plugin\PasswordConstraint\PasswordLength::validate()Comment #4
justanothermark commentedComment #5
alina.basarabeanu commentedChanges tested on Drupal Version 9.5.10 and Password Policy 4.0.0.
The minimum password length is set to 5 characters and aaa$ or tes£ passwords are failing the validation.
Without the patch those passwords are valid.
Comment #6
kristen polAssigning to myself as I'm reviewing/merging ready RTBC fixes/updates over the next few days.
Comment #7
kristen polLooks like we are missing a couple of places, but I can update these:
UPDATED: Looking at the code, I don't think this is necessary as it's removing zero character items from the array.
and perhaps: $blacklisted_passwords = array_filter($blacklisted_passwords, 'strlen');
Comment #8
kristen polI'll test this.
Comment #9
kristen polActually, I think I'm wrong here. Core is using
strlen:so I'll change it back and add a comment.
Comment #10
kristen polTested both min and max and it works as expected.
Since I didn't add logic, just a comment, back to RTBC. I'll get this merged.
Comment #12
kristen polThanks everyone for the help on this issue. The fix has been merged and will be part of the next release.
Comment #14
kristen polThis is part of the new 4.0.1 release.