Skip to content

Commit 85a13f4

Browse files
Merge pull request #142 from bjoernv/master
Setting authorization header globally in basicauth.php is dangerous (fix for #141)
2 parents 132e8b6 + 133d340 commit 85a13f4

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

lib/basicauth.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ public function checkPassword($uid, $password) {
2828
* Connect without user/name password to make sure
2929
* URL is indeed authenticating or not...
3030
*/
31-
stream_context_set_default(array(
32-
'http'=>array(
33-
'method'=>"GET",
31+
$context = stream_context_create(array(
32+
'http' => array(
33+
'method' => "GET",
34+
'follow_location' => 0
3435
))
3536
);
36-
$canary = get_headers($this->authUrl, 1);
37+
$canary = get_headers($this->authUrl, 1, $context);
3738
if(!$canary) {
3839
OC::$server->getLogger()->error(
3940
'ERROR: Not possible to connect to BasicAuth Url: '.$this->authUrl,
@@ -49,13 +50,14 @@ public function checkPassword($uid, $password) {
4950
return false;
5051
}
5152

52-
stream_context_set_default(array(
53-
'http'=>array(
54-
'method'=>"GET",
55-
'header' => "authorization: Basic " . base64_encode("$uid:$password")
53+
$context = stream_context_create(array(
54+
'http' => array(
55+
'method' => "GET",
56+
'header' => "authorization: Basic " . base64_encode("$uid:$password"),
57+
'follow_location' => 0
5658
))
5759
);
58-
$headers = get_headers($this->authUrl, 1);
60+
$headers = get_headers($this->authUrl, 1, $context);
5961

6062
if(!$headers) {
6163
OC::$server->getLogger()->error(

0 commit comments

Comments
 (0)