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.

feat: allow safe environment variable defaults in array-format volumes

Andras Bacsai97868c32640a
diff --git a/bootstrap/helpers/parsers.php b/bootstrap/helpers/parsers.php
index f3d71c83df..f2260f0c6e 100644
--- a/bootstrap/helpers/parsers.php
+++ b/bootstrap/helpers/parsers.php
@@ -59,8 +59,11 @@ function validateDockerComposeForInjection(string $composeYaml): void
if (isset($volume['source'])) {
$source = $volume['source'];
if (is_string($source)) {
+ // Allow simple env vars and env vars with defaults (validated in parseDockerVolumeString)
$isSimpleEnvVar = preg_match('/^\$\{[a-zA-Z_][a-zA-Z0-9_]*\}$/', $source);
- if (! $isSimpleEnvVar) {
+ $isEnvVarWithDefault = preg_match('/^\$\{[^}]+:-[^}]*\}$/', $source);
+
+ if (! $isSimpleEnvVar && ! $isEnvVarWithDefault) {
try {
validateShellSafePath($source, 'volume source');
} catch (\Exception $e) {
diff --git a/tests/Unit/VolumeArrayFormatSecurityTest.php b/tests/Unit/VolumeArrayFormatSecurityTest.php
index b8e5a7f7a8..97a6819b2f 100644
--- a/tests/Unit/VolumeArrayFormatSecurityTest.php
+++ b/tests/Unit/VolumeArrayFormatSecurityTest.php
@@ -171,6 +171,29 @@ YAML;
expect($isSimpleEnvVar)->toBe(1); // preg_match returns 1 on success, not true
});
+test('array-format with safe environment variable default', function () {
+ $dockerComposeYaml = <<<'YAML'
+services:
+ web:
+ image: nginx
+ volumes:
+ - type: bind
+ source: '${DATA_PATH:-./data}'
+ target: /app/data
+YAML;
+
+ $parsed = Yaml::parse($dockerComposeYaml);
+ $source = $parsed['services']['web']['volumes'][0]['source'];
+
+ // Parse correctly extracts the source value
+ expect($source)->toBe('${DATA_PATH:-./data}');
+
+ // Safe environment variable with benign default should be allowed
+ // The pre-save validation skips env vars with safe defaults
+ expect(fn () => validateDockerComposeForInjection($dockerComposeYaml))
+ ->not->toThrow(Exception::class);
+});
+
test('array-format with malicious environment variable default', function () {
$dockerComposeYaml = <<<'YAML'
services: