Skip to content

Commit 13ef0b2

Browse files
committed
fix: adds test for RequestInterface::getRequestTarget origin-form
Adds RequestIntegrationTest::testGetRequestTargetInOriginFormNormalizesUriWithMultipleLeadingSlashesInPath(), which verifies that calling `getRequestTarget()` with a URI that contains a path with multiple leading slashes normalizes those slases to a single leading slash, in order to prevent XSS attacks. Signed-off-by: Matthew Weier O'Phinney <[email protected]>
1 parent 83bfa39 commit 13ef0b2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/RequestIntegrationTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,20 @@ public function testUriPreserveHost_Host_Host()
169169
$request2 = $request->withUri($this->buildUri('http://www.bar.com/foo'), true);
170170
$this->assertEquals($host, $request2->getHeaderLine('host'));
171171
}
172+
173+
/**
174+
* @see UriIntegrationTest::testGetPathNormalizesMultipleLeadingSlashesToSingleSlashToPreventXSS
175+
*/
176+
public function testGetRequestTargetInOriginFormNormalizesUriWithMultipleLeadingSlashesInPath()
177+
{
178+
if (isset($this->skippedTests[__FUNCTION__])) {
179+
$this->markTestSkipped($this->skippedTests[__FUNCTION__]);
180+
}
181+
182+
$url = 'http://example.org//valid///path';
183+
$request = $this->request->withUri($this->buildUri($url));
184+
$requestTarget = $request->getRequestTarget();
185+
186+
$this->assertSame('/valid///path', $requestTarget);
187+
}
172188
}

0 commit comments

Comments
 (0)