8000 [Security] Fix exception when use_referer option is true and referer … · symfony/symfony@a29e069 · GitHub
[go: up one dir, main page]

Skip to content

Commit a29e069

Browse files
linniksafabpot
authored andcommitted
[Security] Fix exception when use_referer option is true and referer is not set or empty
1 parent d74144f commit a29e069

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,11 @@ protected function determineTargetUrl(Request $request)
118118
return $targetUrl;
119119
}
120120

121-
if ($this->options['use_referer']) {
122-
$targetUrl = $request->headers->get('Referer');
121+
if ($this->options['use_referer'] && $targetUrl = $request->headers->get('Referer')) {
123122
if (false !== $pos = strpos($targetUrl, '?')) {
124123
$targetUrl = substr($targetUrl, 0, $pos);
125124
}
126-
if ($targetUrl !== $this->httpUtils->generateUri($request, $this->options['login_path'])) {
125+
if ($targetUrl && $targetUrl !== $this->httpUtils->generateUri($request, $this->options['login_path'])) {
127126
return $targetUrl;
128127
}
129128
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ public function getRequestRedirections()
8383
array(),
8484
'/',
8585
),
86+
'target path as referer when referer not set' => array(
87+
Request::create('/'),
88+
array('use_referer' => true),
89+
'/',
90+
),
91+
'target path as referer when referer is ?' => array(
92+
Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => '?')),
93+
array('use_referer' => true),
94+
'/',
95+
),
8696
'target path should be different than login URL' => array(
8797
Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/login')),
8898
array('use_referer' => true, 'login_path' => '/login'),

0 commit comments

Comments
 (0)
0