{"record":{"id":"8b1e50cc9228941c","repo":"Yeachan-Heo/oh-my-codex","slug":"invalid-ipv6-prefix-address","errorCode":null,"errorMessage":"Invalid IPv6 prefix: ${address}","messagePattern":"Invalid IPv6 prefix: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/url-reader/index.ts","lineNumber":365,"sourceCode":"\tif (inIpv6Range(value, ipv6Prefix(\"2001::\"), 23)) return false; // IETF protocol assignments\n\tif (inIpv6Range(value, ipv6Prefix(\"2001:db8::\"), 32)) return false; // documentation/reserved\n\tif (inIpv6Range(value, ipv6Prefix(\"2002::\"), 16)) return false; // 6to4 transition addresses\n\tif (inIpv6Range(value, ipv6Prefix(\"3fff::\"), 20)) return false; // documentation/reserved\n\tif (inIpv6Range(value, ipv6Prefix(\"5f00::\"), 16)) return false; // segment routing SIDs\n\tif (inIpv6Range(value, ipv6Prefix(\"fc00::\"), 7)) return false; // unique local\n\tif (inIpv6Range(value, ipv6Prefix(\"fe80::\"), 10)) return false; // link local\n\tif (inIpv6Range(value, ipv6Prefix(\"ff00::\"), 8)) return false; // multicast\n\treturn true;\n}\n\nfunction ipv4FromIpv6Mapped(value: bigint): string | null {\n\tif (!inIpv6Range(value, 0xffffn << 32n, 96)) return null;\n\treturn bigIntToIpv4(value & 0xffffffffn);\n}\n\nfunction ipv6Prefix(address: string): bigint {\n\tconst value = ipv6ToBigInt(address);\n\tif (value === null) throw new Error(`Invalid IPv6 prefix: ${address}`);\n\treturn value;\n}\n\nfunction inIpv6Range(value: bigint, prefixValue: bigint, prefixBits: number): boolean {\n\tconst shift = BigInt(128 - prefixBits);\n\treturn value >> shift === prefixValue >> shift;\n}\n\nfunction bigIntToIpv4(value: bigint): string {\n\treturn [24n, 16n, 8n, 0n]\n\t\t.map((shift) => Number((value >> shift) & 0xffn))\n\t\t.join(\".\");\n}\n\nfunction ipv6ToBigInt(address: string): bigint | null {\n\tlet normalized = address.toLowerCase();\n\tconst zoneIndex = normalized.indexOf(\"%\");\n\tif (zoneIndex >= 0) normalized = normalized.slice(0, zoneIndex);","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/url-reader/index.ts#L347-L383","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nconst safe = isSafeIpv6(host); // host may be '::ffff:192.168.1' (malformed)\n// after\nconst host = url.hostname.replace(/^\\[|\\]$/g, '');\nif (!ipv6ToBigInt(host)) throw new TypeError(`bad IPv6: ${host}`);\nconst safe = isSafeIpv6(host);","handlingStrategy":"type-guard","validationCode":"const v = ipv6ToBigInt(host);\nif (v === null) throw new TypeError(`malformed IPv6: ${host}`);","typeGuard":"const isParsableIpv6 = (s: string) => ipv6ToBigInt(s) !== null;","tryCatchPattern":"try { ipv6Prefix(addr); } catch (e) { if (/Invalid IPv6 prefix/.test(String(e))) return null; throw e; }","preventionTips":["Normalize URL hosts with brackets before parsing","Branch IPv4 vs IPv6 inputs explicitly"],"tags":["ipv6","parsing","url","validation"],"backgroundTag":"invalid-ip-address","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}