From 1b6b30066f098e52862022e805ff8b7203bfc6c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=85=E8=86=80?= Date: Fri, 23 Oct 2026 23:21:25 +0800 Subject: [PATCH] fix(filter): read only own payload properties Inherited object properties are not webhook payload data. Read own properties only so JSONPath cannot traverse prototypes. --- server/lib/events/filter-ast.ts | 10 +++++++--- tests/filter-ast.test.ts | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/server/lib/events/filter-ast.ts b/server/lib/events/filter-ast.ts index 4baca79..87627ce 100644 --- a/server/lib/events/filter-ast.ts +++ b/server/lib/events/filter-ast.ts @@ -172,7 +172,8 @@ function stringify(value: unknown): string { if (typeof value === "string") return value; if (value === undefined || value === null) return ""; if (typeof value === "number" || typeof value === "boolean") return String(value); - return JSON.stringify(value); + // Payload values are JSON; anything else (should it appear) compares as "". + return JSON.stringify(value) ?? ""; } function toNumber(value: unknown): number | null { @@ -203,8 +204,11 @@ function walkPath(node: unknown, parts: string[], index: number, out: unknown[]) return; } if (node === null || node === undefined || typeof node !== "object") return; - const next = (node as Record)[parts[index]!]; - walkPath(next, parts, index + 1, out); + // Own properties only: `constructor`, `__proto__`, `toString`... are not + // payload data and must never reach the comparison. + const key = parts[index]!; + if (!Object.prototype.hasOwnProperty.call(node, key)) return; + walkPath((node as Record)[key], parts, index + 1, out); } function valueList(filter: Filter, event: WebhookEvent): unknown[] { diff --git a/tests/filter-ast.test.ts b/tests/filter-ast.test.ts index ac67f2c..4335702 100644 --- a/tests/filter-ast.test.ts +++ b/tests/filter-ast.test.ts @@ -191,3 +191,13 @@ describe("filter-ast pattern engine", () => { expect(evaluateFilterNode({ type: "repo", match: "acme" }, ev)).toBe(false); }); }); + +describe("filter-ast payload paths", () => { + test("never reads inherited properties", () => { + const node = { type: "field" as const, path: "constructor", match: "x" }; + expect(evaluateFilterNode(node, event())).toBe(false); + expect(evaluateFilterNode({ type: "field", path: "__proto__", op: "exists" }, event())).toBe( + false, + ); + }); +});