From dd6ba90661a9893b46557cacb98efc2558361a81 Mon Sep 17 00:00:00 2001 From: MOLW <85048713+MatrixAdventurer@users.noreply.github.com> Date: Wed, 21 Oct 2026 10:14:12 +0800 Subject: [PATCH] fix(openclaw): reject malformed health responses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 由 LW 授权的 ChatGPT Business 智能体提交。 --- .../openclaw/openclaw/__tests__/http-client.test.ts | 10 ++++++++++ plugins/openclaw/openclaw/http-client.ts | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/openclaw/openclaw/__tests__/http-client.test.ts b/plugins/openclaw/openclaw/__tests__/http-client.test.ts index 86044fc7..4c2692b8 100644 --- a/plugins/openclaw/openclaw/__tests__/http-client.test.ts +++ b/plugins/openclaw/openclaw/__tests__/http-client.test.ts @@ -155,6 +155,16 @@ describe("Group 3: Cloud API Communication", () => { expect(result.instance_id).toBe("i-1"); }); + it.each([ + ["an object without status", { instance_id: "i-1", db: true }], + ["an empty status", { status: " ", instance_id: "i-1", db: true }], + ["a non-object response", "ok"], + ])("3.29a healthCheck rejects %s", async (_description, response) => { + fetchMock.respondWith(200, response); + + await expect(transport.healthCheck()).rejects.toThrow(/invalid health response/i); + }); + it("3.30 unknown tool throws", async () => { await expect(transport.callTool("memory_nonexistent", {})) .rejects.toThrow(/Unknown Memoria tool/); diff --git a/plugins/openclaw/openclaw/http-client.ts b/plugins/openclaw/openclaw/http-client.ts index 1945f407..b899c10e 100644 --- a/plugins/openclaw/openclaw/http-client.ts +++ b/plugins/openclaw/openclaw/http-client.ts @@ -332,8 +332,12 @@ export class MemoriaHttpTransport { async healthCheck(): Promise<{ status: string; instance_id?: string; db?: boolean }> { const data = await this.get("/health/instance"); const rec = this.asRecord(data); + const status = typeof rec?.status === "string" ? rec.status.trim() : ""; + if (!status) { + throw new Error("Invalid health response: missing status"); + } return { - status: typeof rec?.status === "string" ? rec.status : "ok", + status, instance_id: typeof rec?.instance_id === "string" ? rec.instance_id : undefined, db: typeof rec?.db === "boolean" ? rec.db : undefined, };