diff --git a/app/config/collections.php b/app/config/collections.php index 171463c033..83fc615edb 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -1115,6 +1115,17 @@ $collections = [ '$id' => 'tokens', 'name' => 'Tokens', 'attributes' => [ + [ + '$id' => 'userInternalId', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => 'userId', 'type' => Database::VAR_STRING, @@ -1186,7 +1197,7 @@ $collections = [ [ '$id' => '_key_user', 'type' => Database::INDEX_KEY, - 'attributes' => ['userId'], + 'attributes' => ['userInternalId'], 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], @@ -1198,6 +1209,17 @@ $collections = [ '$id' => 'sessions', 'name' => 'Sessions', 'attributes' => [ + [ + '$id' => 'userInternalId', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => 'userId', 'type' => Database::VAR_STRING, @@ -1463,7 +1485,7 @@ $collections = [ [ '$id' => '_key_user', 'type' => Database::INDEX_KEY, - 'attributes' => ['userId'], + 'attributes' => ['userInternalId'], 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], @@ -1536,6 +1558,17 @@ $collections = [ '$id' => 'memberships', 'name' => 'Memberships', 'attributes' => [ + [ + '$id' => 'userInternalId', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => 'teamId', 'type' => Database::VAR_STRING, @@ -1634,16 +1667,16 @@ $collections = [ 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC], ], [ - '$id' => '_key_team', + '$id' => '_key_internal', 'type' => Database::INDEX_KEY, - 'attributes' => ['teamId'], + 'attributes' => ['userInternalId'], 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], [ - '$id' => '_key_user', + '$id' => '_key_team', 'type' => Database::INDEX_KEY, - 'attributes' => ['userId'], + 'attributes' => ['teamId'], 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 10c9789882..4e01791d07 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -178,6 +178,7 @@ App::post('/v1/account/sessions') [ '$id' => $dbForProject->getId(), 'userId' => $profile->getId(), + 'userInternalId' => $profile->getInternalId(), 'provider' => Auth::SESSION_PROVIDER_EMAIL, 'providerUid' => $email, 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak @@ -507,6 +508,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $session = new Document(array_merge([ '$id' => $dbForProject->getId(), 'userId' => $user->getId(), + 'userInternalId' => $user->getInternalId(), 'provider' => $provider, 'providerUid' => $oauth2ID, 'providerAccessToken' => $accessToken, @@ -661,6 +663,7 @@ App::post('/v1/account/sessions/magic-url') $token = new Document([ '$id' => $dbForProject->getId(), 'userId' => $user->getId(), + 'userInternalId' => $user->getInternalId(), 'type' => Auth::TOKEN_TYPE_MAGIC_URL, 'secret' => Auth::hash($loginSecret), // One way hash encryption to protect DB leak 'expire' => $expire, @@ -758,6 +761,7 @@ App::put('/v1/account/sessions/magic-url') [ '$id' => $dbForProject->getId(), 'userId' => $user->getId(), + 'userInternalId' => $user->getInternalId(), 'provider' => Auth::SESSION_PROVIDER_MAGIC_URL, 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak 'expire' => $expiry, @@ -901,6 +905,7 @@ App::post('/v1/account/sessions/anonymous') [ '$id' => $dbForProject->getId(), 'userId' => $user->getId(), + 'userInternalId' => $user->getInternalId(), 'provider' => Auth::SESSION_PROVIDER_ANONYMOUS, 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak 'expire' => $expiry, @@ -1680,6 +1685,7 @@ App::post('/v1/account/recovery') $recovery = new Document([ '$id' => $dbForProject->getId(), 'userId' => $profile->getId(), + 'userInternalId' => $profile->getInternalId(), 'type' => Auth::TOKEN_TYPE_RECOVERY, 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak 'expire' => $expire, @@ -1840,6 +1846,7 @@ App::post('/v1/account/verification') $verification = new Document([ '$id' => $dbForProject->getId(), 'userId' => $user->getId(), + 'userInternalId' => $user->getInternalId(), 'type' => Auth::TOKEN_TYPE_VERIFICATION, 'secret' => Auth::hash($verificationSecret), // One way hash encryption to protect DB leak 'expire' => $expire, diff --git a/app/init.php b/app/init.php index 0e1848b2c3..e137f818df 100644 --- a/app/init.php +++ b/app/init.php @@ -333,7 +333,7 @@ Database::addFilter( }, function (mixed $value, Document $document, Database $database) { return Authorization::skip(fn () => $database->find('sessions', [ - new Query('userId', Query::TYPE_EQUAL, [$document->getId()]) + new Query('userId', Query::TYPE_EQUAL, [$document->getInternalId()]) ], APP_LIMIT_SUBQUERY)); } ); @@ -346,7 +346,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return Authorization::skip(fn() => $database ->find('tokens', [ - new Query('userId', Query::TYPE_EQUAL, [$document->getId()]) + new Query('userId', Query::TYPE_EQUAL, [$document->getInternalId()]) ], APP_LIMIT_SUBQUERY)); } ); @@ -359,7 +359,7 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return Authorization::skip(fn() => $database ->find('memberships', [ - new Query('userId', Query::TYPE_EQUAL, [$document->getId()]) + new Query('userId', Query::TYPE_EQUAL, [$document->getInternalId()]) ], APP_LIMIT_SUBQUERY)); } ); diff --git a/docker-compose.yml b/docker-compose.yml index b6e1ed68b2..56cdee0c8a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -103,7 +103,7 @@ services: - ./phpunit.xml:/usr/src/code/phpunit.xml - ./tests:/usr/src/code/tests - ./app:/usr/src/code/app - # - ./vendor:/usr/src/code/vendor + - ./vendor:/usr/src/code/vendor - ./docs:/usr/src/code/docs - ./public:/usr/src/code/public - ./src:/usr/src/code/src