Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Commit adbe113

Browse files
Merge branch '4.1' into 4.2
* 4.1: [Security\Http] detect bad redirect targets using backslashes [Form] Filter file uploads out of regular form types Fix CI minor #28258 [travis] fix composer.lock invalidation for deps=low (nicolas-grekas) [travis] fix composer.lock invalidation for PRs patching several components [travis] fix composer.lock invalidation for deps=low minor #28199 [travis][appveyor] use symfony/flex to accelerate builds (nicolas-grekas) [travis] ignore ordering when validating composer.lock files for deps=low minor #28146 [travis] cache composer.lock files for deps=low (nicolas-grekas) fix ci [travis] fix requiring mongodb/mongodb before composer up minor #28114 [travis] merge "same Symfony version" jobs in one (nicolas-grekas) [2.7] Make CI green updated VERSION for 2.7.49 updated CHANGELOG for 2.7.49 [HttpKernel] fix trusted headers management in HttpCache and InlineFragmentRenderer [HttpFoundation] Remove support for legacy and risky HTTP headers updated VERSION for 2.7.48 update CONTRIBUTORS for 2.7.48 updated CHANGELOG for 2.7.48
2 parents c53cc86 + 310b15e commit adbe113

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Http/HttpUtils.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ public function __construct(UrlGeneratorInterface $urlGenerator = null, $urlMatc
6262
*/
6363
public function createRedirectResponse(Request $request, $path, $status = 302)
6464
{
65-
if (null !== $this->secureDomainRegexp && 'https' === $this->urlMatcher->getContext()->getScheme() && preg_match('#^https?://[^/]++#i', $path, $host) && !preg_match(sprintf($this->secureDomainRegexp, preg_quote($request->getHttpHost())), $host[0])) {
65+
if (null !== $this->secureDomainRegexp && 'https' === $this->urlMatcher->getContext()->getScheme() && preg_match('#^https?:[/\\\\]{2,}+[^/]++#i', $path, $host) && !preg_match(sprintf($this->secureDomainRegexp, preg_quote($request->getHttpHost())), $host[0])) {
6666
$path = '/';
6767
}
68-
if (null !== $this->domainRegexp && preg_match('#^https?://[^/]++#i', $path, $host) && !preg_match(sprintf($this->domainRegexp, preg_quote($request->getHttpHost())), $host[0])) {
68+
if (null !== $this->domainRegexp && preg_match('#^https?:[/\\\\]{2,}+[^/]++#i', $path, $host) && !preg_match(sprintf($this->domainRegexp, preg_quote($request->getHttpHost())), $host[0])) {
6969
$path = '/';
7070
}
7171

Http/Tests/HttpUtilsTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,28 @@ public function testCreateRedirectResponseWithRequestsDomain()
5454
$this->assertTrue($response->isRedirect('http://localhost/blog'));
5555
}
5656

57-
public function testCreateRedirectResponseWithBadRequestsDomain()
57+
/**
58+
* @dataProvider badRequestDomainUrls
59+
*/
60+
public function testCreateRedirectResponseWithBadRequestsDomain($url)
5861
{
5962
$utils = new HttpUtils($this->getUrlGenerator(), null, '#^https?://%s$#i');
60-
$response = $utils->createRedirectResponse($this->getRequest(), 'http://pirate.net/foo');
63+
$response = $utils->createRedirectResponse($this->getRequest(), $url);
6164

6265
$this->assertTrue($response->isRedirect('http://localhost/'));
6366
}
6467

68+
public function badRequestDomainUrls()
69+
{
70+
return array(
71+
array('http://pirate.net/foo'),
72+
array('http:\\\\pirate.net/foo'),
73+
array('http:/\\pirate.net/foo'),
74+
array('http:\\/pirate.net/foo'),
75+
array('http://////pirate.net/foo'),
76+
);
77+
}
78+
6579
public function testCreateRedirectResponseWithProtocolRelativeTarget()
6680
{
6781
$utils = new HttpUtils($this->getUrlGenerator(), null, '#^https?://%s$#i');

0 commit comments

Comments
 (0)