Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
Validate snapshot ids (#5330)
David Tippett875d165d8e40
diff --git a/apps/api/src/controllers/v2/__tests__/agent-zdr-passthrough.test.ts b/apps/api/src/controllers/v2/__tests__/agent-zdr-passthrough.test.tsindex 895c65a89..f04914380 100644--- a/apps/api/src/controllers/v2/__tests__/agent-zdr-passthrough.test.ts+++ b/apps/api/src/controllers/v2/__tests__/agent-zdr-passthrough.test.ts@@ -25,6 +25,7 @@ vi.mock("../../../lib/browser-sessions", () => ({}));const JOB_ID = "job-123";+const SNAPSHOT_ID = "0199a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a5b";function upstream(status: number, body: unknown) {vi.mocked(fetch).mockResolvedValue(@@ -120,12 +121,34 @@ describe("agent passthroughs for zero data retention runs", () => {upstream(404, body);const res = makeRes();- await agentSnapshotController(makeReq({ snapshotId: "snap-1" }), res);+ await agentSnapshotController(makeReq({ snapshotId: SNAPSHOT_ID }), res);expect(res.status).toHaveBeenCalledWith(404);expect(res.json).toHaveBeenCalledWith(body);+ expect(fetch).toHaveBeenCalledWith(+ `https://agent.example/internal/extracts/${JOB_ID}/snapshots/${SNAPSHOT_ID}`,+ {+ headers: {+ Authorization: "Bearer test",+ "x-team-id": "team-123",+ },+ },+ );});+ it.each(["snap-1", "..%2F..%2Fother", "../../other", `${SNAPSHOT_ID}/..`])(+ "snapshot rejects a malformed snapshot id %s",+ async snapshotId => {+ const res = makeRes();++ await agentSnapshotController(makeReq({ snapshotId }), res);++ expect(res.status).toHaveBeenCalledWith(400);+ expect(fetch).not.toHaveBeenCalled();+ expect(getAgentJobAccess).not.toHaveBeenCalled();+ },+ );+it("skill forwards 410 zdr_expired", async () => {const body = { code: "zdr_expired", error: "Expired." };upstream(410, body);diff --git a/apps/api/src/controllers/v2/agent-snapshot.ts b/apps/api/src/controllers/v2/agent-snapshot.tsindex ae3f342ee..cacca0938 100644--- a/apps/api/src/controllers/v2/agent-snapshot.ts+++ b/apps/api/src/controllers/v2/agent-snapshot.ts@@ -1,4 +1,5 @@import { Response } from "express";+import { validate as isUuid } from "uuid";import { config } from "../../config";import { getAgentJobAccess } from "../../lib/operational-job-access";import { AgentSnapshotResponse, RequestWithAuth } from "./types";@@ -11,6 +12,13 @@ export async function agentSnapshotController(>,res: Response<AgentSnapshotResponse>,) {+ if (!isUuid(req.params.snapshotId)) {+ return res.status(400).json({+ success: false,+ error: "Invalid snapshot ID format. Snapshot ID must be a valid UUID.",+ });+ }+const access = await getAgentJobAccess(req.params.jobId);if (@@ -29,10 +37,11 @@ export async function agentSnapshotController(}const upstream = await fetch(- `${config.EXTRACT_V3_BETA_URL}/internal/extracts/${req.params.jobId}/snapshots/${req.params.snapshotId}`,+ `${config.EXTRACT_V3_BETA_URL}/internal/extracts/${encodeURIComponent(req.params.jobId)}/snapshots/${encodeURIComponent(req.params.snapshotId)}`,{headers: {Authorization: `Bearer ${config.AGENT_INTEROP_SECRET}`,+ "x-team-id": req.auth.team_id,},},);