fix: ensure check returns false if no addresses are looked up, fix bug where cached value got changed accidentally

This commit is contained in:
Julian Lam
2025-06-05 11:28:47 -04:00
parent 32f13162dc
commit 6478532bf5

View File

@@ -45,7 +45,8 @@ async function init() {
* - For whatever reason `undici` needs to be required so that lookup can be overwritten properly.
*/
function lookup(hostname, options, callback) {
const { ok, lookup } = checkCache.get(hostname);
let { ok, lookup } = checkCache.get(hostname);
lookup = [...lookup];
if (!ok) {
throw new Error('lookup-failed');
}
@@ -166,6 +167,10 @@ async function check(url) {
});
}
if (addresses.size < 1) {
return { ok: false };
}
// Every IP address that the host resolves to should be a unicast address
const ok = Array.from(addresses).every(({ address: ip }) => {
const parsed = ipaddr.parse(ip);