coolify/app/Http/Controllers/Api
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
..
ApplicationsController.php fix: improve Docker image digest handling and add auto-parse feature 2025-10-15 10:19:01 +02:00
DatabasesController.php fix: missing 422 error code in openapi spec 2025-10-12 14:20:45 +02:00
DeployController.php refactor(deployment): add validation for pull request existence in deployment process to enhance error handling 2025-09-10 14:31:29 +02:00
GithubController.php fix: missing 422 error code in openapi spec 2025-10-12 14:20:45 +02:00
OpenApi.php fix: missing 422 error code in openapi spec 2025-10-12 14:20:45 +02:00
OtherController.php fix: missing 422 error code in openapi spec 2025-10-12 14:20:45 +02:00
ProjectController.php fix: missing 422 error code in openapi spec 2025-10-12 14:20:45 +02:00
ResourcesController.php feat(auth): implement comprehensive authorization checks across API controllers 2025-08-23 18:51:10 +02:00
SecurityController.php fix: missing 422 error code in openapi spec 2025-10-12 14:20:45 +02:00
ServersController.php Merge branch 'next' into fix/openapi 2025-10-13 10:42:05 +02:00
ServicesController.php fix: prevent command injection in Docker Compose parsing - add pre-save validation 2025-10-16 09:51:37 +02:00
TeamController.php fix: hide sensitive email change fields in team member responses 2025-09-18 00:40:09 +08:00