gchq/CyberChef · error · OperationError

Invalid input. Enter either a CIDR range (e.g. 10.0.0.0/24)

Error message

Invalid input.

Enter either a CIDR range (e.g. 10.0.0.0/24) or a hyphenated range (e.g. 10.0.0.0 - 10.0.1.0). IPv6 also supported.

What it means

The Parse IP Range operation tries six regex patterns (IPv4 CIDR, IPv4 hyphenated, IPv4 list, IPv6 CIDR, IPv6 hyphenated, IPv6 list) against the input. If none match, the input does not conform to any supported IP range format.

Source

Thrown at src/core/operations/ParseIPRange.mjs:82

            ipv6CidrRegex = /^\s*(((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\4)::|:\b|(?![\dA-F])))|(?!\3\4)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\/(\d\d?\d?)\s*$/i,
            ipv6RangeRegex = /^\s*(((?=.*::)(?!.*::[^-]+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\4)::|:\b|(?![\dA-F])))|(?!\3\4)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\s*-\s*(((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\17)::|:\b|(?![\dA-F])))|(?!\16\17)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\s*$/i,
            ipv6ListRegex = /^\s*((((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\4)::|:\b|(?![\dA-F])))|(?!\3\4)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))(\/(\d\d?\d?))?(\n|$)(\n*))+\s*$/i;
        let match;

        if ((match = ipv4CidrRegex.exec(input))) {
            return ipv4CidrRange(match, includeNetworkInfo, enumerateAddresses, allowLargeList);
        } else if ((match = ipv4RangeRegex.exec(input))) {
            return ipv4HyphenatedRange(match, includeNetworkInfo, enumerateAddresses, allowLargeList);
        } else if ((match = ipv4ListRegex.exec(input))) {
            return ipv4ListedRange(match, includeNetworkInfo, enumerateAddresses, allowLargeList);
        } else if ((match = ipv6CidrRegex.exec(input))) {
            return ipv6CidrRange(match, includeNetworkInfo);
        } else if ((match = ipv6RangeRegex.exec(input))) {
            return ipv6HyphenatedRange(match, includeNetworkInfo);
        } else if ((match = ipv6ListRegex.exec(input))) {
            return ipv6ListedRange(match, includeNetworkInfo);
        } else {
            throw new OperationError("Invalid input.\n\nEnter either a CIDR range (e.g. 10.0.0.0/24) or a hyphenated range (e.g. 10.0.0.0 - 10.0.1.0). IPv6 also supported.");
        }
    }

}


export default ParseIPRange;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Use a supported format: CIDR (10.0.0.0/24), hyphenated range (10.0.0.0-10.0.1.0), or newline-separated list
  2. For IP lists, separate entries with newlines, not commas
  3. Trim surrounding whitespace and quotes from the input
  4. Ensure octets are 0-255 and CIDR prefixes are valid (0-32 for IPv4, 0-128 for IPv6)

Example fix

// before: "10.0.0.0/24, 10.0.1.0/24" (commas not supported)
// after:  "10.0.0.0/24\n10.0.1.0/24" (newline-separated list)
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check: does the input match any supported IP range format?
const patterns = [
  /^\s*((?:\d{1,3}\.){3}\d{1,3})\/(\d\d?)\s*$/,                    // IPv4 CIDR
  /^\s*((?:\d{1,3}\.){3}\d{1,3})\s*-\s*((?:\d{1,3}\.){3}\d{1,3})\s*$/, // IPv4 range
];
if (!patterns.some(re => re.test(input))) {
  throw new Error("Input does not match a supported IP range format.");
}

Try / catch

try {
  const result = chef.parseIPRange(input, [true, true, false]);
} catch (e) {
  if (/Invalid input/i.test(e.message)) {
    console.error("Use CIDR (10.0.0.0/24), hyphenated (10.0.0.0-10.0.1.0), or newline-separated list");
  } else { throw e; }
}

Prevention

When it happens

Trigger: Input contains typos in IP addresses (e.g., 10.0.0.256/24 with an octet > 255). Unsupported separators (commas instead of newlines in a list). Mixed IPv4 and IPv6 in a single range expression. CIDR prefix out of range (e.g., /33 for IPv4). Leading/trailing junk text around the address.

Common situations: User enters a comma-separated list of IPs (only newline-separated lists are supported). User enters a single IP without a range qualifier. User mixes formats. User pastes with surrounding whitespace or quotes that break the anchored regexes.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/df40b25676e2f9fb. Report an issue: GitHub.