mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Compare commits
13 Commits
fix/issues
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10d17de186 | ||
|
|
65f0919fa7 | ||
|
|
9b7abfbed7 | ||
|
|
6676a86b34 | ||
|
|
d603654ac1 | ||
|
|
d9ffe519b0 | ||
|
|
fa91a74462 | ||
|
|
d7794286be | ||
|
|
f337dd7e01 | ||
|
|
5d5d95bbd3 | ||
|
|
7be1084a10 | ||
|
|
19a525fac1 | ||
|
|
7984497398 |
@@ -1,6 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
containerRestart,
|
containerRestart,
|
||||||
findServerById,
|
|
||||||
getConfig,
|
getConfig,
|
||||||
getContainers,
|
getContainers,
|
||||||
getContainersByAppLabel,
|
getContainersByAppLabel,
|
||||||
@@ -10,9 +9,6 @@ import {
|
|||||||
} from "@dokploy/server";
|
} from "@dokploy/server";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { createTRPCRouter, protectedProcedure } from "../trpc";
|
import { createTRPCRouter, protectedProcedure } from "../trpc";
|
||||||
import { TRPCError } from "@trpc/server";
|
|
||||||
|
|
||||||
export const containerIdRegex = /^[a-zA-Z0-9.\-_]+$/;
|
|
||||||
|
|
||||||
export const dockerRouter = createTRPCRouter({
|
export const dockerRouter = createTRPCRouter({
|
||||||
getContainers: protectedProcedure
|
getContainers: protectedProcedure
|
||||||
@@ -21,23 +17,14 @@ export const dockerRouter = createTRPCRouter({
|
|||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input }) => {
|
||||||
if (input.serverId) {
|
|
||||||
const server = await findServerById(input.serverId);
|
|
||||||
if (server.organizationId !== ctx.session?.activeOrganizationId) {
|
|
||||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return await getContainers(input.serverId);
|
return await getContainers(input.serverId);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
restartContainer: protectedProcedure
|
restartContainer: protectedProcedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
containerId: z
|
containerId: z.string().min(1),
|
||||||
.string()
|
|
||||||
.min(1)
|
|
||||||
.regex(containerIdRegex, "Invalid container id."),
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input }) => {
|
||||||
@@ -47,20 +34,11 @@ export const dockerRouter = createTRPCRouter({
|
|||||||
getConfig: protectedProcedure
|
getConfig: protectedProcedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
containerId: z
|
containerId: z.string().min(1),
|
||||||
.string()
|
|
||||||
.min(1)
|
|
||||||
.regex(containerIdRegex, "Invalid container id."),
|
|
||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input }) => {
|
||||||
if (input.serverId) {
|
|
||||||
const server = await findServerById(input.serverId);
|
|
||||||
if (server.organizationId !== ctx.session?.activeOrganizationId) {
|
|
||||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return await getConfig(input.containerId, input.serverId);
|
return await getConfig(input.containerId, input.serverId);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@@ -70,17 +48,11 @@ export const dockerRouter = createTRPCRouter({
|
|||||||
appType: z
|
appType: z
|
||||||
.union([z.literal("stack"), z.literal("docker-compose")])
|
.union([z.literal("stack"), z.literal("docker-compose")])
|
||||||
.optional(),
|
.optional(),
|
||||||
appName: z.string().min(1).regex(containerIdRegex, "Invalid app name."),
|
appName: z.string().min(1),
|
||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input }) => {
|
||||||
if (input.serverId) {
|
|
||||||
const server = await findServerById(input.serverId);
|
|
||||||
if (server.organizationId !== ctx.session?.activeOrganizationId) {
|
|
||||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return await getContainersByAppNameMatch(
|
return await getContainersByAppNameMatch(
|
||||||
input.appName,
|
input.appName,
|
||||||
input.appType,
|
input.appType,
|
||||||
@@ -91,18 +63,12 @@ export const dockerRouter = createTRPCRouter({
|
|||||||
getContainersByAppLabel: protectedProcedure
|
getContainersByAppLabel: protectedProcedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
appName: z.string().min(1).regex(containerIdRegex, "Invalid app name."),
|
appName: z.string().min(1),
|
||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
type: z.enum(["standalone", "swarm"]),
|
type: z.enum(["standalone", "swarm"]),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input }) => {
|
||||||
if (input.serverId) {
|
|
||||||
const server = await findServerById(input.serverId);
|
|
||||||
if (server.organizationId !== ctx.session?.activeOrganizationId) {
|
|
||||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return await getContainersByAppLabel(
|
return await getContainersByAppLabel(
|
||||||
input.appName,
|
input.appName,
|
||||||
input.type,
|
input.type,
|
||||||
@@ -113,34 +79,22 @@ export const dockerRouter = createTRPCRouter({
|
|||||||
getStackContainersByAppName: protectedProcedure
|
getStackContainersByAppName: protectedProcedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
appName: z.string().min(1).regex(containerIdRegex, "Invalid app name."),
|
appName: z.string().min(1),
|
||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input }) => {
|
||||||
if (input.serverId) {
|
|
||||||
const server = await findServerById(input.serverId);
|
|
||||||
if (server.organizationId !== ctx.session?.activeOrganizationId) {
|
|
||||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return await getStackContainersByAppName(input.appName, input.serverId);
|
return await getStackContainersByAppName(input.appName, input.serverId);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getServiceContainersByAppName: protectedProcedure
|
getServiceContainersByAppName: protectedProcedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
appName: z.string().min(1).regex(containerIdRegex, "Invalid app name."),
|
appName: z.string().min(1),
|
||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input }) => {
|
||||||
if (input.serverId) {
|
|
||||||
const server = await findServerById(input.serverId);
|
|
||||||
if (server.organizationId !== ctx.session?.activeOrganizationId) {
|
|
||||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return await getServiceContainersByAppName(input.appName, input.serverId);
|
return await getServiceContainersByAppName(input.appName, input.serverId);
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -459,15 +459,6 @@ export const settingsRouter = createTRPCRouter({
|
|||||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.serverId) {
|
|
||||||
const server = await findServerById(input.serverId);
|
|
||||||
|
|
||||||
if (server.organizationId !== ctx.session?.activeOrganizationId) {
|
|
||||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return readConfigInPath(input.path, input.serverId);
|
return readConfigInPath(input.path, input.serverId);
|
||||||
}),
|
}),
|
||||||
getIp: protectedProcedure.query(async ({ ctx }) => {
|
getIp: protectedProcedure.query(async ({ ctx }) => {
|
||||||
|
|||||||
@@ -6,9 +6,6 @@ import {
|
|||||||
} from "@dokploy/server";
|
} from "@dokploy/server";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { createTRPCRouter, protectedProcedure } from "../trpc";
|
import { createTRPCRouter, protectedProcedure } from "../trpc";
|
||||||
import { TRPCError } from "@trpc/server";
|
|
||||||
import { findServerById } from "@dokploy/server";
|
|
||||||
import { containerIdRegex } from "./docker";
|
|
||||||
|
|
||||||
export const swarmRouter = createTRPCRouter({
|
export const swarmRouter = createTRPCRouter({
|
||||||
getNodes: protectedProcedure
|
getNodes: protectedProcedure
|
||||||
@@ -17,24 +14,12 @@ export const swarmRouter = createTRPCRouter({
|
|||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input }) => {
|
||||||
if (input.serverId) {
|
|
||||||
const server = await findServerById(input.serverId);
|
|
||||||
if (server.organizationId !== ctx.session?.activeOrganizationId) {
|
|
||||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return await getSwarmNodes(input.serverId);
|
return await getSwarmNodes(input.serverId);
|
||||||
}),
|
}),
|
||||||
getNodeInfo: protectedProcedure
|
getNodeInfo: protectedProcedure
|
||||||
.input(z.object({ nodeId: z.string(), serverId: z.string().optional() }))
|
.input(z.object({ nodeId: z.string(), serverId: z.string().optional() }))
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input }) => {
|
||||||
if (input.serverId) {
|
|
||||||
const server = await findServerById(input.serverId);
|
|
||||||
if (server.organizationId !== ctx.session?.activeOrganizationId) {
|
|
||||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return await getNodeInfo(input.nodeId, input.serverId);
|
return await getNodeInfo(input.nodeId, input.serverId);
|
||||||
}),
|
}),
|
||||||
getNodeApps: protectedProcedure
|
getNodeApps: protectedProcedure
|
||||||
@@ -43,29 +28,17 @@ export const swarmRouter = createTRPCRouter({
|
|||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input }) => {
|
||||||
if (input.serverId) {
|
|
||||||
const server = await findServerById(input.serverId);
|
|
||||||
if (server.organizationId !== ctx.session?.activeOrganizationId) {
|
|
||||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getNodeApplications(input.serverId);
|
return getNodeApplications(input.serverId);
|
||||||
}),
|
}),
|
||||||
getAppInfos: protectedProcedure
|
getAppInfos: protectedProcedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
appName: z.string().min(1).regex(containerIdRegex, "Invalid app name."),
|
appName: z.string(),
|
||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input }) => {
|
||||||
if (input.serverId) {
|
|
||||||
const server = await findServerById(input.serverId);
|
|
||||||
if (server.organizationId !== ctx.session?.activeOrganizationId) {
|
|
||||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return await getApplicationInfo(input.appName, input.serverId);
|
return await getApplicationInfo(input.appName, input.serverId);
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -75,24 +75,6 @@ export const userRouter = createTRPCRouter({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// If user not found in the organization, deny access
|
|
||||||
if (!memberResult) {
|
|
||||||
throw new TRPCError({
|
|
||||||
code: "NOT_FOUND",
|
|
||||||
message: "User not found in this organization",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allow access if:
|
|
||||||
// 1. User is requesting their own information
|
|
||||||
// 2. User has owner role (admin permissions) AND user is in the same organization
|
|
||||||
if (memberResult.userId !== ctx.user.id && ctx.user.role !== "owner") {
|
|
||||||
throw new TRPCError({
|
|
||||||
code: "UNAUTHORIZED",
|
|
||||||
message: "You are not authorized to access this user",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return memberResult;
|
return memberResult;
|
||||||
}),
|
}),
|
||||||
get: protectedProcedure.query(async ({ ctx }) => {
|
get: protectedProcedure.query(async ({ ctx }) => {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import { backups } from "./backups";
|
|||||||
import { projects } from "./project";
|
import { projects } from "./project";
|
||||||
import { schedules } from "./schedule";
|
import { schedules } from "./schedule";
|
||||||
import { certificateType } from "./shared";
|
import { certificateType } from "./shared";
|
||||||
import { paths } from "@dokploy/server/constants";
|
|
||||||
/**
|
/**
|
||||||
* This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
|
* This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
|
||||||
* database instance for multiple projects.
|
* database instance for multiple projects.
|
||||||
@@ -237,31 +236,7 @@ export const apiModifyTraefikConfig = z.object({
|
|||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
});
|
});
|
||||||
export const apiReadTraefikConfig = z.object({
|
export const apiReadTraefikConfig = z.object({
|
||||||
path: z
|
path: z.string().min(1),
|
||||||
.string()
|
|
||||||
.min(1)
|
|
||||||
.refine(
|
|
||||||
(path) => {
|
|
||||||
// Prevent directory traversal attacks
|
|
||||||
if (path.includes("../") || path.includes("..\\")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { MAIN_TRAEFIK_PATH } = paths();
|
|
||||||
if (path.startsWith("/") && !path.startsWith(MAIN_TRAEFIK_PATH)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Prevent null bytes and other dangerous characters
|
|
||||||
if (path.includes("\0") || path.includes("\x00")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message:
|
|
||||||
"Invalid path: path traversal or unauthorized directory access detected",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user