diff options
author | Andreas Fischer <bantu@owncloud.com> | 2014-07-19 02:06:37 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-07-22 15:40:50 +0200 |
commit | e8be18a8d871792c95ea9983db392c4cce2ac5b1 (patch) | |
tree | 53ed192473f55bc7c7192067d1032ee9f0a8e6c8 | |
parent | 3a27cc5221f54c85c0d157eba17c0ffca6784bce (diff) | |
download | nextcloud-server-e8be18a8d871792c95ea9983db392c4cce2ac5b1.tar.gz nextcloud-server-e8be18a8d871792c95ea9983db392c4cce2ac5b1.zip |
Deduplicate user/password extraction from alternative HTTP headers.
-rw-r--r-- | lib/base.php | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/lib/base.php b/lib/base.php index 3c06cc194ad..9c2f4c180ea 100644 --- a/lib/base.php +++ b/lib/base.php @@ -487,22 +487,20 @@ class OC { $_SERVER['HTTP_AUTHORIZATION'] = $_SERVER['HTTP_XAUTHORIZATION']; } - //set http auth headers for apache+php-cgi work around - if (isset($_SERVER['HTTP_AUTHORIZATION']) - && preg_match('/Basic\s+(.*)$/i', $_SERVER['HTTP_AUTHORIZATION'], $matches) - ) { - list($name, $password) = explode(':', base64_decode($matches[1]), 2); - $_SERVER['PHP_AUTH_USER'] = strip_tags($name); - $_SERVER['PHP_AUTH_PW'] = strip_tags($password); - } - - //set http auth headers for apache+php-cgi work around if variable gets renamed by apache - if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) - && preg_match('/Basic\s+(.*)$/i', $_SERVER['REDIRECT_HTTP_AUTHORIZATION'], $matches) - ) { - list($name, $password) = explode(':', base64_decode($matches[1]), 2); - $_SERVER['PHP_AUTH_USER'] = strip_tags($name); - $_SERVER['PHP_AUTH_PW'] = strip_tags($password); + // Extract PHP_AUTH_USER/PHP_AUTH_PW from other headers if necessary. + $httpAuthHeaderServerVars = array( + 'HTTP_AUTHORIZATION', // apache+php-cgi work around + 'REDIRECT_HTTP_AUTHORIZATION', // apache+php-cgi alternative + ); + foreach ($httpAuthHeaderServerVars as $httpAuthHeaderServerVar) { + if (isset($_SERVER[$httpAuthHeaderServerVar]) + && preg_match('/Basic\s+(.*)$/i', $_SERVER[$httpAuthHeaderServerVar], $matches) + ) { + list($name, $password) = explode(':', base64_decode($matches[1]), 2); + $_SERVER['PHP_AUTH_USER'] = strip_tags($name); + $_SERVER['PHP_AUTH_PW'] = strip_tags($password); + break; + } } self::initPaths(); |