fix(users): Enforce validation on first_name for increase security#4701
fix(users): Enforce validation on first_name for increase security#4701
Conversation
mlissner
left a comment
There was a problem hiding this comment.
One thought for you, but I might be wrong.
Thank you. :)
cl/users/forms.py
Outdated
| if not re.match( | ||
| r"""[^!"#$%&()*+,./:;<=>?@[\]_{|}~]+$""", first_name, re.IGNORECASE | ||
| ): |
There was a problem hiding this comment.
Boy, I'm rusty on regexes these days, but why not do:
| if not re.match( | |
| r"""[^!"#$%&()*+,./:;<=>?@[\]_{|}~]+$""", first_name, re.IGNORECASE | |
| ): | |
| import string | |
| if re.match(f"[{string.punctuation}]+$", first_name): |
That flips the logic, uses string.punctuation (which I think is fine?) and removes re.IGNORECASE, because I can't see how it was relevant?
There was a problem hiding this comment.
@mlissner You're absolutely right! The re.IGNORECASE flag isn't necessary here, and your suggestion is great.
Before we implement this change, I'd like to clarify one thing:
The current regex allows names with apostrophes (') and hyphens/dashes (-). If we use string.punctuation to validate names, it will flag these characters as invalid. Is that ok?
There was a problem hiding this comment.
Yeah, we should probably allow those! I didn't look too closely. Thanks for doing so!
There was a problem hiding this comment.
Wait, before we ship, we can flip the regex, remove the not, and remove the IGNORECASE, right?
There was a problem hiding this comment.
Thank you for pointing that out. I've incorporated the refactor into the latest commit
|
Nice. Set for auto-merge! |
This PR addresses a security vulnerability in the registration form. The
first_namefield was previously susceptible to Hyperlink Injection attacks. By allowing arbitrary input, malicious users could inject malicious links into the welcome email, potentially redirecting users to phishing sites or distributing malware.References:
https://hackerone.com/reports/843421
https://hackerone.com/reports/158554
https://hackerone.com/reports/164833
fixes #4687