LP-2026-02: HTTP Host Header Injection and URI Validation Vulnerabilities

The package laminas/laminas-diactoros (Diactoros) is a PSR-7 HTTP Message and PSR-17 HTTP Message Factory implementation. It provides HTTP request and response messages for HTTP client requests and for server-side responses to HTTP requests. In affected versions, Uri::withHost() does not validate its argument. Also, RequestTrait copies the URI host into the Host header without a check by HeaderSecurity. Thus, a host that contains CR, LF or NUL characters goes into the Host header, although each explicit header method rejects that value.

An application can build request URIs from untrusted input and then serialize the request without changes, for example with Request\Serializer or a PSR-18 client that writes to a raw socket. In this configuration, an attacker can inject more headers into the outgoing request (CWE-93). This issue is similar to CVE-2023-29530, but the value goes into the Host header through the URI and not through withHeader(). Thus, the fix for CVE-2023-29530 does not prevent it.

The same code has these related issues:

  • A path that starts with // and has no authority becomes a scheme-relative URL, such as //evil.example/x, in the string form of the URI. PSR-7 requires that __toString() reduces the leading slashes to one. An application that removes the scheme and the host to make a local redirect target can thus send a redirect to a different site (CWE-601).
  • Uri::withHost() and ServerRequestFactory::fromGlobals() accept the characters #, @, / and ? in the host. For example, the header Host: evil.example#good.example gives getHost() === 'evil.example#good.example', but the string form of the URI is http://evil.example#good.example/. An allow-list that examines getHost() can thus accept a URI that points to a different host (CWE-20).
  • A client Host header with port 0 or a port above 65535 causes fromGlobals() to throw an InvalidArgumentException. A non-numeric X-Forwarded-Port header from a trusted proxy has the same effect. Any client can thus cause an HTTP 500 response with one request.
  • FilterUsingXForwardedHeaders accepts an X-Forwarded-Host header that contains whitespace from a trusted proxy, but UriFactory rejects whitespace in the Host header.

This vulnerability has a Medium severity (CVSS 3.1 base score 4.8: AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:N).

Affected versions

  • laminas/laminas-diactoros versions prior to 3.9.1
  • laminas/laminas-diactoros 3.10.0

Action Taken

We have made these changes:

  • Uri::withHost() validates the host against the RFC 3986 reg-name and IP-literal rules, and throws an InvalidArgumentException for an invalid host. Bytes 0x80 to 0xFF stay valid for internationalized domain names.
  • RequestTrait::withUri() and RequestTrait::getHostFromUri() validate the host with HeaderSecurity::assertValid(). This check also applies to other UriInterface implementations.
  • Uri::createUriString() reduces the leading slashes of the path to one when the URI has no authority.
  • UriFactory::marshalHostAndPort() ignores a Host header with an invalid host or port, and uses SERVER_NAME instead.
  • FilterUsingXForwardedHeaders ignores an X-Forwarded-* value that contains whitespace, a non-numeric X-Forwarded-Port value, and a value that withHost() or withPort() rejects.

Uri::withHost() now throws an exception for some values that it accepted before.

The patch that resolves the vulnerability is available in:

We highly recommend all users of the package to update immediately.

Mitigations

To mitigate this vulnerability without an update of the package, use these procedures:

  • Validate each host from untrusted input before you give it to Uri::withHost().
  • Make sure that a local redirect target does not start with //.
  • Configure the web server or the reverse proxy to reject requests with an invalid Host header.

This is an example of a host check. It accepts only ASCII host names, thus change it if your application uses IPv6 addresses or internationalized domain names:

if (preg_match('/^[a-z0-9]([a-z0-9.-]*[a-z0-9])?$/i', $host) !== 1) {
    throw new InvalidArgumentException('Invalid host');
}

$uri = $uri->withHost($host);

This is an example of a local redirect target with one leading slash:

$target = '/' . ltrim($uri->getPath(), '/');

References

This patch is also known by the following identifier:

  • GHSA-j3w3-jvjp-wgcf

Acknowledgments

The Laminas Project thanks

Released 2026-12-04

Have you identified a security vulnerability?

Please report it to us at security@getlaminas.org