Skip to content

Commit 04d6b86

Browse files
Merge branch '6.2' into 6.3
* 6.2: [Security] Allow custom scheme to be used as redirection URIs [Validator] Do not mock metadata factory on debug command tests [HttpKernel][WebProfilerBundle] Fix search feature update Intl component to take into account B-variant when converting Alpha3 to Alpha2. fixing issue with Darwin. [VarDumper] Fix dumping `ArrayObject` with `DumpDataCollector` [VarDumper] Add tests to demonstrate a bug when dumping ArrayObject with full stack fmk [DebugBundle][FrameworkBundle] Fix using the framework without the Console component [FrameworkBundle] Add missing monolog channel tag to the `messenger:failed:retry` command fetch all known ChoiceType values at once [RateLimiter] fix incorrect retryAfter of FixedWindow Fix Finder phpdoc
2 parents bb42256 + d6231db commit 04d6b86

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

HttpUtils.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ public function checkRequestPath(Request $request, string $path): bool
135135
*/
136136
public function generateUri(Request $request, string $path): string
137137
{
138-
if (str_starts_with($path, 'http') || !$path) {
138+
$url = parse_url($path);
139+
140+
if ('' === $path || isset($url['scheme'], $url['host'])) {
139141
return $path;
140142
}
141143

Tests/HttpUtilsTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,54 @@ public function testCreateRedirectResponseWithRequestsDomain()
5858
$this->assertTrue($response->isRedirect('http://localhost/blog'));
5959
}
6060

61+
/**
62+
* @dataProvider validRequestDomainUrls
63+
*/
64+
public function testCreateRedirectResponse(?string $domainRegexp, string $path, string $expectedRedirectUri)
65+
{
66+
$utils = new HttpUtils($this->getUrlGenerator(), null, $domainRegexp);
67+
$response = $utils->createRedirectResponse($this->getRequest(), $path);
68+
69+
$this->assertTrue($response->isRedirect($expectedRedirectUri));
70+
$this->assertEquals(302, $response->getStatusCode());
71+
}
72+
73+
public static function validRequestDomainUrls()
74+
{
75+
return [
76+
'/foobar' => [
77+
null,
78+
'/foobar',
79+
'http://localhost/foobar',
80+
],
81+
'http://symfony.com/ without domain regex' => [
82+
null,
83+
'http://symfony.com/',
84+
'http://symfony.com/',
85+
],
86+
'http://localhost/blog with #^https?://symfony\.com$#i' => [
87+
'#^https?://symfony\.com$#i',
88+
'http://symfony.com/blog',
89+
'http://symfony.com/blog',
90+
],
91+
'http://localhost/blog with #^https?://%s$#i' => [
92+
'#^https?://%s$#i',
93+
'http://localhost/blog',
94+
'http://localhost/blog',
95+
],
96+
'custom scheme' => [
97+
null,
98+
'android-app://com.google.android.gm/',
99+
'android-app://com.google.android.gm/',
100+
],
101+
'custom scheme with all URL components' => [
102+
null,
103+
'android-app://foo:[email protected]:8080/software/index.html?lite=true#section1',
104+
'android-app://foo:[email protected]:8080/software/index.html?lite=true#section1',
105+
],
106+
];
107+
}
108+
61109
/**
62110
* @dataProvider badRequestDomainUrls
63111
*/
@@ -77,6 +125,7 @@ public static function badRequestDomainUrls()
77125
['http:/\\pirate.net/foo'],
78126
['http:\\/pirate.net/foo'],
79127
['http://////pirate.net/foo'],
128+
['http:///foo'],
80129
];
81130
}
82131

0 commit comments

Comments
 (0)