coolify/tests/Unit
Andras Bacsai cb1f571eb4 fix: prevent command injection in Docker Compose parsing - add pre-save validation
This commit addresses a critical security issue where malicious Docker Compose
data was being saved to the database before validation occurred.

Problem:
- Service models were saved to database first
- Validation ran afterwards during parse()
- Malicious data persisted even when validation failed
- User saw error but damage was already done

Solution:
1. Created validateDockerComposeForInjection() to validate YAML before save
2. Added pre-save validation to all Service creation/update points:
   - Livewire: DockerCompose.php, StackForm.php
   - API: ServicesController.php (create, update, one-click)
3. Validates service names and volume paths (string + array formats)
4. Blocks shell metacharacters: backticks, $(), |, ;, &, >, <, newlines

Security fixes:
- Volume source paths (string format) - validated before save
- Volume source paths (array format) - validated before save
- Service names - validated before save
- Environment variable patterns - safe ${VAR} allowed, ${VAR:-$(cmd)} blocked

Testing:
- 60 security tests pass (176 assertions)
- PreSaveValidationTest.php: 15 tests for pre-save validation
- ValidateShellSafePathTest.php: 15 tests for core validation
- VolumeSecurityTest.php: 15 tests for volume parsing
- ServiceNameSecurityTest.php: 15 tests for service names

Related commits:
- Previous: Added validation during parse() phase
- This commit: Moves validation before database save

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-16 09:51:37 +02:00
..
Rules feat: add YAML validation for cloud-init scripts 2025-10-11 13:56:55 +02:00
ApplicationGitSecurityTest.php fix: prevent command injection in git ls-remote operations 2025-10-15 14:53:50 +02:00
ApplicationWatchPathsTest.php refactor(tests): simplify matchWatchPaths tests and update implementation for better clarity 2025-09-26 14:33:18 +02:00
BashEnvEscapingTest.php fix: handle null environment variable values in bash escaping 2025-10-15 13:35:58 +02:00
CloudInitScriptValidationTest.php feat: add cloud-init script support for Hetzner server creation 2025-10-10 19:37:16 +02:00
DatalistComponentTest.php feat: add support for selecting additional SSH keys from Hetzner in server creation form 2025-10-10 12:17:05 +02:00
DockerComposeLabelParsingTest.php Changes auto-committed by Conductor 2025-10-16 08:51:15 +02:00
DockerImageAutoParseTest.php fix: improve Docker image digest handling and add auto-parse feature 2025-10-15 10:19:01 +02:00
DockerImageParserTest.php fix: improve Docker image digest handling and add auto-parse feature 2025-10-15 10:19:01 +02:00
GitLsRemoteParsingTest.php test: improve Git ls-remote parsing tests with uppercase SHA and negative cases 2025-10-14 17:34:26 +02:00
GlobalSearchNewImageQuickActionTest.php fix: 'new image' quick action not progressing to resource selection 2025-10-15 10:49:07 +02:00
HetznerDeletionFailedNotificationTest.php feat: implement Hetzner deletion failure notification system with email and messaging support 2025-10-10 09:35:58 +02:00
HetznerSshKeysTest.php feat: add support for selecting additional SSH keys from Hetzner in server creation form 2025-10-10 12:17:05 +02:00
ParseDockerVolumeStringTest.php fix(parsers): enhance volume string handling by preserving mode in application and service parsers. Update related unit tests for validation. 2025-08-27 16:54:49 +02:00
PreSaveValidationTest.php fix: prevent command injection in Docker Compose parsing - add pre-save validation 2025-10-16 09:51:37 +02:00
PrivateKeyStorageTest.php fix(private-key): implement transaction handling and error verification for private key storage operations 2025-09-09 16:46:38 +02:00
ProxyCustomCommandsTest.php feat(proxy): enhance proxy configuration regeneration by extracting custom commands 2025-10-07 11:11:13 +02:00
ServiceConfigurationRefreshTest.php fix: prevent duplicate services on image change and enable real-time UI refresh 2025-10-14 10:12:36 +02:00
ServiceNameSecurityTest.php fix: prevent command injection in Docker Compose parsing - add pre-save validation 2025-10-16 09:51:37 +02:00
ServiceParserImageUpdateTest.php fix: prevent duplicate services on image change and enable real-time UI refresh 2025-10-14 10:12:36 +02:00
SshRetryMechanismTest.php fix(ssh): introduce SshRetryHandler and SshRetryable trait for enhanced SSH command retry logic with exponential backoff and error handling 2025-09-07 17:17:35 +02:00
ValidateShellSafePathTest.php fix: prevent command injection in Docker Compose parsing - add pre-save validation 2025-10-16 09:51:37 +02:00
ValidGitRepositoryUrlTest.php fix(validation): update git:// URL validation to support port numbers and tilde characters in paths 2025-09-29 12:21:15 +02:00
ValidHostnameTest.php feat: implement ValidHostname validation rule and integrate it into server creation process 2025-10-10 11:03:13 +02:00
VolumeArrayFormatSecurityTest.php fix: prevent command injection in Docker Compose parsing - add pre-save validation 2025-10-16 09:51:37 +02:00
VolumeSecurityTest.php fix: prevent command injection in Docker Compose parsing - add pre-save validation 2025-10-16 09:51:37 +02:00