chore: add stricter checks according to review

This commit is contained in:
Chirag Aggarwal 2025-04-18 15:32:25 +00:00
parent ba22e5f457
commit d130e7d3bd
7 changed files with 13 additions and 12 deletions

View file

@ -954,7 +954,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview')
throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND);
}
$isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') == $bucket->getInternalId();
$isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getInternalId();
$fileSecurity = $bucket->getAttribute('fileSecurity', false);
$validator = new Authorization(Database::PERMISSION_READ);
$valid = $validator->isValid($bucket->getRead());

View file

@ -542,7 +542,7 @@ App::init()
$bucketId = $parts[1] ?? null;
$bucket = Authorization::skip(fn () => $dbForProject->getDocument('buckets', $bucketId));
$isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') == $bucket->getInternalId();
$isToken = !$resourceToken->isEmpty() && $resourceToken->getAttribute('bucketInternalId') === $bucket->getInternalId();
$isAPIKey = Auth::isAppUser(Authorization::getRoles());
$isPrivilegedUser = Auth::isPrivilegedUser(Authorization::getRoles());

View file

@ -861,7 +861,7 @@ App::setResource('resourceToken', function ($project, $dbForProject, $request) {
$token = Authorization::skip(fn () => $dbForProject->getDocument('resourceTokens', $tokenId));
if ($token->isEmpty() || $token->getAttribute('secret') != $secret) {
if ($token->isEmpty() || $token->getAttribute('secret') !== $secret) {
return new Document([]);
}
@ -869,7 +869,7 @@ App::setResource('resourceToken', function ($project, $dbForProject, $request) {
$internalIds = explode(':', $token->getAttribute('resourceInternalId'));
$ids = explode(':', $token->getAttribute('resourceId'));
if (count($internalIds) != 2 || count($ids) != 2) {
if (count($internalIds) !== 2 || count($ids) !== 2) {
return new Document([]);
}

View file

@ -82,12 +82,13 @@ class Create extends Action
$fileSecurity = $bucket->getAttribute('fileSecurity', false);
$validator = new Authorization(Database::PERMISSION_UPDATE);
$bucketPermission = $validator->isValid($bucket->getUpdate());
if (!$fileSecurity && !$bucketPermission) {
throw new Exception(Exception::USER_UNAUTHORIZED);
}
$filePermission = $validator->isValid($file->getUpdate());
if ($fileSecurity && !$bucketPermission && !$filePermission) {
if ($fileSecurity) {
$filePermission = $validator->isValid($file->getUpdate());
if (!$bucketPermission && !$filePermission) {
throw new Exception(Exception::USER_UNAUTHORIZED);
}
} elseif (!$bucketPermission) {
throw new Exception(Exception::USER_UNAUTHORIZED);
}

View file

@ -66,7 +66,7 @@ class Get extends Action
// calculate maxAge based on expiry date
$maxAge = PHP_INT_MAX;
$expire = $token->getAttribute('expire');
if ($expire != null) {
if ($expire !== null) {
$now = new \DateTime();
$expiryDate = new \DateTime($expire);
if ($expiryDate < $now) {

View file

@ -177,7 +177,7 @@ class OpenAPI3 extends Format
$namespace = $sdk->getNamespace() ?? 'default';
$desc = $desc ?? '';
$desc ??= '';
$descContents = \str_ends_with($desc, '.md') ? \file_get_contents($desc) : $desc;
$temp = [

View file

@ -173,7 +173,7 @@ class Swagger2 extends Format
$namespace = $sdk->getNamespace() ?? 'default';
$desc = $desc ?? '';
$desc ??= '';
$descContents = \str_ends_with($desc, '.md') ? \file_get_contents($desc) : $desc;
$temp = [