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

Skip to content

Commit bafa8e2

Browse files
committed
feature #19026 [Security] Strengthen comparison of target_url vs login_path (mrzard)
This PR was merged into the 3.3-dev branch. Discussion ---------- [Security] Strengthen comparison of target_url vs login_path | Q | A | | --- | --- | | Branch? | "master" | | Bug fix? | no | | New feature? | no | | BC breaks? | no | | Deprecations? | no | | Tests pass? | yes | | Fixed tickets | #18862 | | License | MIT | | Doc PR | | Commits ------- ac9d75a [Security] Strengthen comparison of target_url vs login_path
2 parents 6f99837 + ac9d75a commit bafa8e2

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
@@ -139,7 +139,7 @@ public function testTargetPathIsPassedAsReferer()
139139
$this->assertSame($response, $result);
140140
}
141141

142-
public function testRefererHasToBeDifferentThatLoginUrl()
142+
public function testRefererHasToBeDifferentThanLoginUrl()
143143
{
144144
$options = array('use_referer' => true);
145145

@@ -159,6 +159,26 @@ public function testRefererHasToBeDifferentThatLoginUrl()
159159
$this->assertSame($response, $result);
160160
}
161161

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

0 commit comments

Comments
 (0)