
Cloud Vulnerability DB
A community-led vulnerabilities database
** 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).
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.
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.
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
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."