{"record":{"id":"7503ab038bc7bcf6","repo":"gchq/CyberChef","slug":"ipv6-cidr-must-be-less-than-128","errorCode":null,"errorMessage":"IPv6 CIDR must be less than 128","messagePattern":"IPv6 CIDR must be less than 128","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/lib/IP.mjs","lineNumber":67,"sourceCode":"        }\n    }\n    return output;\n}\n\n/**\n * Parses an IPv6 CIDR range (e.g. ff00::/48) and displays information about it.\n *\n * @param {RegExp} cidr\n * @param {boolean} includeNetworkInfo\n * @returns {string}\n */\nexport function ipv6CidrRange(cidr, includeNetworkInfo) {\n    let output = \"\";\n    const network = strToIpv6(cidr[1]),\n        cidrRange = parseInt(cidr[cidr.length-1], 10);\n\n    if (cidrRange < 0 || cidrRange > 127) {\n        throw new OperationError(\"IPv6 CIDR must be less than 128\");\n    }\n\n    const ip1 = new Array(8),\n        ip2 = new Array(8),\n        total = new Array(128);\n\n    const mask = genIpv6Mask(cidrRange);\n    let totalDiff = \"\";\n\n\n    for (let i = 0; i < 8; i++) {\n        ip1[i] = network[i] & mask[i];\n        ip2[i] = ip1[i] | (~mask[i] & 0x0000FFFF);\n        totalDiff = (ip2[i] - ip1[i]).toString(2);\n\n        if (totalDiff !== \"0\") {\n            for (let n = 0; n < totalDiff.length; n++) {\n                total[i*16 + 16-(totalDiff.length-n)] = totalDiff[n];","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/IP.mjs#L49-L85","documentation":"Thrown by ipv6CidrRange when the IPv6 prefix length is outside 0-127. Mirrors the IPv4 guard: /128 (single host) and out-of-range values are rejected. OperationError.","triggerScenarios":"Calling ipv6CidrRange with a prefix group of '128', a negative value, or non-numeric input that parseInt turns into NaN/out-of-range.","commonSituations":"User supplies a /128 host address expecting a one-address range; typo such as '/129'; missing prefix yields NaN.","solutions":["Use an IPv6 prefix length of 0-127.","Treat /128 single-host addresses separately.","Validate the prefix is an integer in [0,127] before calling."],"exampleFix":"// before\nipv6CidrRange([\"ff00::/128\", \"ff00::\", \"128\"], true);\n\n// after\nipv6CidrRange([\"ff00::/48\", \"ff00::\", \"48\"], true);","handlingStrategy":"validation","validationCode":"function assertIpv6Cidr(prefix) {\n  if (!Number.isInteger(prefix) || prefix < 0 || prefix > 127) {\n    throw new Error(`IPv6 CIDR prefix must be 0-127, got ${prefix}`);\n  }\n}\nconst prefix = parseInt(match[match.length - 1], 10);\nassertIpv6Cidr(prefix);\nipv6CidrRange(match, includeNetworkInfo);","typeGuard":"const isRangeIpv6Cidr = prefix => Number.isInteger(prefix) && prefix >= 0 && prefix <= 127;","tryCatchPattern":"try {\n  ipv6CidrRange(match, includeNetworkInfo);\n} catch (err) {\n  if (err instanceof OperationError && /IPv6 CIDR must be less than 128/.test(err.message)) {\n    // /128 or out-of-range; handle as single host or correct input\n  } else throw err;\n}","preventionTips":["Remember this function rejects /128 even though it is a legal CIDR.","Validate the prefix is an integer in [0,127] before calling.","Handle single-host /128 addresses outside this function."],"tags":["ip","ipv6","cidr","validation","range"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}