diff --git a/lib/Routes/Account.php b/lib/Routes/Account.php index 55e08df..9b88776 100644 --- a/lib/Routes/Account.php +++ b/lib/Routes/Account.php @@ -1,13 +1,11 @@ parser()->parse($_GET['request']); $_SESSION['nonce'] = $token->claims()->get('nonce'); } - if (!isset($getVars["redirect_uri"])) { - if (isset($token)) { - $getVars['redirect_uri'] = $token->claims()->get("redirect_uri"); - } + if (! isset($getVars["redirect_uri"]) && isset($token)) { + $getVars['redirect_uri'] = $token->claims()->get("redirect_uri"); } } $requestFactory = new \Laminas\Diactoros\ServerRequestFactory(); - $request = $requestFactory->fromGlobals($_SERVER, $getVars, $_POST, $_COOKIE, $_FILES); + $request = $requestFactory::fromGlobals($_SERVER, $getVars, $_POST, $_COOKIE, $_FILES); $authServer = Server::getAuthServer(); - + $approval = false; // check clientId approval for the user - if (in_array($clientId, ($user['allowedClients'] ?? []))) { + if (in_array($clientId, ($user['allowedClients'] ?? []), true)) { $approval = true; } else { $clientRegistration = ClientRegistration::getRegistration($clientId); - if (isset($clientRegistration['origin']) && in_array($clientRegistration['origin'], TRUSTED_APPS)) { + if (isset($clientRegistration['origin']) && in_array($clientRegistration['origin'], TRUSTED_APPS, true)) { $approval = true; } } @@ -83,13 +82,13 @@ public static function respondToAuthorize() { )); exit(); } - + $webId = "https://id-" . $user['userId'] . "." . BASEDOMAIN . "/#me"; $user = new \Pdsinterop\Solid\Auth\Entity\User(); $user->setIdentifier($webId); $response = $authServer->respondToAuthorizationRequest($request, $user, $approval); - + $tokenGenerator = Server::getTokenGenerator(); $response = $tokenGenerator->addIdTokenToResponse( @@ -105,8 +104,8 @@ public static function respondToAuthorize() { public static function respondToRegister() { $postData = file_get_contents("php://input"); - $clientData = json_decode($postData, true); - if (!isset($clientData)) { + $clientData = json_decode($postData, true, 512, JSON_THROW_ON_ERROR); + if (empty($clientData) || ! is_array($clientData)) { header("HTTP/1.1 400 Bad request"); return; } @@ -125,7 +124,7 @@ public static function respondToRegister() { $clientData['client_secret'] = $generatedClientSecret; $clientData['origin'] = $origin; ClientRegistration::saveClientRegistration($clientData); - + $client = ClientRegistration::getRegistration($generatedClientId); $responseData = array( @@ -145,7 +144,7 @@ public static function respondToRegister() { header("Content-type: application/json"); echo json_encode($responseData, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR); } - + public static function respondToSharing() { $user = User::getUser(Session::getLoggedInUser()); $clientId = $_POST['client_id']; @@ -156,13 +155,13 @@ public static function respondToSharing() { $returnUrl = urldecode($_POST['returnUrl']); header("Location: $returnUrl"); } - + public static function respondToToken() { $authServer = Server::getAuthServer(); $tokenGenerator = Server::getTokenGenerator(); $requestFactory = new \Laminas\Diactoros\ServerRequestFactory(); - $request = $requestFactory->fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); + $request = $requestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); $requestBody = $request->getParsedBody(); $grantType = $requestBody['grant_type'] ?? null; @@ -188,7 +187,7 @@ public static function respondToToken() { $userId = false; break; } - + $httpDpop = $request->getServerParams()['HTTP_DPOP']; $response = $authServer->respondToAccessTokenRequest($request); @@ -205,10 +204,10 @@ public static function respondToToken() { } // Hack for podpro - if (PODPRO_COMPATIBILITY && strstr($clientId, "podpro.dev")) { + if (defined('PODPRO_COMPATIBILITY') && PODPRO_COMPATIBILITY && strstr($clientId, "podpro.dev")) { $response->getBody()->rewind(); $responseBody = $response->getBody()->getContents(); - $body = json_decode($responseBody, true); + $body = json_decode($responseBody, true, 512, JSON_THROW_ON_ERROR); $body['refresh_token'] = str_repeat('a', 209); // Podpro doesn't like refresh tokens longer than 209 characters; Sad. Server::respondPodPro($response, $body); } else { diff --git a/lib/Routes/SolidStorage.php b/lib/Routes/SolidStorage.php index 6eecb89..c10e9c3 100644 --- a/lib/Routes/SolidStorage.php +++ b/lib/Routes/SolidStorage.php @@ -1,20 +1,19 @@ fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); + $rawRequest = $requestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); try { StorageServer::initializeStorage(); @@ -52,7 +51,6 @@ public static function respondToStorage() { $ownerWebId = StorageServer::getOwnerWebId(); $owner = User::getUserByWebId($ownerWebId); - $allowedClients = $owner['allowedClients'] ?? []; $allowedOrigins = array_merge( ($owner['allowedOrigins'] ?? []), (TRUSTED_APPS ?? []) @@ -76,4 +74,3 @@ public static function respondToStorage() { StorageServer::respond($response); } } - \ No newline at end of file diff --git a/lib/Routes/SolidStorageProvider.php b/lib/Routes/SolidStorageProvider.php index 6bc3a31..0f2cd2f 100644 --- a/lib/Routes/SolidStorageProvider.php +++ b/lib/Routes/SolidStorageProvider.php @@ -1,13 +1,13 @@ fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); + $rawRequest = $requestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); $webId = StorageServer::getWebId($rawRequest); if (!isset($webId) || $webId === "public") { @@ -32,4 +32,3 @@ public static function respondToStorageNew() { echo json_encode($responseData, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR); } } - \ No newline at end of file diff --git a/lib/Routes/SolidUserProfile.php b/lib/Routes/SolidUserProfile.php index f650917..edc0220 100644 --- a/lib/Routes/SolidUserProfile.php +++ b/lib/Routes/SolidUserProfile.php @@ -1,21 +1,18 @@ fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); + $rawRequest = $requestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); ProfileServer::initializeProfile(); $filesystem = ProfileServer::getFileSystem(); @@ -31,7 +28,7 @@ public static function respondToProfile() { $wac->setBaseUrl($baseUrl); // use the original $_SERVER without modified path, otherwise the htu check for DPOP will fail - $webId = ProfileServer::getWebId($requestFactory->fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES)); + $webId = ProfileServer::getWebId($requestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES)); if (!isset($webId)) { $response = $resourceServer->getResponse() @@ -45,7 +42,6 @@ public static function respondToProfile() { // FIXME: Read allowed clients from the profile instead; $owner = ProfileServer::getOwner(); - $allowedClients = $owner['allowedClients'] ?? []; $allowedOrigins = array_merge( ($owner['allowedOrigins'] ?? []), (TRUSTED_APPS ?? []) @@ -68,4 +64,3 @@ public static function respondToProfile() { ProfileServer::respond($response); } } - \ No newline at end of file