Skip to content
Merged
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
19 changes: 19 additions & 0 deletions web/actions/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ import cronstrue from "cronstrue";
import { startMigration } from "./migrations";
import { inngest } from "@/lib/inngest/client";

function isValidImageReferencePart(reference: string): boolean {
// Allow only characters that are valid in Docker tags/digests and avoid path traversal.
// Tags: letters, digits, underscores, periods and dashes; Digests: "algorithm:hex".
// This regex is intentionally conservative.
const tagPattern = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$/;
const digestPattern = /^[A-Za-z0-9_+.-]+:[0-9a-fA-F]{32,256}$/;

return reference === "latest" ||
tagPattern.test(reference) ||
digestPattern.test(reference);
}

function parseImageReference(image: string): {
registry: string;
namespace: string;
Expand Down Expand Up @@ -96,6 +108,13 @@ export async function validateDockerImage(
parseImageReference(image);
const reference = digest || tag || "latest";

if (!isValidImageReferencePart(reference)) {
return {
valid: false,
error: "Invalid image tag or digest",
};
}

if (registry === "docker.io") {
const repoPath =
namespace === "library" ? repository : `${namespace}/${repository}`;
Expand Down