From 3bb28c29be58cec16ba166073fe161ab14e48178 Mon Sep 17 00:00:00 2001
From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com>
Date: Mon, 14 Jul 2025 14:45:01 +0200
Subject: [PATCH] fix(application): sanitize service names for HTML form
binding and ensure original names are stored in docker compose domains
---
app/Livewire/Project/Application/General.php | 50 +++++++++++++++++--
.../project/application/general.blade.php | 2 +-
2 files changed, 47 insertions(+), 5 deletions(-)
diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.php
index 74f47232c..3e89ad663 100644
--- a/app/Livewire/Project/Application/General.php
+++ b/app/Livewire/Project/Application/General.php
@@ -156,6 +156,14 @@ class General extends Component
$this->application->settings->save();
}
$this->parsedServiceDomains = $this->application->docker_compose_domains ? json_decode($this->application->docker_compose_domains, true) : [];
+ // Convert service names with dots to use underscores for HTML form binding
+ $sanitizedDomains = [];
+ foreach ($this->parsedServiceDomains as $serviceName => $domain) {
+ $sanitizedKey = str($serviceName)->slug('_')->toString();
+ $sanitizedDomains[$sanitizedKey] = $domain;
+ }
+ $this->parsedServiceDomains = $sanitizedDomains;
+
$this->ports_exposes = $this->application->ports_exposes;
$this->is_preserve_repository_enabled = $this->application->settings->is_preserve_repository_enabled;
$this->is_container_label_escape_enabled = $this->application->settings->is_container_label_escape_enabled;
@@ -242,8 +250,26 @@ class General extends Component
{
$uuid = new Cuid2;
$domain = generateFqdn($this->application->destination->server, $uuid);
- $this->parsedServiceDomains[$serviceName]['domain'] = $domain;
- $this->application->docker_compose_domains = json_encode($this->parsedServiceDomains);
+ $sanitizedKey = str($serviceName)->slug('_')->toString();
+ $this->parsedServiceDomains[$sanitizedKey]['domain'] = $domain;
+
+ // Convert back to original service names for storage
+ $originalDomains = [];
+ foreach ($this->parsedServiceDomains as $key => $value) {
+ // Find the original service name by checking parsed services
+ $originalServiceName = $key;
+ if (isset($this->parsedServices['services'])) {
+ foreach ($this->parsedServices['services'] as $originalName => $service) {
+ if (str($originalName)->slug('_')->toString() === $key) {
+ $originalServiceName = $originalName;
+ break;
+ }
+ }
+ }
+ $originalDomains[$originalServiceName] = $value;
+ }
+
+ $this->application->docker_compose_domains = json_encode($originalDomains);
$this->application->save();
$this->dispatch('success', 'Domain generated.');
if ($this->application->build_pack === 'dockercompose') {
@@ -429,9 +455,25 @@ class General extends Component
$this->application->publish_directory = rtrim($this->application->publish_directory, '/');
}
if ($this->application->build_pack === 'dockercompose') {
- $this->application->docker_compose_domains = json_encode($this->parsedServiceDomains);
+ // Convert sanitized service names back to original names for storage
+ $originalDomains = [];
+ foreach ($this->parsedServiceDomains as $key => $value) {
+ // Find the original service name by checking parsed services
+ $originalServiceName = $key;
+ if (isset($this->parsedServices['services'])) {
+ foreach ($this->parsedServices['services'] as $originalName => $service) {
+ if (str($originalName)->slug('_')->toString() === $key) {
+ $originalServiceName = $originalName;
+ break;
+ }
+ }
+ }
+ $originalDomains[$originalServiceName] = $value;
+ }
- foreach ($this->parsedServiceDomains as $serviceName => $service) {
+ $this->application->docker_compose_domains = json_encode($originalDomains);
+
+ foreach ($originalDomains as $serviceName => $service) {
$domain = data_get($service, 'domain');
if ($domain) {
if (! validate_dns_entry($domain, $this->application->destination->server)) {
diff --git a/resources/views/livewire/project/application/general.blade.php b/resources/views/livewire/project/application/general.blade.php
index 39102c39b..03f26fd04 100644
--- a/resources/views/livewire/project/application/general.blade.php
+++ b/resources/views/livewire/project/application/general.blade.php
@@ -51,7 +51,7 @@
+ id="parsedServiceDomains.{{ str($serviceName)->slug('_') }}.domain">
Generate
Domain