Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix(destination): validate network server pairing

Andras Bacsaif44ace396516
diff --git a/app/Livewire/Project/Shared/Destination.php b/app/Livewire/Project/Shared/Destination.php
index d9e5600742..79892d4c6c 100644
--- a/app/Livewire/Project/Shared/Destination.php
+++ b/app/Livewire/Project/Shared/Destination.php
@@ -112,7 +112,7 @@ class Destination extends Component
{
try {
$server = Server::ownedByCurrentTeam()->findOrFail($server_id);
- $network = StandaloneDocker::ownedByCurrentTeam()->findOrFail($network_id);
+ $network = StandaloneDocker::ownedByCurrentTeam()->where('server_id', $server->id)->findOrFail($network_id);
$this->authorize('update', $this->resource);
$main_destination = $this->resource->destination;
@@ -140,7 +140,7 @@ class Destination extends Component
{
try {
$server = Server::ownedByCurrentTeam()->findOrFail($server_id);
- $network = StandaloneDocker::ownedByCurrentTeam()->findOrFail($network_id);
+ $network = StandaloneDocker::ownedByCurrentTeam()->where('server_id', $server->id)->findOrFail($network_id);
$this->authorize('update', $this->resource);
$this->resource->additional_networks()->attach($network->id, ['server_id' => $server->id]);
diff --git a/tests/Feature/CrossTeamDestinationAttachTest.php b/tests/Feature/CrossTeamDestinationAttachTest.php
index 74c2871073..3bd1511526 100644
--- a/tests/Feature/CrossTeamDestinationAttachTest.php
+++ b/tests/Feature/CrossTeamDestinationAttachTest.php
@@ -98,6 +98,16 @@ describe('Destination::addServer GHSA-j395-3pqh-9r5g', function () {
expect($this->applicationA->fresh()->additional_networks)->toHaveCount(0);
});
+ test('cannot attach own network paired with wrong own server', function () {
+ try {
+ Livewire::test(Destination::class, ['resource' => $this->applicationA])
+ ->call('addServer', $this->destinationA2->id, $this->serverA->id);
+ } catch (Throwable $e) {
+ }
+
+ expect($this->applicationA->fresh()->additional_networks)->toHaveCount(0);
+ });
+
test('can attach own team\'s server + network to own application', function () {
Livewire::test(Destination::class, ['resource' => $this->applicationA])
->call('addServer', $this->destinationA2->id, $this->serverA2->id);
@@ -121,4 +131,16 @@ describe('Destination::promote GHSA-j395-3pqh-9r5g', function () {
expect($this->applicationA->fresh()->destination_id)->toBe($originalDestinationId);
});
+
+ test('cannot promote own network paired with wrong own server', function () {
+ $originalDestinationId = $this->applicationA->destination_id;
+
+ try {
+ Livewire::test(Destination::class, ['resource' => $this->applicationA])
+ ->call('promote', $this->destinationA2->id, $this->serverA->id);
+ } catch (Throwable $e) {
+ }
+
+ expect($this->applicationA->fresh()->destination_id)->toBe($originalDestinationId);
+ });
});