coolify/app/Livewire/Project/Service
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
..
Configuration.php fix: prevent duplicate services on image change and enable real-time UI refresh 2025-10-14 10:12:36 +02:00
Database.php feat(acl): Change views/backend code to able to use proper ACL's later on. Currently it is not enabled. 2025-08-26 10:27:38 +02:00
EditCompose.php fix(ui): Restrict service retrieval to current team 2025-02-27 12:17:23 +01:00
EditDomain.php fix: prevent duplicate services on image change and enable real-time UI refresh 2025-10-14 10:12:36 +02:00
FileStorage.php feat(storage): add read-only volume handling and UI notifications 2025-10-03 20:05:43 +02:00
Heading.php fix(service): ensure configuration changes are properly tracked and dispatched 2025-07-03 15:08:13 +02:00
Index.php feat(acl): Change views/backend code to able to use proper ACL's later on. Currently it is not enabled. 2025-08-26 10:27:38 +02:00
ServiceApplicationView.php move domain trimming before URL validation 2025-08-29 09:09:03 -04:00
StackForm.php fix: prevent command injection in Docker Compose parsing - add pre-save validation 2025-10-16 09:51:37 +02:00
Storage.php feat(storage): consolidate storage management into a single component with enhanced UI 2025-10-01 18:46:21 +02:00