Skip to content

Commit 79689b3

Browse files
committed
Avoid DNS in recursive private hints
Keep recursive private-address hinting on a cheap hostname-only path so the failure branch does not need a second DNS-based public- URL validation pass. Also cover the obvious private-host detection with a dedicated unit test. Addresses #718 (comment) Assisted-by: Codex:gpt-5.4
1 parent 936faf6 commit 79689b3

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

packages/cli/src/lookup.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
import { url as messageUrl } from "@optique/core/message";
4747
import { path, printError } from "@optique/run";
4848
import { createWriteStream, type WriteStream } from "node:fs";
49+
import { isIP } from "node:net";
4950
import process from "node:process";
5051
import ora from "ora";
5152
import { configContext } from "./config.ts";
@@ -565,14 +566,14 @@ export function getPrivateUrlCandidate(
565566
const hostname = url.hostname;
566567
if (hostname === "localhost") return url;
567568

568-
if (/^\d+\.\d+\.\d+\.\d+$/.test(hostname)) {
569-
return isValidPublicIPv4Address(hostname) ? null : url;
570-
}
571-
572569
const normalized = hostname.startsWith("[") && hostname.endsWith("]")
573570
? hostname.slice(1, -1)
574571
: hostname;
575-
if (normalized.includes(":")) {
572+
const ipVersion = isIP(normalized);
573+
if (ipVersion === 4) {
574+
return isValidPublicIPv4Address(normalized) ? null : url;
575+
}
576+
if (ipVersion === 6) {
576577
const expanded = expandIPv6Address(normalized);
577578
return isValidPublicIPv6Address(expanded) ? null : url;
578579
}

0 commit comments

Comments
 (0)