Skip to content

Commit

Permalink
bug #24101 [Security] Fix exception when use_referer option is true a…
Browse files Browse the repository at this point in the history
…nd referer is not set or empty (linniksa)

This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #24101).

Discussion
----------

[Security] Fix exception when use_referer option is true and referer is not set or empty

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

Commits
-------

a29e069 [Security] Fix exception when use_referer option is true and referer is not set or empty
  • Loading branch information
fabpot committed Sep 7, 2017
2 parents d74144f + a29e069 commit b6a29a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Expand Up @@ -118,12 +118,11 @@ protected function determineTargetUrl(Request $request)
return $targetUrl;
}

if ($this->options['use_referer']) {
$targetUrl = $request->headers->get('Referer');
if ($this->options['use_referer'] && $targetUrl = $request->headers->get('Referer')) {
if (false !== $pos = strpos($targetUrl, '?')) {
$targetUrl = substr($targetUrl, 0, $pos);
}
if ($targetUrl !== $this->httpUtils->generateUri($request, $this->options['login_path'])) {
if ($targetUrl && $targetUrl !== $this->httpUtils->generateUri($request, $this->options['login_path'])) {
return $targetUrl;
}
}
Expand Down
Expand Up @@ -83,6 +83,16 @@ public function getRequestRedirections()
array(),
'/',
),
'target path as referer when referer not set' => array(
Request::create('/'),
array('use_referer' => true),
'/',
),
'target path as referer when referer is ?' => array(
Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => '?')),
array('use_referer' => true),
'/',
),
'target path should be different than login URL' => array(
Request::create('/', 'GET', array(), array(), array(), array('HTTP_REFERER' => 'http://localhost/login')),
array('use_referer' => true, 'login_path' => '/login'),
Expand Down

0 comments on commit b6a29a2

Please sign in to comment.