-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## There is no Host header parser in pre-patch psr7\n\n`Message::parseRequestUri` is the function the library calls to build a URI for an HTTP request parsed out of a raw message string. In 2.10.1, its full body is:\n\n```php\npublic static function parseRequestUri(string $path, array $headers): string\n{\n $hostKey = array_filter(array_keys($headers), function ($k) {\n $k = (string) $k;\n return strtolower($k) === 'host';\n });\n\n if (!$hostKey) {\n return $path;\n }\n\n $host = $headers[reset($hostKey)][0];\n $scheme = substr($host, -4) === ':443' ? 'https' : 'http';\n\n return $scheme.'://'.$host.'/'.ltrim($path, '/');\n}\n```\n\n`$host` is the raw value of the Host header. The function does three things with it: a substring check on the last four bytes to pick `https`, a concatenation with `://` and the path, and a return. There is no validation step. No regex. No grammar check. RFC 7230 section 5.4 defines the Host header value as `uri-host [ \":\" port ]`. The function does not enforce that grammar because the function does not read the header at any grammar.\n\n`ServerRequest::extractHostAndPortFromAuthority` is the equivalent on the inbound side, called from `getUriFromGlobals` against `$_SERVER['HTTP_HOST']`. Its 2.10.1 body is:\n\n```php\nprivate static function extractHostAndPortFromAuthority(string $authority): array\n{\n $uri = 'http://'.$authority;\n $parts = parse_url($uri);\n if (!is_array($parts)) {\n return [null, null];\n }\n\n $host = $parts['host'] ?? null;\n $port = $parts['port'] ?? null;\n\n return [$host, $port];\n}\n```\n\nThe function builds `'http://' . $authority`, hands the string to `parse_url`, and reads `host` and `port` out of the dictionary the URL parser returns. `parse_url` does not know it was given the value of a Host header. It applies the RFC 3986 URI grammar to whatever bytes follow `http://`. The RFC 3986 authority grammar is `[ userinfo \"@\" ] host [ \":\" port ]`. `parse_url` recognizes the `@` delimiter, the bracketed-IPv6 form, the multi-colon ambiguity, and a port suffix. None of these are legal in a Host header value.\n\nThe library is named psr7 and ships HTTP-message parsers. It does not contain a Host header parser. It reaches for a URL parser by pasting the header into a URL.\n\n## Two places, same paste, eight years apart\n\n`Message::parseRequestUri`'s `$scheme.'://'.$host.'/'.ltrim($path, '/')` shipped on 2015-07-08 in commit `53136e2`, as part of `_parse_request_uri` in `functions.php`. The function was lifted to a static method in 2020-09-19 by commit `ba0f9e2` (\"Extracted functions to static methods\"), renamed, and not changed in any way that touched the concatenation. The line is the same line.\n\n`ServerRequest::extractHostAndPortFromAuthority`'s `'http://'.$authority` shipped on 2018-11-01 in commit `5f5aff0`. The commit title is \"handle invalid host in getUriFromGlobals.\" The diff added the `if (false === $parts) { return [null, null]; }` guard for the case where `parse_url` returns false. The author was thinking about what happens when `parse_url` rejects the string. They were not thinking about what happens when `parse_url` accepts the string as something other than a hostname.\n\nThe pattern in both functions is the same: take the bytes of a Host header, paste them into a URL, let `parse_url` read the URL. Both functions sit inside a library that exports a `Uri` class implementing PSR-7's `UriInterface`. Downstream code that reaches `$request->getUri()->getHost()` to make a routing decision, an allowlist check, or a credential lookup reads the value `parse_url` extracted from the concatenation. The Host header itself, accessible via `$request->getHeaderLine('Host')`, is the unparsed original. The two views are guaranteed to disagree whenever the Host header contains a delimiter the URL parser recognises.\n\n## What `parse_url` does with `trusted.example@evil.example`\n\nThe 56 new test cases the patch introduces enumerate the strings the pre-patch code accepted. From `tests/MessageTest.php`:\n\n```php\npublic static function invalidHostHeaderProvider(): iterable\n{\n yield 'userinfo delimiter' => ['trusted.example@evil.example'];\n yield 'path delimiter' => ['example.com/path'];\n yield 'query delimiter' => ['example.com?query'];\n yield 'fragment delimiter' => ['example.com#fragment'];\n yield 'backslash delimiter' => ['example.com\\\\evil'];\n yield 'space' => ['bad host'];\n yield 'tab' => [\"bad\\thost\"];\n yield 'control character' => ['example'.chr(1).'com'];\n yield 'delete' => ['example'.chr(0x7F).'com'];\n yield 'multiple ports' => ['example.com:443:8443'];\n yield 'missing closing bracket' => ['[::1'];\n yield 'unexpected bracket suffix' => ['[::1]x'];\n yield 'invalid ip literal' => ['[bad]'];\n yield 'unexpected opening bracket' => ['foo[bar'];\n yield 'unexpected closing bracket' => ['foo]bar'];\n}\n```\n\nEach name in the dataProvider is the URI-authority delimiter the bytes contain. Take the userinfo case. The Host header value is `trusted.example@evil.example`. Pre-patch, `extractHostAndPortFromAuthority` writes `'http://trusted.example@evil.example'`. `parse_url` on that string returns:\n\n```php\n[\n 'scheme' => 'http',\n 'user' => 'trusted.example',\n 'host' => 'evil.example',\n]\n```\n\n`$host` is now `evil.example`. The `Uri` returned by `getUriFromGlobals` has `getHost() === 'evil.example'`. Routing logic that compares `$request->getUri()->getHost()` to an internal-host allowlist sees `evil.example`. An SSRF guard that compares against `127.0.0.1` or a corporate suffix sees `evil.example`. An HTTP client that resolves a redirect relative to `$request->getUri()` resolves against `evil.example`.\n\nThe Host header itself, on the same request object, still returns `trusted.example@evil.example`. Two parsers, two views, one request:\n\n```bash\nGET / HTTP/1.1\nHost: trusted.example@evil.example\n```\n\n```\n$request->getHeaderLine('Host') === 'trusted.example@evil.example'\n$request->getUri()->getHost() === 'evil.example'\n$request->getUri()->getUserInfo() === 'trusted.example'\n```\n\n`getHeaderLine('Host')` reads the verbatim header bytes. `getUri()->getHost()` reads the second segment of an authority the library invented by writing `'http://' . $bytes`. A defender writing the allowlist against one of these two fields is making a meaningful choice about which parser they trust. Most defenders do not know there are two.\n\n## The scheme is also picked by suffix substring\n\n`Message::parseRequestUri` compounds the bug with a second move. Before the concatenation, it runs:\n\n```php\n$scheme = substr($host, -4) === ':443' ? 'https' : 'http';\n```\n\nThe intent is to upgrade to `https` when the Host header carries a port of 443. The implementation is a substring check on the last four bytes. The substring does not know which character class produced those bytes.\n\nA Host header of `evil.example@victim.com:443` ends in `:443`. The scheme becomes `https`. The full concatenation is `https://evil.example@victim.com:443/path`. `parse_url` reads `user=evil.example`, `host=victim.com`, `port=443`, `scheme=https`. Downstream code now believes the request was for `https://victim.com:443/path`. A Host header of `evil.example:443@victim.com` also ends in `:443`. Same outcome. The substring suffix check has no model of the userinfo boundary.\n\nTwo parsers (substring suffix, then `parse_url`) read the same unparsed bytes and are guaranteed to disagree about where the host starts. Both parsers run inside the same function. Neither parser sees the result of the other one.\n\n## host-header-as-self, at the library layer\n\nThis blog has named the pattern: [Host Header As Self](/posts/airflow-aws-saml-poc-tests-wrong-endpoint). A server builds its notion of itself out of server fields and a client-supplied header, then treats the resulting string as authoritative. The Apache Airflow exhibit traced the AWS Auth Manager's `_prepare_request` reading the Host header into `request_data['http_host']`, which flowed into python3-saml's `Destination` validator, which compared a signed SAML attribute to a value the IdP and the attacker both controlled. The Starlette exhibit traced the `URL` constructor concatenating `f\"{scheme}://{host_header}{path}\"` and handing it to `urlsplit`, so middleware reading `request.url.path` saw a value the Host header could rewrite.\n\nBoth prior exhibits were applications or frameworks. CVE-2026-48998 is the same pattern one layer further down. The Airflow case used a library function (`OneLogin_Saml2_Utils.get_self_url_no_query`) that derived the server's URL from the application's `request_data['http_host']`. The Starlette case used the framework's own `URL` constructor. The guzzlehttp/psr7 case is the PSR-7 implementation underneath both. `Message::parseRequest` and `ServerRequest::fromGlobals` are the entry points every PSR-7 consumer in PHP calls when it needs to turn raw bytes into a `RequestInterface`. The `Uri` they produce is what downstream middleware reads. The library does not validate the Host header against any grammar before deciding what the URI's host is. Anything that gates on `$request->getUri()->getHost()` inherits the bypass.\n\nStarlette shipped its fix on 2026-05-21 as one regex matching valid Host headers. guzzlehttp/psr7 shipped its fix on 2026-05-25 as a static method `Rfc7230::parseHostHeader`. Four days apart, two languages, the same RFC, the same line that should have been there from the start.\n\n## The fix is the parser\n\nCommit `c68fe44` (\"Reject malformed Host authorities\") adds `Rfc7230::parseHostHeader(string $authority): ?array`. It returns `null` on inputs that the Host header grammar does not permit. `Message::parseRequestUri` calls it through a new private helper and throws `InvalidArgumentException` on `null`. `ServerRequest::fromGlobals` calls a new `removeInvalidHostHeader` helper that drops the Host header from the headers array, after which `getUriFromGlobals` falls back to `SERVER_NAME` or `SERVER_ADDR`.\n\nThe character class that rejects the bytes the pre-patch code accepted is one line inside the new validator:\n\n```php\nprivate static function isValidHostHeaderHost(string $host): bool\n{\n if (preg_match('/[\\x00-\\x20\\x7F\\/\\?#@\\\\\\\\]/', $host)) {\n return false;\n }\n ...\n}\n```\n\n`\\x00-\\x20` and `\\x7F` are control and whitespace. `/`, `?`, `#`, `@`, and `\\\\` are URI delimiters that have meaning to `parse_url` and have no meaning in the Host header production. Every character in the class is a character that, when written into `'http://' . $host`, will cause `parse_url` to interpret the bytes around it as something other than a hostname. The character class is the enumeration of the bug.\n\nThe same commit centralises the character constants `CHAR_UNRESERVED` and `CHAR_SUB_DELIMS` into a new `Rfc3986` class. The constants existed before, as private properties on `Uri`, used by the URL encoder. The fix promotes them to a shared spec object so the new Host header parser can name the same grammar the URL parser names. The library is now organised around the two RFCs it was always implementing. The pre-patch code did not name either of them.\n\n`Message::parseRequest`, `Message::parseResponse`, and `ServerRequest::fromGlobals` are documented as the high-level message parsers for the most-installed PSR-7 implementation in the PHP ecosystem. They have, since their first releases, treated the Host header as a string to be glued into a URL. The fix names the bug as a security issue in the CHANGELOG: \"Mark Host authority fix as security.\" The line in the changelog and the line that rejects `@` shipped together.\n\nPatch: [c68fe44](https://github.com/guzzle/psr7/commit/c68fe44ea6b56eb0a7ebdeb9012fb7efbc37c2d3) ยท Advisory: [GHSA-34xg-wgjx-8xph](https://github.com/advisories/GHSA-34xg-wgjx-8xph)\n","closing_line":"The fix is the parser the library never had. The bug is the ten years and ten months it shipped without one.","hook_md":"The Host header grammar in RFC 7230 is `uri-host [ \":\" port ]`. The URI authority grammar in RFC 3986 is `[ userinfo \"@\" ] host [ \":\" port ]`. The first does not contain `@`. The second does. There is no Host header parser in pre-patch guzzlehttp/psr7. There is a URL parser, which the library reaches for by writing `'http://' . $host` and handing the result to `parse_url`. CVE-2026-48998 is what `parse_url` returns when the paste produces a string whose authority section contains an `@`.","post_id":609,"slug":"guzzle-psr7-cve-2026-48998-paste-is-not-a-parse","title":"CVE-2026-48998: guzzlehttp/psr7 Pasted The Host Header Into A URL","type":"initial","unreadable_sentence":"The library reached for a URL parser by pasting the Host header into a URL."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaw8MqwAKCRDeZjl4jgkQ Jp/nAQDrWSlvB+kGBKrmc2J6uEn4AM77L+H2CyNM05SZZPWXGgD/QjMkYxvKncp7 yRTOFBD5FiqMExXjGCSHfO+E2FR6ZQU= =iMkj -----END PGP SIGNATURE-----