-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## EspoCRM had two IPv4 parsers and did not know it\n\nThe exploit path is three layers of host parsing stacked on top of each other.\n\nThe HTTP handler is `Espo\\Tools\\Attachment\\Api\\PostFromImageUrl::process` in `application/Espo/Tools/Attachment/Api/PostFromImageUrl.php`. It takes a JSON body, pulls `url`, and hands it to `UploadUrlService::uploadImage`. The first thing `uploadImage` does is gate:\n\n```php\npublic function uploadImage(string $url, FieldData $data): Attachment\n{\n if (!$this->urlCheck->isNotInternalUrl($url)) {\n throw new ForbiddenSilent(\"Not allowed URL.\");\n }\n // ...\n [$type, $contents] = $this->getImageDataByUrl($url) ?? [null, null];\n```\n\n`UrlCheck::isNotInternalUrl` extracts the host with `parse_url($url, PHP_URL_HOST)`. That is layer one. `parse_url` does not canonicalize. Feed it `http://0177.0.0.1/`, get back the literal string `0177.0.0.1`. It is a parser only in the sense of \"find the substring between `://` and `/`.\"\n\nThe string then reaches `HostCheck::isNotInternalHost` in `application/Espo/Core/Utils/Security/HostCheck.php`:\n\n```php\npublic function isNotInternalHost(string $host): bool\n{\n $records = dns_get_record($host, DNS_A);\n\n if (filter_var($host, FILTER_VALIDATE_IP)) {\n return $this->ipAddressIsNotInternal($host);\n }\n\n if (!$records) {\n return true;\n }\n\n foreach ($records as $record) {\n $idAddress = $record['ip'] ?? null;\n if (!$idAddress) {\n return false;\n }\n if (!$this->ipAddressIsNotInternal($idAddress)) {\n return false;\n }\n }\n\n return true;\n}\n```\n\nThis is layer two. The implicit model is binary: an input is either a valid IPv4 (in which case check the address) or a hostname (in which case resolve it via DNS and check the resolved addresses). `filter_var(..., FILTER_VALIDATE_IP)` is the IPv4 oracle. `dns_get_record` is the hostname oracle.\n\n`filter_var(\"0177.0.0.1\", FILTER_VALIDATE_IP)` returns `false`. Each octet must be a 1-to-3-digit decimal in the range 0 to 255; a leading zero followed by more digits is not a decimal number the filter accepts. The string is not an IPv4 in PHP's eyes.\n\n`dns_get_record(\"0177.0.0.1\", DNS_A)` returns the empty array. The string is not a valid hostname either, so no A records exist.\n\nThe function reaches the third branch: `if (!$records) { return true; }`. \"True\" here is the function's name, not its semantics. The call is `isNotInternalHost`, so a `true` return is the verdict \"yes, this is not internal, allow it.\" The gate opens.\n\n`uploadImage` then calls `getImageDataByUrl($url)`:\n\n```php\n$opts[\\CURLOPT_URL] = $url;\n$opts[\\CURLOPT_IPRESOLVE] = \\CURL_IPRESOLVE_V4;\n// ...\n$response = curl_exec($ch);\n```\n\nThis is layer three. libcurl's URL parser hands the host string to its address resolver. Before any DNS lookup, the resolver tries to treat the host as an IP literal. Its IP-literal parser is the historical BSD `inet_aton`-style parser, which accepts hex (`0x7f.0.0.1`), octal (`0177.0.0.1`), decimal dword (`2130706433`), three-part (`127.0.1`), two-part (`127.1`), and zero-padded notations. All twelve forms in the PoC's payload list resolve through this same parser:\n\n```python\nDEFAULT_LOOPBACK_PAYLOADS = [\n (\"octal dotted\", \"0177.0.0.1\"),\n (\"octal dotted padded\", \"0177.0000.0000.0001\"),\n (\"octal compressed\", \"0177.1\"),\n (\"hex dotted\", \"0x7f.0.0.1\"),\n (\"hex dotted full\", \"0x7f.0x0.0x0.0x1\"),\n (\"hex dword\", \"0x7f000001\"),\n (\"decimal dword\", \"2130706433\"),\n (\"octal dword\", \"017700000001\"),\n (\"short IPv4 two-part\", \"127.1\"),\n (\"short IPv4 three-part\", \"127.0.1\"),\n (\"zero-padded dotted\", \"127.000.000.001\"),\n (\"long zero-padded octal\", \"0000000000000000000000000177.0.0.1\"),\n]\n```\n\nEach entry is a valid IPv4 literal under one of `inet_aton`'s legacy notations. libcurl accepts every one of them and dials `127.0.0.1`.\n\nLayer two and layer three disagreed about what `0177.0.0.1` is. Layer two had no parser that could see it as an IPv4 at all. Layer three's parser was forty years old and shipped with the operating system. The same eleven characters were not-an-IP and an-IP in the same PHP request.\n\n## The gate returns true when it has no opinion\n\nThe second mechanism is one line:\n\n```php\nif (!$records) {\n return true;\n}\n```\n\nThe gate's job is to decide whether a host is internal. It has two oracles: `filter_var` for IPv4, `dns_get_record` for hostnames. When the IPv4 oracle says no and the hostname oracle returns nothing, the function does not have a third category. It treats \"I don't know what this is\" as \"not internal\" and lets the caller proceed.\n\nThis is the inverse of the choice every other branch makes. When `filter_var` says yes, the function actually examines the address. When DNS returns records, the function checks every resolved IP. The branch that decides on `!$records` is the only one in the function that returns a verdict without inspecting anything.\n\nThe patch reverses it. In 9.3.4 the new `isHostAndNotInternal` returns `false` when no IP addresses can be obtained:\n\n```php\n$ipAddresses = $this->getHostIpAddresses($host);\n\nif ($ipAddresses === []) {\n return false;\n}\n```\n\nThe default went from \"allow\" to \"deny.\" A host that survives the IPv4 check (it now does not, as we will see) and then resolves to nothing would now be rejected. The fail-open is closed by inverting one return value.\n\n## The patch adds the parser EspoCRM was already shipping\n\nThe 9.3.4 patch is structurally a refactor. The old `isNotInternalHost` is preserved as a deprecated alias; the work moves to `isHostAndNotInternal`, which delegates to two new public helpers and a new private parser.\n\nThe new parser is `normalizeIpAddress`:\n\n```php\nprivate function normalizeIpAddress(string $ip): string|false\n{\n if (!str_contains($ip, '.')) {\n return self::normalizePart($ip);\n }\n\n $parts = explode('.', $ip);\n\n if (count($parts) !== 4) {\n return false;\n }\n\n $result = [];\n\n foreach ($parts as $part) {\n if (preg_match('/^0x[0-9a-f]+$/i', $part)) {\n $num = hexdec($part);\n } else if (preg_match('/^0[0-7]+$/', $part) && $part !== '0') {\n $num = octdec($part);\n } else if (ctype_digit($part)) {\n $num = (int)$part;\n } else {\n return false;\n }\n\n if ($num < 0 || $num > 255) {\n return false;\n }\n\n $result[] = $num;\n }\n\n return implode('.', $result);\n}\n```\n\nThis is EspoCRM's `inet_aton`. It accepts hex parts (`0x7f`), octal parts (`0177`), decimal parts, four-part dotted form, and via `normalizePart` the single-token decimal/hex/octal dword. It is a reimplementation, in PHP, of the IPv4-literal parsing rules libcurl was already using.\n\nThe gate uses this new parser to reject hostnames that look like alternative IPv4 literals before the DNS path runs. From `isDomainHost`:\n\n```php\npublic function isDomainHost(string $host): bool\n{\n $normalized = $this->normalizeIpAddress($host);\n\n if ($normalized !== false && filter_var($normalized, FILTER_VALIDATE_IP)) {\n return false;\n }\n // ...\n}\n```\n\nIf `normalizeIpAddress` can turn the string into a dotted-decimal IP, the function refuses to treat it as a domain. The point of the call is not to allow the address; it is to deny the disagreement. `0177.0.0.1` is now neither an IP (for `filter_var` purposes) nor a domain (`isDomainHost` rejects it because `normalizeIpAddress` succeeds). The branch that used to fall through to `return true` is no longer reachable for any of the PoC's twelve payloads.\n\nThe fix has four moves, and each addresses the same parser gap from a different angle. The default switches from allow to deny. A new IPv4 parser names the alternative notations. A new domain check refuses inputs whose components look like numeric IP parts. The IP branch runs before the DNS branch, so the order of inspection now matches the order of action.\n\nWhat the patch did not do is unify the parser. The new `normalizeIpAddress` is not the parser libcurl uses; it is PHP code that approximates what libcurl does. The two parsers are still distinct. The two parsers are still in the same process. The fix gates the gap rather than eliminating it. This is the same shape the s3-proxy maintainer chose in [CVE-2026-42882](/posts/s3-proxy-cve-2026-42882-two-parses-one-bouncer), where the patch added a third middleware to reject the inputs where the auth and handler parses would disagree, rather than making them agree.\n\nThe shape of `normalizeIpAddress` is also a quiet admission. The function exists because `FILTER_VALIDATE_IP` does not know about hex octets, octal octets, decimal dwords, hex dwords, octal dwords, two-part addresses, three-part addresses, or zero-padded octets. Every one of those notations is in the function. The developers had to enumerate the parser they were defending against. The parser they were defending against was `inet_aton`, which has been part of the C library since 4.2BSD in 1983.\n\n## Gate before canonicalize, applied to hostnames\n\nThis is a gate-before-canonicalize bug. The gate (PHP `filter_var` plus `dns_get_record`) inspects an input for a forbidden form. A downstream subsystem (libcurl) canonicalizes the same input into that forbidden form. The check sees the wrapped representation; the action sees the unwrapped one.\n\nThe pattern's prior exhibits in URL-validation contexts each name a different parser mismatch. [CVE-2026-42596](/posts/gotenberg-cve-2026-42596-patch-removed-the-default-protection) is the IPv4-mapped-IPv6 flavor: Gotenberg's deny-list regex was written against IPv4 strings, and `[::ffff:127.0.0.1]` reaches loopback without ever matching the regex's character classes. [CVE-2026-40280](/posts/gotenberg-cve-2026-40280-named-fix-adds-the-bug) is the URL-scheme flavor: `^https?://` is byte-pattern-matched case-sensitively while Go's `net/http` dials a lowercased scheme. [CVE-2026-42260](/posts/open-websearch-cve-2026-42260-block-list-never-reached) is the bracketed-IPv6 flavor: `isIP('[::1]')` returns 0 because Node's `net.isIP` does not accept brackets, while the URL parser produces `'[::1]'` as the hostname.\n\nEspoCRM's case is the alternative-IPv4-notation flavor, and it is the cleanest of the four. The gate's parser and the action's parser are not exotic. `FILTER_VALIDATE_IP` is what every PHP developer reaches for; `inet_aton` is what every C and Unix developer has been reading hostnames through for forty years. The two have always disagreed about what an IPv4 address looks like. EspoCRM picked the strict one for its gate and shipped libcurl unchanged for its action. The disagreement was a system call away from any web request.\n\nThe host-block in 9.3.3 is also a fail-open intercept. Its job is to decide internal-or-not; its third branch decides not-internal when it cannot decide at all. The fix flips the default. Internal hosts now fail closed.\n\nThe bug is moderate-severity by every available metric. CVSS 4.3. Authenticated. Read-only. The patch landed cleanly. None of that is the story.\n\nThe story is that EspoCRM was running two IPv4 parsers, in the same process, against the same string, and the developers had only modeled one of them. The patch added PHP code that approximates what libcurl was already doing, then gated the disagreement that remains between them.\n\nPoC: [EntroVyx/CVE-2026-33534](https://github.com/EntroVyx/CVE-2026-33534)","closing_line":"The fix gates the disagreement. The parsers still disagree.","hook_md":"EspoCRM 9.3.3 ships a host-block intended to stop authenticated users from making the server fetch loopback URLs. The block runs `filter_var($host, FILTER_VALIDATE_IP)` and then `dns_get_record($host, DNS_A)`. The PoC sends `0177.0.0.1` and neither check has an opinion: it is not a dotted-decimal IPv4, and it has no A records. The function falls through to `return true`. The string then reaches libcurl, which reads `0177` as octal and connects to `127.0.0.1`.\n\nThe host check could not name `0177.0.0.1` as an IPv4 address. libcurl, inside the same PHP request, could.","post_id":354,"slug":"espocrm-cve-2026-33534-host-check-had-no-ipv4-parser","title":"CVE-2026-33534: EspoCRM's Host Check Had No IPv4 Parser. cURL Did.","type":"initial","unreadable_sentence":"The host check could not name `0177.0.0.1` as an IPv4 address. libcurl, inside the same PHP request, could."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaj7EtwAKCRDeZjl4jgkQ JmmvAP4kbuO+A7QBKlqRPt36N5+hOWZ9mGQmATRXkK+T4HvbIAD/fdy3S1LwbyUx xYrmiXJyOCJYW5gWrK0rJQds7sWv3QE= =WnuU -----END PGP SIGNATURE-----