{"record":{"id":"10961c37ddd95e82","repo":"symfony/http-foundation","slug":"unable-to-check-ipv6-check-that-php-was-not-compiled-with","errorCode":null,"errorMessage":"Unable to check Ipv6. Check that PHP was not compiled with option \"disable-ipv6\".","messagePattern":"Unable to check Ipv6\\. Check that PHP was not compiled with option \"disable-ipv6\"\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"IpUtils.php","lineNumber":147,"sourceCode":"     * In case a subnet is given, it checks if it contains the request IP.\n     *\n     * @author David Soria Parra <dsp at php dot net>\n     *\n     * @see https://github.com/dsp/v6tools\n     *\n     * @param string $ip IPv6 address or subnet in CIDR notation\n     *\n     * @throws \\RuntimeException When IPV6 support is not enabled\n     */\n    public static function checkIp6(string $requestIp, string $ip): bool\n    {\n        $cacheKey = $requestIp.'-'.$ip.'-v6';\n        if (null !== $cacheValue = self::getCacheResult($cacheKey)) {\n            return $cacheValue;\n        }\n\n        if (!((\\extension_loaded('sockets') && \\defined('AF_INET6')) || @inet_pton('::1'))) {\n            throw new \\RuntimeException('Unable to check Ipv6. Check that PHP was not compiled with option \"disable-ipv6\".');\n        }\n\n        // Check to see if we were given a IP4 $requestIp or $ip by mistake\n        if (!filter_var($requestIp, \\FILTER_VALIDATE_IP, \\FILTER_FLAG_IPV6)) {\n            return self::setCacheResult($cacheKey, false);\n        }\n\n        if (str_contains($ip, '/')) {\n            [$address, $netmask] = explode('/', $ip, 2);\n\n            if (!filter_var($address, \\FILTER_VALIDATE_IP, \\FILTER_FLAG_IPV6)) {\n                return self::setCacheResult($cacheKey, false);\n            }\n\n            if ('0' === $netmask) {\n                return (bool) unpack('n*', @inet_pton($address));\n            }\n","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/symfony/http-foundation/blob/5aea19cd678fa4140f6108406f1096de5e9ed6e4/IpUtils.php#L129-L165","documentation":"IpUtils::checkIp6() needs IPv6 support to compare addresses (it ultimately relies on inet_pton / the sockets extension). If PHP was compiled with --disable-ipv6 (no AF_INET6 constant, no sockets extension, and inet_pton('::1') fails), the method cannot do its job and throws this RuntimeException instead of returning a wrong result. This is an environment-capability check, not a data validation error.","triggerScenarios":"Calling checkIp6() or checkIp() with an IPv6 address on a PHP build compiled with --disable-ipv6; running in a minimal Docker/alpine PHP image or a custom-compiled PHP without the sockets extension and without working inet_pton.","commonSituations":"Self-hosted PHP compiled without IPv6; hardened/minimal container images; CI runners with a stripped-down PHP; Symfony access-control rules (security.yaml access_control with IP ranges) evaluated on such a runtime.","solutions":["Recompile PHP with IPv6 support (drop the --disable-ipv6 configure option).","Enable/install the sockets extension (install php-sockets / compile with --enable-sockets) so AF_INET6 is defined.","Switch to an official PHP Docker image or distro package that includes IPv6 support.","Guard calls: only call checkIp6() when the request IP is IPv4, or check extension_loaded('sockets') && defined('AF_INET6') first and fail gracefully.","Upgrade to a PHP build where inet_pton supports IPv6 (verify with var_dump(@inet_pton('::1')))."],"exampleFix":"// before\n$allowed = IpUtils::checkIp($requestIp, '2001:db8::/32'); // RuntimeException on crippled PHP\n\n// after\nif (filter_var($requestIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)\n    && !\\extension_loaded('sockets') && !@inet_pton('::1')) {\n    throw new \\RuntimeException('IPv6 support missing; rebuild PHP with IPv6 enabled.');\n}\n$allowed = IpUtils::checkIp($requestIp, '2001:db8::/32');","handlingStrategy":"fallback","validationCode":"// before relying on IPv6 checks\n$ipv6Supported = (\\extension_loaded('sockets') && \\defined('AF_INET6')) || @inet_pton('::1') !== false;\nif (!$ipv6Supported) {\n    // skip IPv6 rules, use IPv4-only handling, or fail fast with a clear setup error\n}","typeGuard":"function phpSupportsIpv6(): bool {\n    return (\\extension_loaded('sockets') && \\defined('AF_INET6')) || @inet_pton('::1') !== false;\n}","tryCatchPattern":"try {\n    $ok = IpUtils::checkIp($requestIp, $allowedIps);\n} catch (\\RuntimeException $e) {\n    $logger->error('PHP lacks IPv6 support', ['exception' => $e]);\n    $ok = false; // deny or fall back to IPv4-only matching\n}","preventionTips":["Verify IPv6 support in deployment smoke tests: php -r \"var_dump(@inet_pton('::1'));\"","Use official PHP images or distro packages; never compile with --disable-ipv6.","Enable the sockets extension in your container image (php-sockets).","Gate IPv6-specific features behind a capability check at boot."],"tags":["php","ipv6","environment","runtime-configuration"],"backgroundTag":"feature-not-enabled","analyzedSha":"5aea19cd678fa4140f6108406f1096de5e9ed6e4","analyzedAt":"2026-09-13T01:52:22.855Z","contentChangedAt":"2026-09-13T01:52:22.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}