//nefariousplan

CVE-2026-48998: guzzlehttp/psr7 Pasted The Host Header Into A URL

vendor

pattern

cve

proof of concept

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 @.

There is no Host header parser in pre-patch psr7

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:

public static function parseRequestUri(string $path, array $headers): string
{
    $hostKey = array_filter(array_keys($headers), function ($k) {
        $k = (string) $k;
        return strtolower($k) === 'host';
    });

    if (!$hostKey) {
        return $path;
    }

    $host = $headers[reset($hostKey)][0];
    $scheme = substr($host, -4) === ':443' ? 'https' : 'http';

    return $scheme.'://'.$host.'/'.ltrim($path, '/');
}

$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.

ServerRequest::extractHostAndPortFromAuthority is the equivalent on the inbound side, called from getUriFromGlobals against $_SERVER['HTTP_HOST']. Its 2.10.1 body is:

private static function extractHostAndPortFromAuthority(string $authority): array
{
    $uri = 'http://'.$authority;
    $parts = parse_url($uri);
    if (!is_array($parts)) {
        return [null, null];
    }

    $host = $parts['host'] ?? null;
    $port = $parts['port'] ?? null;

    return [$host, $port];
}

The 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.

The 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.

Two places, same paste, eight years apart

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.

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.

The 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.

What parse_url does with [email protected]

The 56 new test cases the patch introduces enumerate the strings the pre-patch code accepted. From tests/MessageTest.php:

public static function invalidHostHeaderProvider(): iterable
{
    yield 'userinfo delimiter' => ['[email protected]'];
    yield 'path delimiter' => ['example.com/path'];
    yield 'query delimiter' => ['example.com?query'];
    yield 'fragment delimiter' => ['example.com#fragment'];
    yield 'backslash delimiter' => ['example.com\\evil'];
    yield 'space' => ['bad host'];
    yield 'tab' => ["bad\thost"];
    yield 'control character' => ['example'.chr(1).'com'];
    yield 'delete' => ['example'.chr(0x7F).'com'];
    yield 'multiple ports' => ['example.com:443:8443'];
    yield 'missing closing bracket' => ['[::1'];
    yield 'unexpected bracket suffix' => ['[::1]x'];
    yield 'invalid ip literal' => ['[bad]'];
    yield 'unexpected opening bracket' => ['foo[bar'];
    yield 'unexpected closing bracket' => ['foo]bar'];
}

Each name in the dataProvider is the URI-authority delimiter the bytes contain. Take the userinfo case. The Host header value is [email protected]. Pre-patch, extractHostAndPortFromAuthority writes 'http://[email protected]'. parse_url on that string returns:

[
    'scheme' => 'http',
    'user'   => 'trusted.example',
    'host'   => 'evil.example',
]

$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.

The Host header itself, on the same request object, still returns [email protected]. Two parsers, two views, one request:

GET / HTTP/1.1
Host: [email protected]
$request->getHeaderLine('Host')     === '[email protected]'
$request->getUri()->getHost()       === 'evil.example'
$request->getUri()->getUserInfo()   === 'trusted.example'

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.

The scheme is also picked by suffix substring

Message::parseRequestUri compounds the bug with a second move. Before the concatenation, it runs:

$scheme = substr($host, -4) === ':443' ? 'https' : 'http';

The 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.

A Host header of [email protected]:443 ends in :443. The scheme becomes https. The full concatenation is https://[email protected]: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:[email protected] also ends in :443. Same outcome. The substring suffix check has no model of the userinfo boundary.

Two 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.

host-header-as-self, at the library layer

This blog has named the pattern: Host Header As Self. 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.

Both 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.

Starlette 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.

The fix is the parser

Commit 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.

The character class that rejects the bytes the pre-patch code accepted is one line inside the new validator:

private static function isValidHostHeaderHost(string $host): bool
{
    if (preg_match('/[\x00-\x20\x7F\/\?#@\\\\]/', $host)) {
        return false;
    }
    ...
}

\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.

The 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.

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.

Patch: c68fe44 · Advisory: GHSA-34xg-wgjx-8xph

The fix is the parser the library never had. The bug is the ten years and ten months it shipped without one.