-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Add gmail validation to isEmail #832
Changes from 2 commits
58cd58c
c4e229e
2a0988e
4a2685e
9ad2034
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ const default_email_options = { | |
/* eslint-disable no-control-regex */ | ||
const displayName = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\.\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\,\.\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\s]*<(.+)>$/i; | ||
const emailUserPart = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i; | ||
const gmailUserPart = /^[a-z\d](\.?[a-z\d])+$/; | ||
const quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i; | ||
const emailUserUtf8Part = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i; | ||
const quotedEmailUserUtf8 = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i; | ||
|
@@ -49,6 +50,17 @@ export default function isEmail(str, options) { | |
should be done in normalizeEmail | ||
*/ | ||
user = user.toLowerCase(); | ||
|
||
// Removing sub-address from username before gmail validation | ||
const username = user.split('+')[0]; | ||
|
||
if (!isByteLength(username, { min: 6, max: 30 })) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have a source for the [6, 30] length restriction? and the alphanumeric char restriction? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't find a link in google/gmail support except for G-suite users but both length and characters restrictions can be found in Gmail sign-up page There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return false; | ||
} | ||
|
||
if (!gmailUserPart.test(username)) { | ||
return false; | ||
} | ||
} | ||
|
||
if (!isByteLength(user, { max: 64 }) || | ||
|
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably vulnerable to ReDoS. To sidestep this, we split the user part by
.
and then test each part individually. Could you set the pattern we use to/^[a-z\d]+$/i
when it's a gmail domain?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, i did put length checking before and not inside the regex to try to avoid ReDoS but testing each part individually is a better idea since i have found that dots don't count in length checking