fix: improve the email domain validation by rejecting MX records pointing to unresolvable domains
Some checks failed
Deploy Next.js application / deploy (push) Failing after 23m45s
Some checks failed
Deploy Next.js application / deploy (push) Failing after 23m45s
This commit is contained in:
parent
fd015ddbc5
commit
7288e380ee
1 changed files with 18 additions and 1 deletions
|
@ -74,7 +74,24 @@ export async function POST(req: NextRequest) {
|
|||
let isEmailHostValid = false;
|
||||
try {
|
||||
const mxRecords = await dns.resolveMx(emailDomain);
|
||||
if (mxRecords.length > 0) isEmailHostValid = true;
|
||||
if (mxRecords.length > 0) {
|
||||
for (let i = 0; i < mxRecords.length; i++) {
|
||||
try {
|
||||
const aRecords = await dns.resolve4(mxRecords[i].exchange);
|
||||
if (aRecords.length > 0) {
|
||||
isEmailHostValid = true;
|
||||
break;
|
||||
}
|
||||
} catch (err) {}
|
||||
try {
|
||||
const aaaaRecords = await dns.resolve6(mxRecords[i].exchange);
|
||||
if (aaaaRecords.length > 0) {
|
||||
isEmailHostValid = true;
|
||||
break;
|
||||
}
|
||||
} catch (err) {}
|
||||
}
|
||||
}
|
||||
} catch (err) {}
|
||||
if (!isEmailHostValid) {
|
||||
return NextResponse.json(
|
||||
|
|
Loading…
Reference in a new issue