fix(auth): strip login credentials#2458
fix(auth): strip login credentials#2458ppigazzini wants to merge 1 commit intoofficial-stockfish:masterfrom
Conversation
Normalize username and password inputs during login to avoid whitespace-related auth failures.
There was a problem hiding this comment.
Pull request overview
This PR normalizes username and password inputs during login by stripping leading and trailing whitespace to prevent authentication failures caused by accidental whitespace.
Changes:
- Modified the login function to apply
.strip()to username and password inputs, aligning with the existing behavior in the signup function
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@vdbergh I have not merged yet because I'm unsure about the best practices here. GitHub login form at example strips only trail spaces and only for the username. |
|
https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html
|
We allow internal space ("aaa bbb"), but we strip username and password in signup before saving in DB. In my experience as user a login form usually does not strip the fields and reports an error if I add accidentally leading/trailing spaces. fishtest/server/fishtest/views.py Lines 400 to 411 in f7cea27 |
|
|
from that same link because your passage was about usernames
|
|
I checked the DB:
|
|
My initial reaction was that if a user wants to enter a password starting and ending with spaces then they should be allowed to do so (the user has to enter the password twice, so they are presumably aware what they are doing). Spaces are not weirder than all kinds of control characters. But then I noticed that the server strips passwords... |
|
this was only added here #1822 |
|
On the server I have not a companion script of that PR to strip the username and the password in the DB. |
|
I don't feel strongly about this. But let me say that I don't like spaces in usernames but about passwords I feel differently. |
I think Peregrine added that to the front end. But we could not do it in the back end since unfortunately there are some usernames in the userdb with spaces. And it is not trivial to fix this since these usernames appear also in the rundb and actiondb (and maybe in other collections). |
|
Concerning spaces in usernames. We could enforce "no spaces" in the schema, except for some explicit list of historical usernames (perhaps contained in the key value store). |

Normalize username and password inputs during login to avoid whitespace-related auth failures.