The Open Framework for Building Agents
fix(eve): validate OpenAPI path parameter segments (#4931)
Allen Zhou0857ff4ecade
diff --git a/.changeset/tidy-path-parameters.md b/.changeset/tidy-path-parameters.mdnew file mode 100644index 000000000..132f01314--- /dev/null+++ b/.changeset/tidy-path-parameters.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Reject OpenAPI path parameter values equal to `.` or `..` before sending requests, so URL normalization cannot change the intended route. This validation also applies to application-provided arguments.diff --git a/docs/connections/openapi.mdx b/docs/connections/openapi.mdxindex cdcf6355a..062eab774 100644--- a/docs/connections/openapi.mdx+++ b/docs/connections/openapi.mdx@@ -119,6 +119,8 @@ Filters match `operationId`. If an operation does not declare one, use the deterWhen an operation path contains dynamic segments, the spec must declare matching OpenAPI path parameters. eve exposes path, query, header, and cookie parameters as top-level tool inputs, then substitutes `in: "path"` values into the matching `{name}` placeholder before making the request.+Path parameter values must not be exactly `.` or `..`. eve rejects these values before URL parsing can normalize them and change the route, including values resolved through `toolCall.providedArguments`. Other values remain URL-encoded during substitution, including embedded slashes.+```ts title="agent/connections/cart.ts"import { defineOpenAPIConnection } from "eve/connections";diff --git a/packages/eve/src/runtime/connections/openapi-client.test.ts b/packages/eve/src/runtime/connections/openapi-client.test.tsindex 0660c521f..dfe79b470 100644--- a/packages/eve/src/runtime/connections/openapi-client.test.ts+++ b/packages/eve/src/runtime/connections/openapi-client.test.ts@@ -317,6 +317,53 @@ describe("OpenApiConnectionClient", () => {expect((init.headers as Record<string, string>).Authorization).toBe("Bearer secret");});+ it.each([".", ".."])(+ "rejects dot segments in path parameter %j before sending a request",+ async (id) => {+ const fetchMock = vi.fn();+ vi.stubGlobal("fetch", fetchMock);+ const client = new OpenApiConnectionClient(makeConnection());++ await expect(client.executeTool("getProject", { id }, EXECUTE_OPTIONS)).rejects.toThrow(+ 'Path parameter "id" for tool "getProject" in connection "test" must not be "." or "..".',+ );+ expect(fetchMock).not.toHaveBeenCalled();+ },+ );++ it("validates resolved application-provided path parameters", async () => {+ const fetchMock = vi.fn();+ vi.stubGlobal("fetch", fetchMock);+ const client = new OpenApiConnectionClient(+ makeConnection({ toolCall: { providedArguments: { id: Promise.resolve("..") } } }),+ );++ await expect(+ client.executeTool("getProject", { id: "prj_1" }, EXECUTE_OPTIONS),+ ).rejects.toThrow('Path parameter "id"');+ expect(fetchMock).not.toHaveBeenCalled();+ });++ it.each([+ ["release.v1/café 100%", "release.v1%2Fcaf%C3%A9%20100%25"],+ ["folder/../item", "folder%2F..%2Fitem"],+ ["folder/./item", "folder%2F.%2Fitem"],+ ])("preserves application-provided path value %j and its encoding", async (id, encodedId) => {+ const fetchMock = vi.fn(async (_url: URL) => new Response(null, { status: 200 }));+ vi.stubGlobal("fetch", fetchMock);+ const client = new OpenApiConnectionClient(+ makeConnection({+ toolCall: { providedArguments: { id } },+ }),+ );++ await client.executeTool("getProject", { id: "..", teamId: ".." }, EXECUTE_OPTIONS);++ expect(fetchMock).toHaveBeenCalledOnce();+ const [calledUrl] = fetchMock.mock.calls[0]!;+ expect(calledUrl.toString()).toBe(`https://api.example.com/v1/projects/${encodedId}?teamId=..`);+ });+it("resolves auth and headers from the active caller", async () => {const fetchMock = vi.fn(async (_url: URL, _init: RequestInit) => new Response(null, { status: 200 }),diff --git a/packages/eve/src/runtime/connections/openapi-client.ts b/packages/eve/src/runtime/connections/openapi-client.tsindex eef02af26..1f4a6f8d5 100644--- a/packages/eve/src/runtime/connections/openapi-client.ts+++ b/packages/eve/src/runtime/connections/openapi-client.ts@@ -421,7 +421,14 @@ export class OpenApiConnectionClient implements ConnectionClient {continue;}if (param.location === "path") {- path = path.replace(`{${param.name}}`, encodeURIComponent(String(value)));+ const pathValue = String(value);+ // URL parsing normalizes dot segments even after encodeURIComponent.+ if (pathValue === "." || pathValue === "..") {+ throw new Error(+ `Path parameter "${param.name}" for tool "${operation.toolName}" in connection "${this.#connection.connectionName}" must not be "." or "..".`,+ );+ }+ path = path.replace(`{${param.name}}`, encodeURIComponent(pathValue));} else if (param.location === "query") {appendQuery(query, param.name, value);} else if (param.location === "cookie") {