Skip to content

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

fix(api): reject invalid public pagination pages (#15918)

Max Deichmannf509cbd6241c
diff --git a/packages/shared/src/utils/zod.ts b/packages/shared/src/utils/zod.ts
index 52d3e5e3c6..2ff8a0f83f 100644
--- a/packages/shared/src/utils/zod.ts
+++ b/packages/shared/src/utils/zod.ts
@@ -59,7 +59,7 @@ export const paginationZod = {
export const publicApiPaginationZod = {
page: z.preprocess(
(x) => (x === "" ? undefined : x),
- z.coerce.number().gt(0).default(1),
+ z.coerce.number().int().gt(0).default(1),
),
limit: publicApiPaginationLimitZod,
};
diff --git a/web/src/__tests__/server/llm-connections-api.servertest.ts b/web/src/__tests__/server/llm-connections-api.servertest.ts
index c8e40e3adb..a1a22bb5cf 100644
--- a/web/src/__tests__/server/llm-connections-api.servertest.ts
+++ b/web/src/__tests__/server/llm-connections-api.servertest.ts
@@ -239,7 +239,24 @@ describe("/api/public/llm-connections API Endpoints", () => {
});
it("should return 400 for invalid query parameters", async () => {
- const [negativePageResponse, negativeLimitResponse] = await Promise.all([
+ const [
+ zeroPageResponse,
+ fractionalPageResponse,
+ negativePageResponse,
+ negativeLimitResponse,
+ ] = await Promise.all([
+ makeAPICall(
+ "GET",
+ "/api/public/llm-connections?page=0&limit=10",
+ undefined,
+ auth,
+ ),
+ makeAPICall(
+ "GET",
+ "/api/public/llm-connections?page=0.5&limit=10",
+ undefined,
+ auth,
+ ),
makeAPICall(
"GET",
"/api/public/llm-connections?page=-1&limit=10",
@@ -254,6 +271,8 @@ describe("/api/public/llm-connections API Endpoints", () => {
),
]);
+ expect(zeroPageResponse.status).toBe(400);
+ expect(fractionalPageResponse.status).toBe(400);
expect(negativePageResponse.status).toBe(400);
expect(negativeLimitResponse.status).toBe(400);
});
diff --git a/web/src/features/public-api/types/llm-connections.ts b/web/src/features/public-api/types/llm-connections.ts
index 5d4125521a..9d5d9f802a 100644
--- a/web/src/features/public-api/types/llm-connections.ts
+++ b/web/src/features/public-api/types/llm-connections.ts
@@ -1,6 +1,6 @@
import { z } from "zod";
import {
- paginationZod,
+ publicApiPaginationZod,
LLMAdapter,
type JSONValue,
BedrockConfigSchema,
@@ -31,7 +31,7 @@ export const LlmConnectionResponse = z
// GET /api/public/llm-connections query parameters
export const GetLlmConnectionsV1Query = z
.object({
- ...paginationZod,
+ ...publicApiPaginationZod,
})
.strict();