Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/server/src/db/schema/application.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { VALID_BRANCH_REGEX } from "@dokploy/server/utils/git-branch-validation";
import { VALID_GIT_URL_REGEX } from "@dokploy/server/utils/git-url-validation";
import { relations } from "drizzle-orm";
import {
bigint,
Expand Down Expand Up @@ -512,7 +513,13 @@ export const apiSaveGitProvider = createSchema
enableSubmodules: true,
})
.required()
.extend({ customGitBranch: branchField })
.extend({
customGitBranch: branchField,
customGitUrl: z
.string()
.min(1)
.refine(VALID_GIT_URL_REGEX, "Invalid Git URL"),
})
.merge(
createSchema.pick({
customGitSSHKeyId: true,
Expand Down
20 changes: 20 additions & 0 deletions packages/server/src/utils/git-url-validation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Valid git URL patterns for HTTPS and SSH clone URLs.
// Rejects shell metacharacters that would enable command injection.
//
// HTTPS examples accepted:
// https://github.com/owner/repo.git
// http://gitlab.example.com/group/subgroup/repo.git
//
// SSH examples accepted:
// git@github.com:owner/repo.git
// ssh://git@gitlab.com:22/owner/repo.git
// git@gitea.example.com:owner/repo.git
//
// Rejected: $(...), `...`, ;, |, &, <, >, newlines, spaces outside of SSH scheme
const HTTPS_GIT_URL_REGEX = /^https?:\/\/[^\s;|&$`(){}[\]<>'"\\]+$/;
const SSH_GIT_URL_REGEX =
/^(?:ssh:\/\/)?[a-zA-Z_][a-zA-Z0-9_-]*@[a-zA-Z0-9.-]+(?::\d{1,5})?:[^\s;|&$`(){}[\]<>'"\\]+$/;

export const VALID_GIT_URL_REGEX = (url: string): boolean => {
return HTTPS_GIT_URL_REGEX.test(url) || SSH_GIT_URL_REGEX.test(url);
};