mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 22:38:26 +00:00
fix (gateway): harden chat.send message input sanitization
This commit is contained in:
20
src/gateway/server-methods/chat.sanitize-message.test.ts
Normal file
20
src/gateway/server-methods/chat.sanitize-message.test.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { sanitizeChatSendMessageInput } from "./chat.js";
|
||||
|
||||
describe("sanitizeChatSendMessageInput", () => {
|
||||
it("rejects null bytes", () => {
|
||||
expect(sanitizeChatSendMessageInput("before\u0000after")).toEqual({
|
||||
ok: false,
|
||||
error: "message must not contain null bytes",
|
||||
});
|
||||
});
|
||||
|
||||
it("strips unsafe control characters while preserving tab/newline/carriage return", () => {
|
||||
const result = sanitizeChatSendMessageInput("a\u0001b\tc\nd\re\u0007f\u007f");
|
||||
expect(result).toEqual({ ok: true, message: "ab\tc\nd\ref" });
|
||||
});
|
||||
|
||||
it("normalizes unicode to NFC", () => {
|
||||
expect(sanitizeChatSendMessageInput("Cafe\u0301")).toEqual({ ok: true, message: "Café" });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user