Skip to content

Commit 88450cd

Browse files
Mossakaclaude
andcommitted
fix: address review feedback on dns-resolver
- Remove unused DOCKER_EMBEDDED_DNS and LOCAL_STUB_RESOLVERS constants (and their eslint-disable comments) - Replace hand-rolled isValidIp with Node's net.isIP() for strict IPv4/IPv6 validation - Allow leading whitespace in resolv.conf nameserver lines - Convert dynamic import to static import in cli.ts Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4de6c65 commit 88450cd

2 files changed

Lines changed: 4 additions & 13 deletions

File tree

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { runMainWorkflow } from './cli-workflow';
2424
import { redactSecrets } from './redact-secrets';
2525
import { validateDomainOrPattern } from './domain-patterns';
2626
import { loadAndMergeDomains } from './rules';
27+
import { detectHostDnsServers } from './dns-resolver';
2728
import { OutputFormat } from './types';
2829
import { version } from '../package.json';
2930

@@ -1611,7 +1612,6 @@ program
16111612
process.exit(1);
16121613
}
16131614
} else {
1614-
const { detectHostDnsServers } = await import('./dns-resolver');
16151615
dnsServers = detectHostDnsServers(logger);
16161616
}
16171617

src/dns-resolver.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
import * as fs from 'fs';
2+
import { isIP } from 'net';
23
import { logger as defaultLogger } from './logger';
34

45
type Logger = typeof defaultLogger;
56

6-
/** Docker's embedded DNS resolver — always allowed but never used as upstream */
7-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
8-
const DOCKER_EMBEDDED_DNS = '127.0.0.11';
9-
10-
/** Local stub resolvers (systemd-resolved, dnsmasq) that can't be used inside containers */
11-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
12-
const LOCAL_STUB_RESOLVERS = ['127.0.0.1', '127.0.0.53'];
13-
147
/** Fallback when no usable resolvers are detected on the host */
158
export const DEFAULT_DNS_SERVERS = ['8.8.8.8', '8.8.4.4'];
169

@@ -21,10 +14,8 @@ export const DEFAULT_DNS_SERVERS = ['8.8.8.8', '8.8.4.4'];
2114
*/
2215
const RESOLV_CONF_PATHS = ['/run/systemd/resolve/resolv.conf', '/etc/resolv.conf'];
2316

24-
const IPV4_REGEX = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
25-
2617
function isValidIp(ip: string): boolean {
27-
return IPV4_REGEX.test(ip) || ip.includes(':');
18+
return isIP(ip) !== 0;
2819
}
2920

3021
function isLoopback(ip: string): boolean {
@@ -42,7 +33,7 @@ function isLoopback(ip: string): boolean {
4233
export function parseResolvConf(content: string): string[] {
4334
const servers: string[] = [];
4435
for (const line of content.split('\n')) {
45-
const match = line.match(/^nameserver\s+(\S+)/);
36+
const match = line.match(/^\s*nameserver\s+(\S+)/);
4637
if (match) {
4738
const ip = match[1];
4839
if (isValidIp(ip)) {

0 commit comments

Comments
 (0)