From 2cb499fb64f05ddfccbc6b539b091d605935122c Mon Sep 17 00:00:00 2001 From: Shuvo Date: Mon, 17 Aug 2026 12:41:58 +0600 Subject: [PATCH] fix: prevent Postgres 100-argument limit crash and restore data parity for restricted-member project access The application table has 101 columns. The restricted-member branch of project.one (apps/dokploy/server/api/routers/project.ts) queried the applications relation with no columns narrowing, so Drizzle's relational query builder generated a json_build_array call with one argument per column, exceeding Postgres's FUNC_MAX_ARGS (100). Any non-owner/admin member with limited access to a project containing at least one application hit an opaque INTERNAL_SERVER_ERROR and got redirected away from the project/environment page instead of seeing their project. The same branch was also missing the "server" relation that the owner/admin path (findProjectById) already includes, so restricted members saw different (incomplete) data than owners/admins for the same project. Fixes this by extracting the existing serviceColumns column-selection constant to a module-level export in packages/server/src/services/project.ts and applying it (plus the server relation) to all 8 service relations in the restricted-member query path, matching the owner/admin path. --- apps/dokploy/server/api/routers/project.ts | 25 ++++++++++++++++++++++ packages/server/src/services/project.ts | 18 ++++++++-------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/apps/dokploy/server/api/routers/project.ts b/apps/dokploy/server/api/routers/project.ts index 2e35aee2a..43d2cf792 100644 --- a/apps/dokploy/server/api/routers/project.ts +++ b/apps/dokploy/server/api/routers/project.ts @@ -38,6 +38,7 @@ import { checkProjectAccess, findMemberByUserId, } from "@dokploy/server/services/permission"; +import { serviceColumns } from "@dokploy/server/services/project"; import { TRPCError } from "@trpc/server"; import { and, desc, eq, ilike, or, sql } from "drizzle-orm"; import type { AnyPgColumn } from "drizzle-orm/pg-core"; @@ -130,39 +131,63 @@ export const projectRouter = createTRPCRouter({ environments: { with: { applications: { + columns: { + ...serviceColumns, + applicationId: true, + icon: true, + }, + with: { server: { columns: { name: true } } }, where: buildServiceFilter( applications.applicationId, accessedServices, ), }, compose: { + columns: { + ...serviceColumns, + composeId: true, + composeStatus: true, + }, + with: { server: { columns: { name: true } } }, where: buildServiceFilter( compose.composeId, accessedServices, ), }, libsql: { + columns: { ...serviceColumns, libsqlId: true }, + with: { server: { columns: { name: true } } }, where: buildServiceFilter(libsql.libsqlId, accessedServices), }, mariadb: { + columns: { ...serviceColumns, mariadbId: true }, + with: { server: { columns: { name: true } } }, where: buildServiceFilter( mariadb.mariadbId, accessedServices, ), }, mongo: { + columns: { ...serviceColumns, mongoId: true }, + with: { server: { columns: { name: true } } }, where: buildServiceFilter(mongo.mongoId, accessedServices), }, mysql: { + columns: { ...serviceColumns, mysqlId: true }, + with: { server: { columns: { name: true } } }, where: buildServiceFilter(mysql.mysqlId, accessedServices), }, postgres: { + columns: { ...serviceColumns, postgresId: true }, + with: { server: { columns: { name: true } } }, where: buildServiceFilter( postgres.postgresId, accessedServices, ), }, redis: { + columns: { ...serviceColumns, redisId: true }, + with: { server: { columns: { name: true } } }, where: buildServiceFilter(redis.redisId, accessedServices), }, }, diff --git a/packages/server/src/services/project.ts b/packages/server/src/services/project.ts index 52ef679b4..04a628a86 100644 --- a/packages/server/src/services/project.ts +++ b/packages/server/src/services/project.ts @@ -47,16 +47,16 @@ export const createProject = async ( }; }; -export const findProjectById = async (projectId: string) => { - const serviceColumns = { - name: true, - description: true, - appName: true, - createdAt: true, - serverId: true, - applicationStatus: true, - } as const; +export const serviceColumns = { + name: true, + description: true, + appName: true, + createdAt: true, + serverId: true, + applicationStatus: true, +} as const; +export const findProjectById = async (projectId: string) => { const project = await db.query.projects.findFirst({ where: eq(projects.projectId, projectId), with: {