Problem/Motivation
Currently, Drupal silently trims leading and trailing whitespace from password fields ... which probably saves many more headaches than it causes. But if a user does try, for some reason, to intentionally put a leading or trailing space in their password; the whitespace will be stripped and the password stored in the database without the spaces. However, because we also trim the inputs, the password *with* the spaces still works, so the end user has no idea that this change has taken place.
Example:
User A sets password of " abc ".
User A logs into site with " abc ", thinking they have 9 characters of entrophy.
Malicious User B comes along and brute-forces the password with "abc".
Steps to reproduce
Create a user with the password " a b c "
Try to login with that user but with the password "a b c", it works but it shouldn't
Note: spaces inside the password is working ( if you create a password " a b c " you can enter with "a b c" but not with "abc" )
Proposed resolution
Not automatically trim the password, we should either explicitly fail or warn that there is leading or trailing whitespace and disallow it, or just allow it.
Remaining tasks
Create Patch
Create Tests
Test it
Commit
User interface changes
None
API changes
Change the way we handle whitespaces in the password.
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #33 | interdiff-32-33.txt | 723 bytes | paulocs |
| #33 | 1921576-33.patch | 3.54 KB | paulocs |
| #32 | 1921576-32.patch | 3.54 KB | paulocs |
| #26 | 1921576-26.patch | 9.77 KB | quietone |
| #26 | interdiff-25-26.txt | 1.88 KB | quietone |
Issue fork drupal-1921576
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 #1
floydm commentedI verified the same behavior exists in D8. If you sign up with the password " abc ", you can log back in later with either " abc " or the trimmed string "abc".
Comment #1.0
floydm commentedUpdated issue summary.
Comment #2
charles belovIf it does no harm for the user to have entered the spaces (that is, it doesn't prevent the user from logging in) is there a reason to expose this system quirk to the user?
As long as the trimmed spaces do not contribute to a greater password complexity rating, the user will see that " abc " is not complex enough and hopefully increase the complexity of their password. (In 7.x, they do contribute, so I've filed issue #2254235 and related it to this issue.)
Alternatively, a less technical explanation would be a warning such as "Leading and trailing spaces do not improve password strength."
Comment #3
aohrvetpv commentedIt can still be misleading and give users a false sense of security. Suppose a user's password strength is already at the maximum according to the password-strength indicator*, but they add some spaces to further increase the strength of their password. Those spaces are not actually stored, against the expectation of the user.
There is another unusual behavior caused by this problem unrelated to password-strength indication: If a user attempts to save a password of all spaces, the password appears to save, yet their password remains unchanged.
* I assume the password-strength indicator has a maximum indication in D8 as it does in D7.
Comment #4
rooby commentedYes this is definitely an issue and it has caught me out in the past when I wasted a bunch of time investigating it. It gives a very strange user experience and is also a security issue of sorts.
Comment #7
dpiConfirmed issue is still valid in 8.3.x
Its probably better we don't trim whitespace: Password managers will record the whitespace. (confirmed with 1Password).
Taking the position of removing spaces means we are adding arbitrary password rules/requirements.
Perhaps spaces make a password harder to brute force because they are unexpected characters!
Comment #8
dpiComment #9
scott_euser commentedIf a site is upgrading, it already has users which potentially have their passwords trimmed from spaces; however, the users do not necessarily know it is trimmed as their input on login is also trimmed each time. I think we need to maintain that behaviour for existing sites and only apply this to fresh installs.
If I understand correctly, the config/install/* will be installed when a site is first created, but existing sites will have NULL as the password_trim_spaces value and if NULL, we can set it to TRUE to maintain the existing behaviour.
Thoughts?
Comment #10
dpiWe don't really do backwards compatibility flags in Drupal. I'd say go all in on removing trimming, or defer to next major version (9.x)
If they put spaces in it originally, then it is likely they will continue to put spaces in passwords both before and after the patch. This means there is no noticable diffference at all.
At worst, a password reset is required if they originally used spaces, but for some reason they know of this bug and stopped using spaces thereafter.
Comment #11
jibranWe should maintain the existing behavior. If not then this is a bug report. Anyway, we need functional tests for the new config and we also need upgrade path tests.
Comment #16
mlncn commentedThis is a bug as it violates people's reasonable expectations. If someone has included leading or trailing spaces in their password, they expect them to be used.
Comment #17
floydm commentedI'd venture to guess that most of the time when people include a leading or trailing space it is because they copy and pasted a password and didn't notice the space, but I have no data to support that hunch.
Comment #22
hmendes commentedComment #23
hmendes commentedComment #24
hmendes commentedComment #25
quietone commented@hmendes, thank you for updating the Issue Summary. I find that really helpful.
First, a reroll. I did make one additional change, to add password_trim_spaces to user.schema.yml because \Drupal\Tests\user\Functional\UserCancelTest::testUserCancelWithoutPermission was failing. Testing locally and the patch doesn't work, setting password_trim-spaces to false and updating config, clear cache and the password was still trimmed. But then, this is my first patch touching javascript so the reroll could be wrong anyway.
Comment #26
quietone commentedThis is working for me, although I did minimal testing. Still needs tests, plus and update test.
Comment #27
cilefen commentedIf some portion of site users won’t be able to log in, isn’t that a sort of backwards compatibility break? Ironically the behavior change would hurt the same users—those that cleverly lead or follow a pass phrase with spaces—that it tries to help.
To me, this would have to release in a major version, and it needs to be mentioned in release notes.
Comment #28
bnjmnmI think the issue summary is correct in saying the current functionality "probably saves many more headaches than it causes". I think there may be a way to preserve these benefits while addressing the concerns expressed here:
Something like this could address the concerns without being as invasive. It also doesn't require the multiple instances of conditional logic necessary to apply different behavior depending on when the user was created. From what I can see, the changes in the patch do this nicely, but an unexpected use case would impact an incredibly crucial piece of a sites functionality.
Comment #29
cilefen commentedObviously I did not read the patch over carefully! It’s a new default, but opt-in for existing sites?
Comment #31
paulocsI prefer the approach suggested in #28 because people oft add white-spaces wrongly
Comment #32
paulocsI wrote a patch with the approach proposed in #28.
It still need tests.
Comment #33
paulocsOps! I only checked JS lint.
Comment #41
oily commentedAdded test coverage. Test out leading whitespace. If that works, can use same pattern to test trailing whitespace.