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: sanitize and validate application domains

Andras Bacsai24eaa2c9b2c0
diff --git a/app/Livewire/Project/Service/EditDomain.php b/app/Livewire/Project/Service/EditDomain.php
index cdec580bb0..4138f720e0 100644
--- a/app/Livewire/Project/Service/EditDomain.php
+++ b/app/Livewire/Project/Service/EditDomain.php
@@ -4,6 +4,7 @@ namespace App\Livewire\Project\Service;
use App\Models\ServiceApplication;
use Livewire\Component;
+use Spatie\Url\Url;
class EditDomain extends Component
{
@@ -20,25 +21,16 @@ class EditDomain extends Component
{
$this->application = ServiceApplication::find($this->applicationId);
}
-
- public function updatedApplicationFqdn()
+ public function submit()
{
try {
$this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();
$this->application->fqdn = str($this->application->fqdn)->replaceStart(',', '')->trim();
$this->application->fqdn = str($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {
+ Url::fromString($domain, ['http', 'https']);
return str($domain)->trim()->lower();
});
$this->application->fqdn = $this->application->fqdn->unique()->implode(',');
- $this->application->save();
- } catch(\Throwable $e) {
- return handleError($e, $this);
- }
- }
-
- public function submit()
- {
- try {
check_domain_usage(resource: $this->application);
$this->validate();
$this->application->save();
@@ -48,12 +40,15 @@ class EditDomain extends Component
} else {
$this->dispatch('success', 'Service saved.');
}
- } catch (\Throwable $e) {
- return handleError($e, $this);
- } finally {
$this->application->service->parse();
$this->dispatch('refresh');
$this->dispatch('configurationChanged');
+ } catch (\Throwable $e) {
+ $originalFqdn = $this->application->getOriginal('fqdn');
+ if ($originalFqdn !== $this->application->fqdn) {
+ $this->application->fqdn = $originalFqdn;
+ }
+ return handleError($e, $this);
}
}
diff --git a/app/Livewire/Project/Service/ServiceApplicationView.php b/app/Livewire/Project/Service/ServiceApplicationView.php
index 56b506043d..ba37313fd5 100644
--- a/app/Livewire/Project/Service/ServiceApplicationView.php
+++ b/app/Livewire/Project/Service/ServiceApplicationView.php
@@ -6,6 +6,7 @@ use App\Models\ServiceApplication;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Livewire\Component;
+use Spatie\Url\Url;
class ServiceApplicationView extends Component
{
@@ -31,13 +32,7 @@ class ServiceApplicationView extends Component
public function updatedApplicationFqdn()
{
- $this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();
- $this->application->fqdn = str($this->application->fqdn)->replaceStart(',', '')->trim();
- $this->application->fqdn = str($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {
- return str($domain)->trim()->lower();
- });
- $this->application->fqdn = $this->application->fqdn->unique()->implode(',');
- $this->application->save();
+
}
public function instantSave()
@@ -83,6 +78,14 @@ class ServiceApplicationView extends Component
public function submit()
{
try {
+ $this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();
+ $this->application->fqdn = str($this->application->fqdn)->replaceStart(',', '')->trim();
+ $this->application->fqdn = str($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {
+ Url::fromString($domain, ['http', 'https']);
+ return str($domain)->trim()->lower();
+ });
+ $this->application->fqdn = $this->application->fqdn->unique()->implode(',');
+
check_domain_usage(resource: $this->application);
$this->validate();
$this->application->save();
@@ -92,10 +95,13 @@ class ServiceApplicationView extends Component
} else {
$this->dispatch('success', 'Service saved.');
}
+ $this->dispatch('generateDockerCompose');
} catch (\Throwable $e) {
+ $originalFqdn = $this->application->getOriginal('fqdn');
+ if ($originalFqdn !== $this->application->fqdn) {
+ $this->application->fqdn = $originalFqdn;
+ }
return handleError($e, $this);
- } finally {
- $this->dispatch('generateDockerCompose');
}
}