Skip to content

Commit 7bfc265

Browse files
committed
api(remote): fix use of missing node_id field
Fixes pterodactyl#5088
1 parent b7b2413 commit 7bfc265

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

app/Http/Controllers/Api/Remote/Backups/BackupRemoteUploadController.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,22 @@ public function __invoke(Request $request, string $backup): JsonResponse
4242
throw new BadRequestHttpException('A non-empty "size" query parameter must be provided.');
4343
}
4444

45-
/** @var \Pterodactyl\Models\Backup $backup */
46-
$backup = Backup::query()
47-
->where('node_id', $node->id)
45+
/** @var \Pterodactyl\Models\Backup $model */
46+
$model = Backup::query()
4847
->where('uuid', $backup)
4948
->firstOrFail();
5049

50+
// Check that the backup is "owned" by the node making the request. This avoids other nodes
51+
// from messing with backups that they don't own.
52+
/** @var \Pterodactyl\Models\Server $server */
53+
$server = $model->server;
54+
if ($server->node_id !== $node->id) {
55+
throw new HttpForbiddenException('You do not have permission to access that backup.');
56+
}
57+
5158
// Prevent backups that have already been completed from trying to
5259
// be uploaded again.
53-
if (!is_null($backup->completed_at)) {
60+
if (!is_null($model->completed_at)) {
5461
throw new ConflictHttpException('This backup is already in a completed state.');
5562
}
5663

@@ -61,7 +68,7 @@ public function __invoke(Request $request, string $backup): JsonResponse
6168
}
6269

6370
// The path where backup will be uploaded to
64-
$path = sprintf('%s/%s.tar.gz', $backup->server->uuid, $backup->uuid);
71+
$path = sprintf('%s/%s.tar.gz', $model->server->uuid, $model->uuid);
6572

6673
// Get the S3 client
6774
$client = $adapter->getClient();
@@ -99,7 +106,7 @@ public function __invoke(Request $request, string $backup): JsonResponse
99106
}
100107

101108
// Set the upload_id on the backup in the database.
102-
$backup->update(['upload_id' => $params['UploadId']]);
109+
$model->update(['upload_id' => $params['UploadId']]);
103110

104111
return new JsonResponse([
105112
'parts' => $parts,

app/Http/Controllers/Api/Remote/Backups/BackupStatusController.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,17 @@ public function index(ReportBackupCompleteRequest $request, string $backup): Jso
3636

3737
/** @var \Pterodactyl\Models\Backup $model */
3838
$model = Backup::query()
39-
->where('node_id', $node->id)
4039
->where('uuid', $backup)
4140
->firstOrFail();
4241

42+
// Check that the backup is "owned" by the node making the request. This avoids other nodes
43+
// from messing with backups that they don't own.
44+
/** @var \Pterodactyl\Models\Server $server */
45+
$server = $model->server;
46+
if ($server->node_id !== $node->id) {
47+
throw new HttpForbiddenException('You do not have permission to access that backup.');
48+
}
49+
4350
if ($model->is_successful) {
4451
throw new BadRequestHttpException('Cannot update the status of a backup that is already marked as completed.');
4552
}

0 commit comments

Comments
 (0)