Yeachan-Heo/oh-my-codex · error · Error
Invalid IPv6 prefix: ${address}
Error message
Invalid IPv6 prefix: ${address} What it means
ipv6Prefix converts an IPv6 address string to a bigint via ipv6ToBigInt; when parsing returns null (malformed address), it throws 'Invalid IPv6 prefix'. This guards IPv6 range checks (e.g. isSafeIpv6 testing IPv4-mapped/NAT ranges) from bad input.
Source
Thrown at src/url-reader/index.ts:365
if (inIpv6Range(value, ipv6Prefix("2001::"), 23)) return false; // IETF protocol assignments
if (inIpv6Range(value, ipv6Prefix("2001:db8::"), 32)) return false; // documentation/reserved
if (inIpv6Range(value, ipv6Prefix("2002::"), 16)) return false; // 6to4 transition addresses
if (inIpv6Range(value, ipv6Prefix("3fff::"), 20)) return false; // documentation/reserved
if (inIpv6Range(value, ipv6Prefix("5f00::"), 16)) return false; // segment routing SIDs
if (inIpv6Range(value, ipv6Prefix("fc00::"), 7)) return false; // unique local
if (inIpv6Range(value, ipv6Prefix("fe80::"), 10)) return false; // link local
if (inIpv6Range(value, ipv6Prefix("ff00::"), 8)) return false; // multicast
return true;
}
function ipv4FromIpv6Mapped(value: bigint): string | null {
if (!inIpv6Range(value, 0xffffn << 32n, 96)) return null;
return bigIntToIpv4(value & 0xffffffffn);
}
function ipv6Prefix(address: string): bigint {
const value = ipv6ToBigInt(address);
if (value === null) throw new Error(`Invalid IPv6 prefix: ${address}`);
return value;
}
function inIpv6Range(value: bigint, prefixValue: bigint, prefixBits: number): boolean {
const shift = BigInt(128 - prefixBits);
return value >> shift === prefixValue >> shift;
}
function bigIntToIpv4(value: bigint): string {
return [24n, 16n, 8n, 0n]
.map((shift) => Number((value >> shift) & 0xffn))
.join(".");
}
function ipv6ToBigInt(address: string): bigint | null {
let normalized = address.toLowerCase();
const zoneIndex = normalized.indexOf("%");
if (zoneIndex >= 0) normalized = normalized.slice(0, zoneIndex);View on GitHub (pinned to 3ad79a8a6f)
Solutions
- Validate/normalize the IPv6 literal before passing it (use a library or URL parsing to extract the host correctly)
- Ensure IPv6 URLs use bracket notation [::1] and strip brackets before parsing
- If input may be IPv4, branch to the IPv4 path instead of forcing IPv6 parsing
Example fix
// before
const safe = isSafeIpv6(host); // host may be '::ffff:192.168.1' (malformed)
// after
const host = url.hostname.replace(/^\[|\]$/g, '');
if (!ipv6ToBigInt(host)) throw new TypeError(`bad IPv6: ${host}`);
const safe = isSafeIpv6(host); Defensive patterns
Strategy: type-guard
Validate before calling
const v = ipv6ToBigInt(host);
if (v === null) throw new TypeError(`malformed IPv6: ${host}`); Type guard
const isParsableIpv6 = (s: string) => ipv6ToBigInt(s) !== null;
Try / catch
try { ipv6Prefix(addr); } catch (e) { if (/Invalid IPv6 prefix/.test(String(e))) return null; throw e; } Prevention
- Normalize URL hosts with brackets before parsing
- Branch IPv4 vs IPv6 inputs explicitly
When it happens
Trigger: Calling isSafeIpv6 (or ipv6Prefix directly) with a string that ipv6ToBigInt cannot parse — wrong group counts, invalid hex, stray '::', empty segments, or a bare IPv4 passed where IPv6 is expected.
Common situations: URL host parsing bugs that pass truncated IPv6 literals; missing brackets around IPv6 in URLs; configuration values like '::ffff:999.1.1.1' with malformed IPv4 tails; user-supplied addresses not pre-validated.
Related errors
- invalid auth slot path
- Autoresearch goal ${mission.slug} cannot complete until prof
- autoresearch candidate artifact must be valid JSON
- autoresearch candidate artifact notes must be a string array
- autoresearch candidate artifact created_at is required
AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27).
Data as JSON: /api/errors/8b1e50cc9228941c.
Report an issue: GitHub.