Skip to content

Commit 24eaa2c

Browse files
committed
fix: sanitize and validate application domains
1 parent d59d8cd commit 24eaa2c

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

app/Livewire/Project/Service/EditDomain.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Models\ServiceApplication;
66
use Livewire\Component;
7+
use Spatie\Url\Url;
78

89
class EditDomain extends Component
910
{
@@ -20,25 +21,16 @@ public function mount()
2021
{
2122
$this->application = ServiceApplication::find($this->applicationId);
2223
}
23-
24-
public function updatedApplicationFqdn()
24+
public function submit()
2525
{
2626
try {
2727
$this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();
2828
$this->application->fqdn = str($this->application->fqdn)->replaceStart(',', '')->trim();
2929
$this->application->fqdn = str($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {
30+
Url::fromString($domain, ['http', 'https']);
3031
return str($domain)->trim()->lower();
3132
});
3233
$this->application->fqdn = $this->application->fqdn->unique()->implode(',');
33-
$this->application->save();
34-
} catch(\Throwable $e) {
35-
return handleError($e, $this);
36-
}
37-
}
38-
39-
public function submit()
40-
{
41-
try {
4234
check_domain_usage(resource: $this->application);
4335
$this->validate();
4436
$this->application->save();
@@ -48,12 +40,15 @@ public function submit()
4840
} else {
4941
$this->dispatch('success', 'Service saved.');
5042
}
51-
} catch (\Throwable $e) {
52-
return handleError($e, $this);
53-
} finally {
5443
$this->application->service->parse();
5544
$this->dispatch('refresh');
5645
$this->dispatch('configurationChanged');
46+
} catch (\Throwable $e) {
47+
$originalFqdn = $this->application->getOriginal('fqdn');
48+
if ($originalFqdn !== $this->application->fqdn) {
49+
$this->application->fqdn = $originalFqdn;
50+
}
51+
return handleError($e, $this);
5752
}
5853
}
5954

app/Livewire/Project/Service/ServiceApplicationView.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Support\Facades\Auth;
77
use Illuminate\Support\Facades\Hash;
88
use Livewire\Component;
9+
use Spatie\Url\Url;
910

1011
class ServiceApplicationView extends Component
1112
{
@@ -31,13 +32,7 @@ class ServiceApplicationView extends Component
3132

3233
public function updatedApplicationFqdn()
3334
{
34-
$this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();
35-
$this->application->fqdn = str($this->application->fqdn)->replaceStart(',', '')->trim();
36-
$this->application->fqdn = str($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {
37-
return str($domain)->trim()->lower();
38-
});
39-
$this->application->fqdn = $this->application->fqdn->unique()->implode(',');
40-
$this->application->save();
35+
4136
}
4237

4338
public function instantSave()
@@ -83,6 +78,14 @@ public function mount()
8378
public function submit()
8479
{
8580
try {
81+
$this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();
82+
$this->application->fqdn = str($this->application->fqdn)->replaceStart(',', '')->trim();
83+
$this->application->fqdn = str($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {
84+
Url::fromString($domain, ['http', 'https']);
85+
return str($domain)->trim()->lower();
86+
});
87+
$this->application->fqdn = $this->application->fqdn->unique()->implode(',');
88+
8689
check_domain_usage(resource: $this->application);
8790
$this->validate();
8891
$this->application->save();
@@ -92,10 +95,13 @@ public function submit()
9295
} else {
9396
$this->dispatch('success', 'Service saved.');
9497
}
98+
$this->dispatch('generateDockerCompose');
9599
} catch (\Throwable $e) {
100+
$originalFqdn = $this->application->getOriginal('fqdn');
101+
if ($originalFqdn !== $this->application->fqdn) {
102+
$this->application->fqdn = $originalFqdn;
103+
}
96104
return handleError($e, $this);
97-
} finally {
98-
$this->dispatch('generateDockerCompose');
99105
}
100106
}
101107

0 commit comments

Comments
 (0)