Skip to content

Commit ba24636

Browse files
Claude Botclaude
andcommitted
fix(CookieMap): use identifierToUSVString for property name conversion
When creating a CookieMap from an object, calling propertyName.string() directly could cause a null pointer reference crash with UBSAN. This change uses identifierToUSVString() which properly handles the conversion of property names to strings, following the same pattern used in JSDOMConvertRecord.h. Fixes: ENG-21750 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ddcec61 commit ba24636

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/bun.js/bindings/webcore/JSCookieMap.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ template<> JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES JSCookieMapDOMConstructo
164164
auto valueStr = value.toString(lexicalGlobalObject)->value(lexicalGlobalObject);
165165
RETURN_IF_EXCEPTION(throwScope, {});
166166

167-
record.set(propertyName.string(), valueStr);
167+
auto keyStr = identifierToUSVString(*lexicalGlobalObject, propertyName);
168+
RETURN_IF_EXCEPTION(throwScope, {});
169+
170+
record.set(keyStr, valueStr);
168171
}
169172
init = WTFMove(record);
170173
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { expect, test } from "bun:test";
2+
3+
// https://linear.app/oven/issue/ENG-21750
4+
// CookieMap constructor should not crash when passed an object with symbol properties
5+
test("CookieMap should handle objects with symbol properties without crashing", () => {
6+
// This should not crash - Bun object has symbol properties
7+
const cookieMap = new Bun.CookieMap(Bun);
8+
expect(cookieMap).toBeInstanceOf(Bun.CookieMap);
9+
10+
// Also test with a custom object that has symbol properties
11+
const obj = {
12+
foo: "bar",
13+
[Symbol.for("test")]: "value",
14+
[Symbol("local")]: "another",
15+
};
16+
const cookieMap2 = new Bun.CookieMap(obj);
17+
expect(cookieMap2).toBeInstanceOf(Bun.CookieMap);
18+
// Symbol properties should be skipped, but string properties should work
19+
expect(cookieMap2.get("foo")).toBe("bar");
20+
});

0 commit comments

Comments
 (0)