Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(dashboards): reject unsupported sort columns (#19069)

Valery Meleshkinf696389f0776
diff --git a/web/src/__tests__/server/dashboard-service-delete.servertest.ts b/web/src/__tests__/server/dashboard-service-delete.servertest.ts
index 4aea0a1a28..fce803708b 100644
--- a/web/src/__tests__/server/dashboard-service-delete.servertest.ts
+++ b/web/src/__tests__/server/dashboard-service-delete.servertest.ts
@@ -3,7 +3,11 @@ import {
createOrgProjectAndApiKey,
DashboardService,
} from "@langfuse/shared/src/server";
-import { LangfuseNotFoundError, LangfuseConflictError } from "@langfuse/shared";
+import {
+ LangfuseNotFoundError,
+ LangfuseConflictError,
+ type OrderByState,
+} from "@langfuse/shared";
import { DashboardWidgetViews, prisma } from "@langfuse/shared/src/db";
import { appRouter } from "@/src/server/api/root";
import { createInnerTRPCContext } from "@/src/server/api/trpc";
@@ -77,6 +81,47 @@ async function createOwnerCaller() {
};
}
+describe("dashboard.allDashboards", () => {
+ it.each(["startTime", "name; SELECT pg_sleep(1)"])(
+ "returns BAD_REQUEST for unsupported sort column %s",
+ async (column) => {
+ const { projectId, caller } = await createOwnerCaller();
+
+ await expect(
+ caller.dashboard.allDashboards({
+ projectId,
+ page: 0,
+ limit: 50,
+ orderBy: { column, order: "DESC" },
+ }),
+ ).rejects.toMatchObject({
+ code: "BAD_REQUEST",
+ } satisfies Partial<TRPCError>);
+ },
+ );
+
+ it("accepts supported sort columns and the default sort", async () => {
+ const { projectId, caller } = await createOwnerCaller();
+ const sorts: OrderByState[] = [
+ { column: "name", order: "ASC" },
+ { column: "createdAt", order: "DESC" },
+ { column: "updatedAt", order: "DESC" },
+ null,
+ ];
+
+ for (const orderBy of sorts) {
+ await expect(
+ caller.dashboard.allDashboards({
+ projectId,
+ page: 0,
+ limit: 50,
+ orderBy,
+ }),
+ ).resolves.toHaveProperty("dashboards");
+ }
+ });
+});
+
describe("DashboardService.deleteDashboard", () => {
it("deletes an existing dashboard and throws LangfuseNotFoundError on repeat delete", async () => {
const { projectId } = await createOrgProjectAndApiKey();
diff --git a/web/src/features/dashboard/server/dashboard-router.ts b/web/src/features/dashboard/server/dashboard-router.ts
index c34a9d996e..0503b15dcf 100644
--- a/web/src/features/dashboard/server/dashboard-router.ts
+++ b/web/src/features/dashboard/server/dashboard-router.ts
@@ -47,7 +47,12 @@ const ListDashboardsInput = z.object({
// The Home-dashboard picker and clone detection fetch the whole list in one
// page, so allow a higher ceiling than the default table pagination.
limit: z.coerce.number().int().positive().lte(500).default(50),
- orderBy: orderBy,
+ orderBy: orderBy.refine(
+ (value) =>
+ value === null ||
+ ["name", "createdAt", "updatedAt"].includes(value.column),
+ { message: "Invalid dashboard sort column", path: ["column"] },
+ ),
});
// Get dashboard by ID input schema