Skip to content

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

fix(annotation-queues): enforce read scope in typeById (#13519)

Max Deichmannd676ee2c01e2
diff --git a/web/src/__tests__/server/annotation-queue-items-trpc.servertest.ts b/web/src/__tests__/server/annotation-queue-items-trpc.servertest.ts
new file mode 100644
index 0000000000..a53e418a03
--- /dev/null
+++ b/web/src/__tests__/server/annotation-queue-items-trpc.servertest.ts
@@ -0,0 +1,118 @@
+import { appRouter } from "@/src/server/api/root";
+import { createInnerTRPCContext } from "@/src/server/api/trpc";
+import { AnnotationQueueObjectType } from "@langfuse/shared";
+import { prisma } from "@langfuse/shared/src/db";
+import { createOrgProjectAndApiKey } from "@langfuse/shared/src/server";
+import type { Session } from "next-auth";
+import { v4 as uuidv4 } from "uuid";
+
+describe("annotationQueueItems trpc", () => {
+ const orgIds: string[] = [];
+
+ type TestSetup = Awaited<ReturnType<typeof createOrgProjectAndApiKey>>;
+
+ const createCallerForProjectRole = (
+ setup: TestSetup,
+ projectRole: "ADMIN" | "NONE" = "ADMIN",
+ ) => {
+ const session: Session = {
+ expires: "1",
+ user: {
+ id: "user-1",
+ name: "Demo User",
+ canCreateOrganizations: true,
+ admin: false,
+ organizations: [
+ {
+ id: setup.org.id,
+ name: setup.org.name,
+ role: "MEMBER",
+ plan: "cloud:hobby",
+ cloudConfig: undefined,
+ metadata: {},
+ projects: [
+ {
+ id: setup.project.id,
+ role: projectRole,
+ name: setup.project.name,
+ deletedAt: null,
+ retentionDays: null,
+ metadata: {},
+ },
+ ],
+ },
+ ],
+ featureFlags: {
+ templateFlag: true,
+ excludeClickhouseRead: false,
+ },
+ },
+ environment: {} as Session["environment"],
+ };
+
+ const ctx = createInnerTRPCContext({ session, headers: {} });
+
+ return {
+ caller: appRouter.createCaller({ ...ctx, prisma }),
+ };
+ };
+
+ afterAll(async () => {
+ await prisma.organization.deleteMany({
+ where: {
+ id: {
+ in: orgIds,
+ },
+ },
+ });
+ });
+
+ describe("typeById", () => {
+ it("requires annotationQueues:read access", async () => {
+ const setup = await createOrgProjectAndApiKey();
+ orgIds.push(setup.org.id);
+
+ const { caller: adminCaller } = createCallerForProjectRole(
+ setup,
+ "ADMIN",
+ );
+ const queue = await prisma.annotationQueue.create({
+ data: {
+ name: "Test Queue",
+ description: "Test Queue Description",
+ scoreConfigIds: [],
+ projectId: setup.project.id,
+ },
+ });
+ const item = await prisma.annotationQueueItem.create({
+ data: {
+ queueId: queue.id,
+ objectId: uuidv4(),
+ objectType: AnnotationQueueObjectType.TRACE,
+ projectId: setup.project.id,
+ },
+ });
+
+ await expect(
+ adminCaller.annotationQueueItems.typeById({
+ projectId: setup.project.id,
+ queueId: queue.id,
+ itemId: item.id,
+ }),
+ ).resolves.toBe(AnnotationQueueObjectType.TRACE);
+
+ const { caller: limitedCaller } = createCallerForProjectRole(
+ setup,
+ "NONE",
+ );
+
+ await expect(
+ limitedCaller.annotationQueueItems.typeById({
+ projectId: setup.project.id,
+ queueId: queue.id,
+ itemId: item.id,
+ }),
+ ).rejects.toThrow("User does not have access to this resource or action");
+ });
+ });
+});
diff --git a/web/src/features/annotation-queues/server/annotationQueueItemsRouter.ts b/web/src/features/annotation-queues/server/annotationQueueItemsRouter.ts
index bba93d257e..9293cdde35 100644
--- a/web/src/features/annotation-queues/server/annotationQueueItemsRouter.ts
+++ b/web/src/features/annotation-queues/server/annotationQueueItemsRouter.ts
@@ -71,6 +71,12 @@ export const queueItemRouter = createTRPCRouter({
}),
)
.query(async ({ input, ctx }) => {
+ throwIfNoProjectAccess({
+ session: ctx.session,
+ projectId: input.projectId,
+ scope: "annotationQueues:read",
+ });
+
const item = await ctx.prisma.annotationQueueItem.findUnique({
where: {
id: input.itemId,