Skip to content

Commit 0bd40d7

Browse files
committed
Add fix caused by "Origin" headers being an array.
1 parent 7bb4beb commit 0bd40d7

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/WAC.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ public function isAllowed($request, $webId, $origin=false, $allowedOrigins=[]) {
5151
$uri = $request->getUri();
5252
$parentUri = $this->getParentUri($uri);
5353

54-
foreach ($requestedGrants as $requestedGrant) {
54+
// @FIXME: $origin can be anything at this point, null, string, array, bool
55+
// This causes trouble downstream where an unchecked `parse_url($origin)['host'];` occurs
56+
57+
foreach ($requestedGrants as $requestedGrant) {
5558
switch ($requestedGrant['type']) {
5659
case "resource":
5760
if ($this->isPublicGranted($requestedGrant['grants'], $uri)) {
@@ -121,11 +124,16 @@ private function isUserGranted($requestedGrants, $uri, $webId) {
121124
}
122125

123126
private function isOriginGranted($requestedGrants, $uri, $origin, $allowedOrigins) {
127+
if (is_array($origin)) {
128+
$origin = reset($origin);
129+
}
130+
124131
if (!$origin) {
125132
return true;
126133
}
134+
127135
$parsedOrigin = parse_url($origin)['host'];
128-
if (in_array($parsedOrigin, $allowedOrigins)) {
136+
if (in_array($parsedOrigin, $allowedOrigins, true)) {
129137
return true;
130138
}
131139
//error_log("REQUESTED GRANT: " . join(" or ", $requestedGrants) . " on $uri");

0 commit comments

Comments
 (0)