@@ -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 ,
0 commit comments