@devries-cameron20 / t3code-1 / commits / 3ee4aa62ec
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): accept ASCII whitespace in base64 image payloads (#31798)

Darsh Mahadevia committed Nov 15, 2026 at 03:03 UTC 3ee4aa62ec0ed16375e3f28c8ad2138a44ebaa88
2 files changed +14 -8
apps/server/src/imageMime.test.ts
+13 -7
@@ -10,16 +10,22 @@ describe("imageMime", () => {
10 });
11 });
12
13 - it("parses base64 data URL with spaces in payload", () => {
14 - expect(parseBase64DataUrl("data:image/png;base64,SGVs bG8=\n")).toEqual({
15 - mimeType: "image/png",
16 - base64: "SGVsbG8=",
17 - });
18 - });
13 + it.each(["\t", "\n", "\f", "\r", " "])(
14 + "parses base64 data URL with ASCII whitespace %j",
15 + (space) => {
16 + expect(parseBase64DataUrl(`data:image/png;base64,SGVs${space}bG8=\n`)).toEqual({
17 + mimeType: "image/png",
18 + base64: "SGVsbG8=",
19 + });
20 + },
21 + );
22
23 it("rejects payload with characters outside the base64 alphabet", () => {
24 expect(parseBase64DataUrl("data:image/png;base64,SGVs!bG8=")).toBeNull();
25 expect(parseBase64DataUrl("data:image/png;base64,SGVs,bG8=")).toBeNull();
26 + for (const space of ["\v", "\u00a0", "\u2003"]) {
27 + expect(parseBase64DataUrl(`data:image/png;base64,SGVs${space}bG8=`)).toBeNull();
28 + }
29 });
30
31 // regression: #3952 image upload crashed dispatchCommand with a stack overflow
@@ -43,7 +49,7 @@ describe("imageMime", () => {
49
50 it("rejects empty and whitespace-only payloads", () => {
51 expect(parseBase64DataUrl("data:image/png;base64,")).toBeNull();
46 - expect(parseBase64DataUrl("data:image/png;base64, \r\n")).toBeNull();
52 + expect(parseBase64DataUrl("data:image/png;base64, \t\r\n\f")).toBeNull();
53 });
54
55 it("parses a case-insensitive scheme and mime type", () => {
apps/server/src/imageMime.ts
+1 -1
@@ -42,7 +42,7 @@ function isBase64Char(code: number): boolean {
42 }
43
44 function isBase64Whitespace(code: number): boolean {
45 - return code === 0x0d || code === 0x0a || code === 0x20;
45 + return code === 0x09 || code === 0x0a || code === 0x0c || code === 0x0d || code === 0x20;
46 }
47
48 // V8 regexes use the JS stack; scanning image payloads can overflow a deep fiber stack.