mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Return project_not_found when project region does not match _APP_REGION
Reject opening the project database on the wrong regional node (router deployment path, legacy request format filter, and shared dbForProject / getProjectDB resources). Compares project region to System::_APP_REGION with default "default". Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -153,6 +153,13 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw
|
||||
}
|
||||
}
|
||||
|
||||
if (!$project->isEmpty() && $project->getId() !== 'console') {
|
||||
$localRegion = System::getEnv('_APP_REGION', 'default');
|
||||
if ($project->getAttribute('region', 'default') !== $localRegion) {
|
||||
throw new AppwriteException(AppwriteException::PROJECT_NOT_FOUND, view: $errorView);
|
||||
}
|
||||
}
|
||||
|
||||
/** @var Database $dbForProject */
|
||||
$dbForProject = $getProjectDB($project);
|
||||
|
||||
@@ -903,6 +910,12 @@ App::init()
|
||||
$request->addFilter(new RequestV19());
|
||||
}
|
||||
if (version_compare($requestFormat, '1.8.0', '<')) {
|
||||
if (!$project->isEmpty() && $project->getId() !== 'console') {
|
||||
$localRegion = System::getEnv('_APP_REGION', 'default');
|
||||
if ($project->getAttribute('region', 'default') !== $localRegion) {
|
||||
throw new AppwriteException(AppwriteException::PROJECT_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
$dbForProject = $getProjectDB($project);
|
||||
$request->addFilter(new RequestV20($dbForProject, $route->getPathValues($request)));
|
||||
}
|
||||
@@ -1154,7 +1167,7 @@ App::options()
|
||||
$platformHostnames = $platform['hostnames'] ?? [];
|
||||
// Only run Router when external domain
|
||||
if (!in_array($request->getHostname(), $platformHostnames) || !empty($previewHostname)) {
|
||||
if (router($utopia, $dbForPlatform, $getProjectDB, $swooleRequest, $request, $response, $log, $queueForEvents, $queueForStatsUsage, $queueForFunctions, $executor, $geodb, $isResourceBlocked, $platform, $previewHostname, $apiKey)) {
|
||||
if (router($utopia, $dbForPlatform, $getProjectDB, $swooleRequest, $request, $response, $log, $queueForEvents, $queueForStatsUsage, $queueForFunctions, $executor, $geodb, $isResourceBlocked, $platform, $previewHostname, $authorization, $apiKey)) {
|
||||
$utopia->getRoute()?->label('router', true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,6 +515,11 @@ App::setResource('dbForProject', function (Group $pools, Database $dbForPlatform
|
||||
return $dbForPlatform;
|
||||
}
|
||||
|
||||
$localRegion = System::getEnv('_APP_REGION', 'default');
|
||||
if ($project->getAttribute('region', 'default') !== $localRegion) {
|
||||
throw new Exception(Exception::PROJECT_NOT_FOUND);
|
||||
}
|
||||
|
||||
try {
|
||||
$dsn = new DSN($project->getAttribute('database'));
|
||||
} catch (\InvalidArgumentException) {
|
||||
@@ -576,6 +581,11 @@ App::setResource('getProjectDB', function (Group $pools, Database $dbForPlatform
|
||||
return $dbForPlatform;
|
||||
}
|
||||
|
||||
$localRegion = System::getEnv('_APP_REGION', 'default');
|
||||
if ($project->getAttribute('region', 'default') !== $localRegion) {
|
||||
throw new Exception(Exception::PROJECT_NOT_FOUND);
|
||||
}
|
||||
|
||||
try {
|
||||
$dsn = new DSN($project->getAttribute('database'));
|
||||
} catch (\InvalidArgumentException) {
|
||||
|
||||
Reference in New Issue
Block a user