Vulnerability DatabaseGHSA-j3w3-jvjp-wgcf

GHSA-j3w3-jvjp-wgcf: 
PHP vulnerability analysis and mitigation

Summary

** I used AI to help me with this writeup, but I tried to make it as short as possible Uri::withHost() doesn't validate its argument, and RequestTrait copies the URI host into the Host header without HeaderSecurity. A host containing CR/LF therefore ends up in the Host header, although every explicit header method rejects that value. If an application builds request URIs from untrusted input and the request is serialised verbatim (e.g. Request\Serializer or a raw-socket PSR-18 client), extra headers can be injected into the outgoing request. The same code has two related issues, reported together because their fixes overlap: a path starting with // and no authority stringifies as a scheme-relative URL (//evil.example/x, an open-redirect primitive, contrary to PSR-7), and the host accepts # @ / ?, so getHost() and the URI string disagree about the host. Two minor items in the same code: invalid Host/X-Forwarded-Port values throw an uncaught exception, and X-Forwarded-Host whitespace is accepted from trusted proxies. Tested on 3.9.0. Proposed severity: Medium, CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:N (4.8).

Details

Tested on 3.9.0 (tag 3.9.0, commit 4ab9fe1), PHP 8.5.12, PHPUnit 10.5.65. I only had the 3.9.0 tag, so I haven't checked which release first had this behaviour; from the code it is probably long-standing.

  1. CR/LF/NUL in a URI host reaches the Host header (main issue) Uri::withHost() only lower-cases its argument. RequestTrait builds the Host header from the URI in initialize(), withUri() and getHostFromUri() (which feeds getHeader() and getHeaders()), and writes the value directly, without HeaderSecurity::assertValid(). So a host containing "\r\n" ends up in the Host header, although every explicit header mutator rejects that same value. This is close to GHSA-xv3h-4844-9h36 / CVE-2023-29530 (a line feed accepted at the end of a header name), but it reaches the Host header through the URI instead of through withHeader(), so that fix doesn't cover it.
  2. A // path without an authority becomes a scheme-relative URL Uri::createUriString() doesn't collapse leading slashes when the authority is empty, although PSR-7 UriInterface::__toString() says they MUST be reduced to one. getPath() already collapses them, so getPath() and the string form disagree.
  3. The host accepts gen-delims (#, @, /, ?) Both withHost() and ServerRequestFactory::fromGlobals() (from the Host header) accept them. For example, Host: evil.example#good.example gives getHost() === "evil.example#good.example", while (string) $uri is http://evil.example#good.example/. 4 and 5. Smaller items in the same code A client-supplied Host with port 0 or a port above 65535 makes fromGlobals() throw InvalidArgumentException. A trusted proxy sending a non-numeric X-Forwarded-Port has the same effect. X-Forwarded-Host containing whitespace is accepted from a trusted proxy, while UriFactory already rejects whitespace in Host. Suggested fix I have a patch against 3.9.0 (applies with git apply), which I'll post as a comment here or push to a private fork, whichever you prefer: Uri::withHost() validates the host against RFC 3986 reg-name / IP-literal (allowing bytes 0x80–0xFF for IDN) and throws InvalidArgumentException otherwise, which PSR-7 lists for invalid hostnames. The check is a new Uri::isValidHost(), marked @internal. RequestTrait::withUri() and getHostFromUri() call HeaderSecurity::assertValid() on the host. This also covers foreign UriInterface implementations. Uri::createUriString() collapses leading slashes in the path when there is no authority. UriFactory::marshalHostAndPort() ignores a Host header whose host or port is invalid and falls back to SERVER_NAME, as it already does for whitespace and commas. FilterUsingXForwardedHeaders ignores X-Forwarded-* values that contain whitespace, a non-numeric X-Forwarded-Port, or a value that withHost()/withPort() rejects. Behaviour change to consider: withHost() now throws on values it used to accept. With the patch, the existing suite shows the same failures as before, all environment-related on my machine (IANA fixture drift; UTF-8 parse_url locale on macOS). phpcs and psalm are clean. Disclosure Please request a CVE through this advisory once you've confirmed it. Proposed coordinated disclosure date: 28 January 2027. Happy to move it if you need more time or can release earlier. I also have a few unrelated, lower-impact hardening fixes for other parts of the package, which I'll send as normal public pull requests. Anything that touches the code above, or would point to it, will wait until this advisory is public.

Proof of concept

Install laminas/laminas-diactoros 3.9.0 with Composer and run this script. Output observed on 3.9.0 is in the comments. <?php require 'vendor/autoload.php'; use Laminas\Diactoros\Request; use Laminas\Diactoros\Request\Serializer; use Laminas\Diactoros\ServerRequestFactory; use Laminas\Diactoros\Uri; // (1) "GET / HTTP/1.1\r\nHost: a.example\r\nx-injected: 1" $request = (new Request('http://a.example/')) ->withUri((new Uri('http://a.example/'))->withHost("a.example\r\nX-Injected: 1")); echo json_encode(Serializer::toString($request)), "\n"; // (2) "//evil.example/x" echo (new Uri('https://good.example//evil.example/x'))->withScheme('')->withHost(''), "\n"; // (3) "evil.example#good.example | http://evil.example#good.example/ | evil.example" $uri = (new Uri('http://placeholder/'))->withHost('evil.example#good.example'); echo $uri->getHost(), ' | ', $uri, ' | ', parse_url((string) $uri, PHP_URL_HOST), "\n"; // (4) InvalidArgumentException: Invalid port "0" specified; must be a valid TCP/UDP port ServerRequestFactory::fromGlobals( ['HTTP_HOST' => 'example.com:0', 'REQUEST_URI' => '/', 'REMOTE_ADDR' => '203.0.113.1'] ); ?>


The patch also adds PHPUnit tests under test/Security/. These fail on 3.9.0 and pass with the fix: HostHeaderInjectionTest::testWithUriDoesNotPlaceControlCharactersIntoHostHeader (3 data sets) HostHeaderInjectionTest::testConstructorDoesNotPlaceControlCharactersIntoHostHeader (3) HostHeaderInjectionTest::testServerRequestConstructorDoesNotPlaceControlCharactersIntoHostHeader UriSecurityTest::testStringFormOfUriWithoutAuthorityCollapsesLeadingSlashes UriSecurityTest::testRemovingAuthorityDoesNotTurnPathIntoAuthority UriSecurityTest::testFromGlobalsWithoutHostDoesNotTreatDoubleSlashPathAsAuthority UriSecurityTest::testWithHostRejectsOrEncodesGenDelims (4) ServerRequestFromGlobalsSecurityTest::testInvalidHostHeaderDoesNotProduceAmbiguousUri (4 of 6 sets) ServerRequestFromGlobalsSecurityTest::testOutOfRangePortInHostHeaderDoesNotThrow (2) ServerRequestFromGlobalsSecurityTest::testInvalidForwardedPortFromTrustedProxyDoesNotThrow (3) ServerRequestFromGlobalsSecurityTest::testForwardedHostWithWhitespaceIsIgnoredLikeHostHeader The same files also contain tests for existing defences, which pass before and after the patch.

Impact

Applications using laminas-diactoros are affected when they build request URIs or handle incoming requests in the ways below. Each item depends on how the application uses the library. Header injection in outbound requests (CWE-93). Needs both: the application passes attacker-influenced data to Uri::withHost(), or uses a third-party UriInterface that doesn't validate the host. URI strings are not a vector: parse_url() replaces or rejects control characters; the request is serialised by something that writes header values verbatim, for example Request\Serializer or a raw-socket PSR-18 client. Typical places are webhook or "fetch this URL" features that build URIs from parts. Possible results are injected request headers, or request smuggling against the upstream. I didn't test real HTTP clients (curl, Guzzle, Symfony HttpClient); some may reject CR/LF themselves, so real-world exploitability depends on the transport. Open redirect (CWE-601). Applications that strip the scheme and host to build a "local" redirect target can emit //evil.example/x, which a browser follows off-site. Host confusion (CWE-20). Allow-lists that check getHost() (e.g. str_ends_with($host, 'good.example')) can be bypassed while the URI string points elsewhere. Whether such a Host header reaches PHP depends on the front-end server: PHP's built-in server passes it through; I didn't test nginx or Apache. Uncaught exception (CWE-20). Any client can trigger an HTTP 500 with one request. No amplification. Forwarded-header whitespace. Trusted-proxy input only. Proposed severity: Medium, CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:N (4.8). Reachable over the network without authentication, but AC:H because the application must pass untrusted data to withHost() and the transport must write header values verbatim. Please adjust if you assess it differently.


Source: NVD

Related PHP vulnerabilities:

CVE ID

Severity

Score

Technologies

Component name

CISA KEV exploit

Has fix

Published date

CVE-2026-45262CRITICAL9.9
  • PHP logoPHP
  • facturascripts/facturascripts
NoYesDec 04, 2026
CVE-2026-47677CRITICAL9.3
  • PHP logoPHP
  • facturascripts/facturascripts
NoYesDec 04, 2026
CVE-2026-45263HIGH8
  • PHP logoPHP
  • facturascripts/facturascripts
NoYesDec 04, 2026
CVE-2026-45693HIGH7.5
  • PHP logoPHP
  • facturascripts/facturascripts
NoNoDec 04, 2026
GHSA-j3w3-jvjp-wgcfMEDIUM4.8
  • PHP logoPHP
  • laminas/laminas-diactoros
NoNoDec 04, 2026

Free Vulnerability Assessment

Benchmark your Cloud Security Posture

Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.

Request assessment

Additional Wiz resources

Get a personalized demo

Ready to see Wiz in action?

"Best User Experience I have ever seen, provides full visibility to cloud workloads."
David EstlickCISO
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
Adam FletcherChief Security Officer
"We know that if Wiz identifies something as critical, it actually is."
Greg PoniatowskiHead of Threat and Vulnerability Management