Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ac9d75a

Browse files
author
Gonzalo Míguez
committed
[Security] Strengthen comparison of target_url vs login_path
1 parent e188cd7 commit ac9d75a

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected function determineTargetUrl(Request $request)
122122
return $targetUrl;
123123
}
124124

125-
if ($this->options['use_referer'] && ($targetUrl = $request->headers->get('Referer')) && $targetUrl !== $this->httpUtils->generateUri($request, $this->options['login_path'])) {
125+
if ($this->options['use_referer'] && ($targetUrl = $request->headers->get('Referer')) && parse_url($targetUrl, PHP_URL_PATH) !== $this->httpUtils->generateUri($request, $this->options['login_path'])) {
126126
return $targetUrl;
127127
}
128128

src/Symfony/Component/Security/Http/Tests/Authentication/DefaultAuthenticationSuccessHandlerTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function testTargetPathIsPassedAsReferer()
137137
$this->assertSame($response, $result);
138138
}
139139

140-
public function testRefererHasToBeDifferentThatLoginUrl()
140+
public function testRefererHasToBeDifferentThanLoginUrl()
141141
{
142142
$options = array('use_referer' => true);
143143

@@ -157,6 +157,26 @@ public function testRefererHasToBeDifferentThatLoginUrl()
157157
$this->assertSame($response, $result);
158158
}
159159

160+
public function testRefererWithoutParametersHasToBeDifferentThanLoginUrl()
161+
{
162+
$options = array('use_referer' => true);
163+
164+
$this->request->headers->expects($this->any())
165+
->method('get')->with('Referer')
166+
->will($this->returnValue('/subfolder/login?t=1&p=2'));
167+
168+
$this->httpUtils->expects($this->once())
169+
->method('generateUri')->with($this->request, '/login')
170+
->will($this->returnValue('/subfolder/login'));
171+
172+
$response = $this->expectRedirectResponse('/');
173+
174+
$handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
175+
$result = $handler->onAuthenticationSuccess($this->request, $this->token);
176+
177+
$this->assertSame($response, $result);
178+
}
179+
160180
public function testRefererTargetPathIsIgnoredByDefault()
161181
{
162182
$this->request->headers->expects($this->never())->method('get');

0 commit comments

Comments
 (0)