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: Prevent version downgrades and centralize CDN configuration (#7383)

Andras Bacsaid9774d296849
diff --git a/app/Actions/Server/UpdateCoolify.php b/app/Actions/Server/UpdateCoolify.php
index 0bf763d78d..faf733a106 100644
--- a/app/Actions/Server/UpdateCoolify.php
+++ b/app/Actions/Server/UpdateCoolify.php
@@ -3,6 +3,8 @@
namespace App\Actions\Server;
use App\Models\Server;
+use Illuminate\Support\Facades\Http;
+use Illuminate\Support\Facades\Log;
use Illuminate\Support\Sleep;
use Lorisleiva\Actions\Concerns\AsAction;
@@ -29,7 +31,25 @@ class UpdateCoolify
return;
}
CleanupDocker::dispatch($this->server, false, false);
- $this->latestVersion = get_latest_version_of_coolify();
+
+ // Fetch fresh version from CDN instead of using cache
+ try {
+ $response = Http::retry(3, 1000)->timeout(10)
+ ->get(config('constants.coolify.versions_url'));
+
+ if ($response->successful()) {
+ $versions = $response->json();
+ $this->latestVersion = data_get($versions, 'coolify.v4.version');
+ } else {
+ // Fallback to cache if CDN unavailable
+ Log::warning('Failed to fetch fresh version from CDN (unsuccessful response), using cache');
+ $this->latestVersion = get_latest_version_of_coolify();
+ }
+ } catch (\Throwable $e) {
+ Log::warning('Failed to fetch fresh version from CDN, using cache', ['error' => $e->getMessage()]);
+ $this->latestVersion = get_latest_version_of_coolify();
+ }
+
$this->currentVersion = config('constants.coolify.version');
if (! $manual_update) {
if (! $settings->is_auto_update_enabled) {
@@ -42,6 +62,20 @@ class UpdateCoolify
return;
}
}
+
+ // ALWAYS check for downgrades (even for manual updates)
+ if (version_compare($this->latestVersion, $this->currentVersion, '<')) {
+ Log::error('Downgrade prevented', [
+ 'target_version' => $this->latestVersion,
+ 'current_version' => $this->currentVersion,
+ 'manual_update' => $manual_update,
+ ]);
+ throw new \Exception(
+ "Cannot downgrade from {$this->currentVersion} to {$this->latestVersion}. ".
+ 'If you need to downgrade, please do so manually via Docker commands.'
+ );
+ }
+
$this->update();
$settings->new_version_available = false;
$settings->save();
@@ -56,8 +90,9 @@ class UpdateCoolify
$image = config('constants.coolify.registry_url').'/coollabsio/coolify:'.$this->latestVersion;
instant_remote_process(["docker pull -q $image"], $this->server, false);
+ $upgradeScriptUrl = config('constants.coolify.upgrade_script_url');
remote_process([
- 'curl -fsSL https://cdn.coollabs.io/coolify/upgrade.sh -o /data/coolify/source/upgrade.sh',
+ "curl -fsSL {$upgradeScriptUrl} -o /data/coolify/source/upgrade.sh",
"bash /data/coolify/source/upgrade.sh $this->latestVersion",
], $this->server);
}
diff --git a/app/Jobs/CheckForUpdatesJob.php b/app/Jobs/CheckForUpdatesJob.php
index 4f2bfa68ce..0d29069688 100644
--- a/app/Jobs/CheckForUpdatesJob.php
+++ b/app/Jobs/CheckForUpdatesJob.php
@@ -10,6 +10,7 @@ use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http;
+use Illuminate\Support\Facades\Log;
class CheckForUpdatesJob implements ShouldBeEncrypted, ShouldQueue
{
@@ -22,20 +23,44 @@ class CheckForUpdatesJob implements ShouldBeEncrypted, ShouldQueue
return;
}
$settings = instanceSettings();
- $response = Http::retry(3, 1000)->get('https://cdn.coollabs.io/coolify/versions.json');
+ $response = Http::retry(3, 1000)->get(config('constants.coolify.versions_url'));
if ($response->successful()) {
$versions = $response->json();
$latest_version = data_get($versions, 'coolify.v4.version');
$current_version = config('constants.coolify.version');
+ // Read existing cached version
+ $existingVersions = null;
+ $existingCoolifyVersion = null;
+ if (File::exists(base_path('versions.json'))) {
+ $existingVersions = json_decode(File::get(base_path('versions.json')), true);
+ $existingCoolifyVersion = data_get($existingVersions, 'coolify.v4.version');
+ }
+
+ // Detect CDN serving older Coolify version
+ if ($existingCoolifyVersion && version_compare($latest_version, $existingCoolifyVersion, '<')) {
+ Log::warning('CDN served older Coolify version', [
+ 'cdn_version' => $latest_version,
+ 'cached_version' => $existingCoolifyVersion,
+ 'current_version' => $current_version,
+ ]);
+
+ // Keep the NEWER Coolify version from cache, but update other components
+ $versions['coolify']['v4']['version'] = $existingCoolifyVersion;
+ $latest_version = $existingCoolifyVersion;
+ }
+
+ // ALWAYS write versions.json (for Sentinel, Helper, Traefik updates)
+ File::put(base_path('versions.json'), json_encode($versions, JSON_PRETTY_PRINT));
+
+ // Invalidate cache to ensure fresh data is loaded
+ invalidate_versions_cache();
+
+ // Only mark new version available if Coolify version actually increased
if (version_compare($latest_version, $current_version, '>')) {
// New version available
$settings->update(['new_version_available' => true]);
- File::put(base_path('versions.json'), json_encode($versions, JSON_PRETTY_PRINT));
-
- // Invalidate cache to ensure fresh data is loaded
- invalidate_versions_cache();
} else {
$settings->update(['new_version_available' => false]);
}
diff --git a/app/Jobs/CheckHelperImageJob.php b/app/Jobs/CheckHelperImageJob.php
index 6abb8a1502..6d76da8eb7 100644
--- a/app/Jobs/CheckHelperImageJob.php
+++ b/app/Jobs/CheckHelperImageJob.php
@@ -21,7 +21,7 @@ class CheckHelperImageJob implements ShouldBeEncrypted, ShouldQueue
public function handle(): void
{
try {
- $response = Http::retry(3, 1000)->get('https://cdn.coollabs.io/coolify/versions.json');
+ $response = Http::retry(3, 1000)->get(config('constants.coolify.versions_url'));
if ($response->successful()) {
$versions = $response->json();
$settings = instanceSettings();
diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php
index 1b23247faf..1066f1a633 100644
--- a/bootstrap/helpers/shared.php
+++ b/bootstrap/helpers/shared.php
@@ -230,7 +230,7 @@ function get_route_parameters(): array
function get_latest_sentinel_version(): string
{
try {
- $response = Http::get('https://cdn.coollabs.io/coolify/versions.json');
+ $response = Http::get(config('constants.coolify.versions_url'));
$versions = $response->json();
return data_get($versions, 'coolify.sentinel.version');
diff --git a/config/constants.php b/config/constants.php
index 893fb11fdf..9b1dd5f687 100644
--- a/config/constants.php
+++ b/config/constants.php
@@ -12,6 +12,9 @@ return [
'helper_image' => env('HELPER_IMAGE', env('REGISTRY_URL', 'ghcr.io').'/coollabsio/coolify-helper'),
'realtime_image' => env('REALTIME_IMAGE', env('REGISTRY_URL', 'ghcr.io').'/coollabsio/coolify-realtime'),
'is_windows_docker_desktop' => env('IS_WINDOWS_DOCKER_DESKTOP', false),
+ 'cdn_url' => env('CDN_URL', 'https://cdn.coollabs.io'),
+ 'versions_url' => env('VERSIONS_URL', env('CDN_URL', 'https://cdn.coollabs.io').'/coolify/versions.json'),
+ 'upgrade_script_url' => env('UPGRADE_SCRIPT_URL', env('CDN_URL', 'https://cdn.coollabs.io').'/coolify/upgrade.sh'),
'releases_url' => 'https://cdn.coolify.io/releases.json',
],