Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dokploy): exclude password column from application queries #645

Open
wants to merge 9 commits into
base: canary
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const SaveDockerProvider = ({ applicationId }: Props) => {
if (data) {
form.reset({
dockerImage: data.dockerImage || "",
password: data.password || "",
password: "*".repeat(data.passwordLength || 0) || "",
username: data.username || "",
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { CheckCircle2, Terminal } from "lucide-react";
import React from "react";
import { toast } from "sonner";
import { DockerTerminalModal } from "../../settings/web-server/docker-terminal-modal";
import { RedbuildApplication } from "../rebuild-application";
import { RebuildApplication } from "../rebuild-application";
import { StartApplication } from "../start-application";
import { StopApplication } from "../stop-application";
import { DeployApplication } from "./deploy-application";
Expand Down Expand Up @@ -60,7 +60,7 @@ export const ShowGeneralApplication = ({ applicationId }: Props) => {
Autodeploy
{data?.autoDeploy && <CheckCircle2 className="size-4" />}
</Toggle>
<RedbuildApplication applicationId={applicationId} />
<RebuildApplication applicationId={applicationId} />
{data?.applicationStatus === "idle" ? (
<StartApplication applicationId={applicationId} />
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface Props {
applicationId: string;
}

export const RedbuildApplication = ({ applicationId }: Props) => {
export const RebuildApplication = ({ applicationId }: Props) => {
const { data } = api.application.one.useQuery(
{
applicationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ interface Props {
}

export const AddUserPermissions = ({ userId }: Props) => {
const { data: projects } = api.project.all.useQuery();

const { data, refetch } = api.user.byUserId.useQuery(
{
userId,
Expand Down
12 changes: 11 additions & 1 deletion apps/dokploy/pages/dashboard/project/[projectId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,17 @@ export type Services = {
status?: "idle" | "running" | "done" | "error";
};

type Project = Awaited<ReturnType<typeof findProjectById>>;
type ChangeFields<T, R> = Omit<T, keyof R> & R;

type Project = ChangeFields<
Awaited<ReturnType<typeof findProjectById>>,
{
applications: Omit<
Awaited<ReturnType<typeof findProjectById>>["applications"][number],
"password"
>[];
}
>;

export const extractServices = (data: Project | undefined) => {
const applications: Services[] =
Expand Down
10 changes: 9 additions & 1 deletion apps/dokploy/server/api/routers/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { cleanQueuesByApplication, myQueue } from "@/server/queues/queueSetup";
import { deploy } from "@/server/utils/deploy";
import { uploadFileSchema } from "@/utils/schema";
import {
type Application,
IS_CLOUD,
addNewService,
checkServiceAccess,
Expand Down Expand Up @@ -112,7 +113,14 @@ export const applicationRouter = createTRPCRouter({
message: "You are not authorized to access this application",
});
}
return application;
const {
password,
...rest
}: Awaited<ReturnType<typeof findApplicationById>> & {
passwordLength?: number;
} = application;
rest.passwordLength = application.password?.length || 0;
return rest;
}),

reload: protectedProcedure
Expand Down
9 changes: 9 additions & 0 deletions apps/dokploy/server/api/routers/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ export const projectRouter = createTRPCRouter({
applications.applicationId,
accesedServices,
),
columns: {
password: false,
},
},
mariadb: {
where: buildServiceFilter(mariadb.mariadbId, accesedServices),
Expand Down Expand Up @@ -143,6 +146,9 @@ export const projectRouter = createTRPCRouter({
),
with: {
applications: {
columns: {
password: false,
},
where: buildServiceFilter(
applications.applicationId,
accesedServices,
Expand Down Expand Up @@ -178,6 +184,9 @@ export const projectRouter = createTRPCRouter({
return await db.query.projects.findMany({
with: {
applications: {
columns: {
password: false,
},
with: {
domains: true,
},
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/services/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const findApplicationById = async (applicationId: string) => {
message: "Application not found",
});
}

return application;
};

Expand Down