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(proxy): add validation and normalization for database proxy timeout

Andras Bacsai184fbb98f3ec
diff --git a/app/Actions/Database/StartDatabaseProxy.php b/app/Actions/Database/StartDatabaseProxy.php
index 0d20fa4a40..1de28a2459 100644
--- a/app/Actions/Database/StartDatabaseProxy.php
+++ b/app/Actions/Database/StartDatabaseProxy.php
@@ -54,8 +54,7 @@ class StartDatabaseProxy
if (isDev()) {
$configuration_dir = '/var/lib/docker/volumes/coolify_dev_coolify_data/_data/databases/'.$database->uuid.'/proxy';
}
- $timeout = $database->public_port_timeout ?? 3600;
- $timeoutConfig = $timeout === 0 ? 'proxy_timeout 0;' : "proxy_timeout {$timeout}s;";
+ $timeoutConfig = $this->buildProxyTimeoutConfig($database->public_port_timeout);
$nginxconf = <<<EOF
user nginx;
worker_processes auto;
@@ -163,4 +162,13 @@ class StartDatabaseProxy
return false;
}
+
+ private function buildProxyTimeoutConfig(?int $timeout): string
+ {
+ if ($timeout === null || $timeout < 1) {
+ $timeout = 3600;
+ }
+
+ return "proxy_timeout {$timeout}s;";
+ }
}
diff --git a/app/Livewire/Project/Service/Index.php b/app/Livewire/Project/Service/Index.php
index f12a11215e..b735d7e71e 100644
--- a/app/Livewire/Project/Service/Index.php
+++ b/app/Livewire/Project/Service/Index.php
@@ -92,7 +92,7 @@ class Index extends Component
'image' => 'required',
'excludeFromStatus' => 'required|boolean',
'publicPort' => 'nullable|integer',
- 'publicPortTimeout' => 'nullable|integer',
+ 'publicPortTimeout' => 'nullable|integer|min:1',
'isPublic' => 'required|boolean',
'isLogDrainEnabled' => 'required|boolean',
// Application-specific rules
diff --git a/tests/Feature/StartDatabaseProxyTest.php b/tests/Feature/StartDatabaseProxyTest.php
index c625698661..b14cb414a9 100644
--- a/tests/Feature/StartDatabaseProxyTest.php
+++ b/tests/Feature/StartDatabaseProxyTest.php
@@ -43,3 +43,15 @@ test('isNonTransientError detects port conflict patterns', function () {
->and($method->invoke($action, 'network timeout'))->toBeFalse()
->and($method->invoke($action, 'connection refused'))->toBeFalse();
});
+
+test('buildProxyTimeoutConfig normalizes invalid values to default', function (?int $input, string $expected) {
+ $action = new StartDatabaseProxy;
+ $method = new ReflectionMethod($action, 'buildProxyTimeoutConfig');
+
+ expect($method->invoke($action, $input))->toBe($expected);
+})->with([
+ [null, 'proxy_timeout 3600s;'],
+ [0, 'proxy_timeout 3600s;'],
+ [-10, 'proxy_timeout 3600s;'],
+ [120, 'proxy_timeout 120s;'],
+]);
diff --git a/tests/Unit/ServiceIndexValidationTest.php b/tests/Unit/ServiceIndexValidationTest.php
new file mode 100644
index 0000000000..7b746cde67
--- /dev/null
+++ b/tests/Unit/ServiceIndexValidationTest.php
@@ -0,0 +1,11 @@
+<?php
+
+use App\Livewire\Project\Service\Index;
+
+test('service database proxy timeout requires a minimum of one second', function () {
+ $component = new Index;
+ $rules = (fn (): array => $this->rules)->call($component);
+
+ expect($rules['publicPortTimeout'])
+ ->toContain('min:1');
+});