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()andServerRequestFactory::fromGlobals()accept the characters#,@,/and?in the host. For example, the headerHost: evil.example#good.examplegivesgetHost() === 'evil.example#good.example', but the string form of the URI ishttp://evil.example#good.example/. An allow-list that examinesgetHost()can thus accept a URI that points to a different host (CWE-20).- A client
Hostheader with port0or a port above65535causesfromGlobals()to throw anInvalidArgumentException. A non-numericX-Forwarded-Portheader from a trusted proxy has the same effect. Any client can thus cause an HTTP 500 response with one request. FilterUsingXForwardedHeadersaccepts anX-Forwarded-Hostheader that contains whitespace from a trusted proxy, butUriFactoryrejects whitespace in theHostheader.
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 3986reg-nameandIP-literalrules, and throws anInvalidArgumentExceptionfor an invalid host. Bytes0x80to0xFFstay valid for internationalized domain names.RequestTrait::withUri()andRequestTrait::getHostFromUri()validate the host withHeaderSecurity::assertValid(). This check also applies to otherUriInterfaceimplementations.Uri::createUriString()reduces the leading slashes of the path to one when the URI has no authority.UriFactory::marshalHostAndPort()ignores aHostheader with an invalid host or port, and usesSERVER_NAMEinstead.FilterUsingXForwardedHeadersignores anX-Forwarded-*value that contains whitespace, a non-numericX-Forwarded-Portvalue, and a value thatwithHost()orwithPort()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
Hostheader.
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
- slyth11907 and localhost8080 for reporting the issue.
- localhost8080 for developing the patch.
Released 2026-12-04
Have you identified a security vulnerability?
Please report it to us at security@getlaminas.org