-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Safe regex for email #22
Comments
Hi @danielmocan, Great to see you are following secure code best practices! Both email regex that you're using seem suspicious. One of the attributes of bad regexs is repeating capture groups, which you can spot in both of them. In the first one Proof of ConceptI crafted a malicious email address and used it against one of those email regexes and the result you can see below using regex101: The malicious email input is available here https://pastebin.com/Wwb4n18G Alternative solutionIf you're trying to match a common pattern like an e-mail address or an IP address then I suggest always betting on one of the existing libraries for this instead of writing your own. In our case for the JavaScript / Node.js world it would be the validator project. P.S. |
Hi @lirantal, Thank you for answering my question. I will change my problematic regex validations to use validator.js ( and see if I can add validator.js for the safe regex patterns as well ). |
Yes OWASP has great resources but validator will be a better choice for this purpose. |
I was trying out Liran`s suggestion to validate regex expressions.
I used safer-regex but I have a problem validating email regex, I even used the regex used by w3c ( /^[a-zA-Z0-9.!#$%&’+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)$/ )
I still receive false ( not safe regex ).
Does anyone have any suggestions?
The text was updated successfully, but these errors were encountered: