Skip to content

Commit a4f432b

Browse files
Merge branch '6.4' into 7.0
* 6.4: Update FileProfilerStorage.php [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 [ErrorHandler] Avoid compile crash while trying to find candidate when a class is not found [Security] Make `PersistentToken` immutable and tell `TokenProviderInterface::updateToken()` implementations should accept `DateTimeInterface` do not listen to signals if the pcntl extension is missing [DependencyInjection] Improve reporting named autowiring aliases [DependencyInjection] Make better use of memory and CPU during auto-discovery 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 [TwigBundle] Allow omitting the `autoescape_service_method` option when `autoescape_service` is set to an invokable service id [PropertyAccess] Auto-cast from/to DateTime/Immutable when appropriate
2 parents 019fd93 + ef6567d commit a4f432b

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
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

RememberMe/PersistentRememberMeHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function createRememberMeCookie(UserInterface $user): void
5151
$series = random_bytes(66);
5252
$tokenValue = strtr(base64_encode(substr($series, 33)), '+/=', '-_~');
5353
$series = strtr(base64_encode(substr($series, 0, 33)), '+/=', '-_~');
54-
$token = new PersistentToken($user::class, $user->getUserIdentifier(), $series, $tokenValue, new \DateTime());
54+
$token = new PersistentToken($user::class, $user->getUserIdentifier(), $series, $tokenValue, new \DateTimeImmutable());
5555

5656
$this->tokenProvider->createNewToken($token);
5757
$this->createCookie(RememberMeDetails::fromPersistentToken($token, time() + $this->options['lifetime']));
@@ -85,7 +85,7 @@ public function consumeRememberMeCookie(RememberMeDetails $rememberMeDetails): U
8585
public function processRememberMe(RememberMeDetails $rememberMeDetails, UserInterface $user): void
8686
{
8787
[$lastUsed, $series, $tokenValue, $class] = explode(':', $rememberMeDetails->getValue(), 4);
88-
$persistentToken = new PersistentToken($class, $rememberMeDetails->getUserIdentifier(), $series, $tokenValue, new \DateTime('@'.$lastUsed));
88+
$persistentToken = new PersistentToken($class, $rememberMeDetails->getUserIdentifier(), $series, $tokenValue, new \DateTimeImmutable('@'.$lastUsed));
8989

9090
// if a token was regenerated less than a minute ago, there is no need to regenerate it
9191
// if multiple concurrent requests reauthenticate a user we do not want to update the token several times

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

Tests/RememberMe/PersistentRememberMeHandlerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function testConsumeRememberMeCookieValid()
7878
$this->tokenProvider->expects($this->any())
7979
->method('loadTokenBySeries')
8080
->with('series1')
81-
->willReturn(new PersistentToken(InMemoryUser::class, 'wouter', 'series1', 'tokenvalue', new \DateTime('-10 min')))
81+
->willReturn(new PersistentToken(InMemoryUser::class, 'wouter', 'series1', 'tokenvalue', new \DateTimeImmutable('-10 min')))
8282
;
8383

8484
$this->tokenProvider->expects($this->once())->method('updateToken')->with('series1');
@@ -106,7 +106,7 @@ public function testConsumeRememberMeCookieValidByValidatorWithoutUpdate()
106106
$verifier = $this->createMock(TokenVerifierInterface::class);
107107
$handler = new PersistentRememberMeHandler($this->tokenProvider, $this->userProvider, $this->requestStack, [], null, $verifier);
108108

109-
$persistentToken = new PersistentToken(InMemoryUser::class, 'wouter', 'series1', 'tokenvalue', new \DateTime('30 seconds'));
109+
$persistentToken = new PersistentToken(InMemoryUser::class, 'wouter', 'series1', 'tokenvalue', new \DateTimeImmutable('30 seconds'));
110110

111111
$this->tokenProvider->expects($this->any())
112112
->method('loadTokenBySeries')
@@ -133,7 +133,7 @@ public function testConsumeRememberMeCookieInvalidToken()
133133
$this->tokenProvider->expects($this->any())
134134
->method('loadTokenBySeries')
135135
->with('series1')
136-
->willReturn(new PersistentToken(InMemoryUser::class, 'wouter', 'series1', 'tokenvalue1', new \DateTime('-10 min')));
136+
->willReturn(new PersistentToken(InMemoryUser::class, 'wouter', 'series1', 'tokenvalue1', new \DateTimeImmutable('-10 min')));
137137

138138
$this->tokenProvider->expects($this->never())->method('updateToken')->with('series1');
139139

@@ -148,7 +148,7 @@ public function testConsumeRememberMeCookieExpired()
148148
$this->tokenProvider->expects($this->any())
149149
->method('loadTokenBySeries')
150150
->with('series1')
151-
->willReturn(new PersistentToken(InMemoryUser::class, 'wouter', 'series1', 'tokenvalue', new \DateTime('@'.(time() - (31536000 + 1)))));
151+
->willReturn(new PersistentToken(InMemoryUser::class, 'wouter', 'series1', 'tokenvalue', new \DateTimeImmutable('@'.(time() - (31536000 + 1)))));
152152

153153
$this->tokenProvider->expects($this->never())->method('updateToken')->with('series1');
154154

@@ -160,7 +160,7 @@ public function testBase64EncodedTokens()
160160
$this->tokenProvider->expects($this->any())
161161
->method('loadTokenBySeries')
162162
->with('series1')
163-
->willReturn(new PersistentToken(InMemoryUser::class, 'wouter', 'series1', 'tokenvalue', new \DateTime('-10 min')))
163+
->willReturn(new PersistentToken(InMemoryUser::class, 'wouter', 'series1', 'tokenvalue', new \DateTimeImmutable('-10 min')))
164164
;
165165

166166
$this->tokenProvider->expects($this->once())->method('updateToken')->with('series1');

0 commit comments

Comments
 (0)