fix: IPv4-first dialling, and a mail-less subdomain is not a broken domain
Two false results found by running the real checks, not by reading the code: example.com reported its certificate as skipped because dns.lookup returned the AAAA answer first and the local IPv6 route stalls; tools.hoelee.com reported 'Broken' email because a website-only subdomain publishes no MX, SPF or DMARC, which is normal. resolvePublic now sorts IPv4 first, and applyHostRole points such a host at its registrable apex (keeping .com.my intact). 96 tests green.
This commit is contained in:
1 parent
b2707f49f7
commit
bc29f2a963
4 files changed
+480
-2
No files matched your search
@@ -871,7 +871,55 @@ export async function check(input, { dns: resolver, lookup, now = Date.now(), ca
|
||||
void cache; // caching is the router's job; this module always reports fromCache: false
|
||||
const dnsClient = pickResolver(resolver || lookup);
|
||||
const gathered = await gather(host, dnsClient);
|
||||
return analyseMailAuth(gathered, { now });
|
||||
return applyHostRole(analyseMailAuth(gathered, { now }), host, gathered);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Host role: a subdomain with no mail setup is normal, not a broken domain
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const SECOND_LEVEL = new Set(['com', 'net', 'org', 'edu', 'gov', 'mil', 'name', 'biz', 'sch', 'co', 'ac', 'or', 'ne', 'go', 'web']);
|
||||
|
||||
/** The registrable domain: tools.hoelee.com → hoelee.com, shop.example.com.my → example.com.my. */
|
||||
export function registrableApex(host) {
|
||||
const labels = String(host).split('.');
|
||||
if (labels.length <= 2) return host;
|
||||
const tld = labels[labels.length - 1];
|
||||
const sld = labels[labels.length - 2];
|
||||
if (tld.length === 2 && SECOND_LEVEL.has(sld)) return labels.slice(-3).join('.');
|
||||
return labels.slice(-2).join('.');
|
||||
}
|
||||
|
||||
/**
|
||||
* tools.hoelee.com has no MX and no SPF because it only serves a website — the mail comes from
|
||||
* hoelee.com. Reporting that as "anyone can spoof this domain" is a false accusation against a
|
||||
* perfectly ordinary setup, so a subdomain with no mail surface at all reads as OK with a pointer
|
||||
* to the domain that actually sends the mail.
|
||||
*/
|
||||
export function applyHostRole(result, host, gathered) {
|
||||
const apex = registrableApex(host);
|
||||
if (apex === host) return result;
|
||||
if (gathered?.fatal) return result;
|
||||
const publishesNothing =
|
||||
gathered.spfRecords.length === 0 &&
|
||||
!gathered.mx.nullMx &&
|
||||
gathered.mx.records.length === 0 &&
|
||||
!gathered.dmarc.record &&
|
||||
!gathered.dkim.some((entry) => entry.key);
|
||||
if (!publishesNothing) return result;
|
||||
return {
|
||||
...result,
|
||||
state: 'ok',
|
||||
summary: `This host does not send or receive email of its own. Email for ${apex} is what matters — check ${apex}.`,
|
||||
findings: [
|
||||
{
|
||||
level: 'info',
|
||||
code: 'subdomain_no_mail',
|
||||
message: `${host} publishes no mail servers and no email records, which is normal for a subdomain that only hosts a website or an app.`,
|
||||
fix: `Check ${apex} for SPF, DKIM and DMARC — that is the domain your mail is actually sent from.`
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
export const checkMailAuth = check;
|
||||
@@ -242,7 +242,9 @@ export async function resolvePublic(host, { lookup, timeoutMs = 4000 } = {}) {
|
||||
throw new NetGuardError('private_address', 'That domain points at a private address.');
|
||||
}
|
||||
}
|
||||
return addresses;
|
||||
// Prefer IPv4. On a home connection with a broken or slow IPv6 route, dialling the AAAA answer
|
||||
// first turns a 40 ms check into a timeout, and the visitor reads "skipped" when the site is fine.
|
||||
return [...addresses].sort((a, b) => (a.family === 4 ? 0 : 1) - (b.family === 4 ? 0 : 1));
|
||||
}
|
||||
|
||||
function normaliseAnswers(answers) {
|
||||
|
||||
Reference in new issue
Block a user