mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Guard consoleApiKey to same-instance migrations only
Revert controller to original form without console API key generation to avoid leaking JWT to untrusted remote endpoints. In the worker, only set consoleApiKey when the source endpoint matches the local endpoint, ensuring the locally-signed JWT is never sent cross-instance.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
use Ahc\Jwt\JWT;
|
||||
use Appwrite\Event\Event;
|
||||
use Appwrite\Event\Migration;
|
||||
use Appwrite\Extend\Exception;
|
||||
@@ -719,17 +718,7 @@ Http::get('/v1/migrations/appwrite/report')
|
||||
->inject('user')
|
||||
->action(function (array $resources, string $endpoint, string $projectID, string $key, Response $response) {
|
||||
|
||||
$consoleApiKey = '';
|
||||
$openSslKey = System::getEnv('_APP_OPENSSL_KEY_V1');
|
||||
if (!empty($openSslKey)) {
|
||||
$jwt = new JWT($openSslKey, 'HS256', 86400, 0);
|
||||
$consoleApiKey = API_KEY_DYNAMIC . '_' . $jwt->encode([
|
||||
'projectId' => 'console',
|
||||
'scopes' => ['platforms.read', 'keys.read'],
|
||||
]);
|
||||
}
|
||||
|
||||
$appwrite = new Appwrite($projectID, $endpoint, $key, consoleApiKey: $consoleApiKey, sourceProjectId: $projectID);
|
||||
$appwrite = new Appwrite($projectID, $endpoint, $key);
|
||||
|
||||
try {
|
||||
$report = $appwrite->report($resources);
|
||||
|
||||
@@ -385,7 +385,13 @@ class Migrations extends Action
|
||||
$credentials['projectId'] = $credentials['projectId'] ?? $project->getId();
|
||||
$credentials['apiKey'] = $credentials['apiKey'] ?? $tempAPIKey;
|
||||
$credentials['endpoint'] = $credentials['endpoint'] ?? $endpoint;
|
||||
$credentials['consoleApiKey'] = $credentials['consoleApiKey'] ?? $tempConsoleAPIKey;
|
||||
|
||||
// Only set consoleApiKey for same-instance migrations to avoid
|
||||
// leaking a locally-signed JWT to untrusted remote servers
|
||||
if (($credentials['endpoint'] ?? '') === $endpoint) {
|
||||
$credentials['consoleApiKey'] = $tempConsoleAPIKey;
|
||||
$credentials['sourceProjectId'] = $credentials['projectId'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($migration->getAttribute('destination') === DestinationAppwrite::getName()) {
|
||||
|
||||
Reference in New Issue
Block a user