Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/jsc/bindings/JSPropertyIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ extern "C" JSPropertyIterator* Bun__JSPropertyIterator__create(JSC::JSGlobalObje
ASSERT(count);

auto scope = DECLARE_THROW_SCOPE(vm);
JSC::PropertyNameArrayBuilder array(vm, PropertyNameMode::StringsAndSymbols, PrivateSymbolMode::Exclude);
// Strings only: the name crosses the FFI as a BunString, so a symbol key would be
// indistinguishable from a string key equal to its description (and leaked into
// serializers, child process env, HTTP/2 headers, etc.). Callers that need symbol
// keys use forEachProperty, which reports an isSymbol flag.
JSC::PropertyNameArrayBuilder array(vm, PropertyNameMode::Strings, PrivateSymbolMode::Exclude);

if (object->hasNonReifiedStaticProperties()) [[unlikely]] {
object->reifyAllStaticProperties(globalObject);
Expand Down
9 changes: 9 additions & 0 deletions test/js/bun/console/console-table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ describe("console.table", () => {
const actualOutput = renderTable(...args());
expect(actualOutput).toMatchSnapshot();
});

test("symbol-keyed properties are skipped", () => {
const sym = Symbol("SYMK");
expect(renderTable([{ a: 2, [sym]: 1 }])).toBe(renderTable([{ a: 2 }]));
expect(renderTable({ r: { a: 2, [sym]: 1 } })).toBe(renderTable({ r: { a: 2 } }));
// Symbol keys still print through Bun.inspect, whose property walk can
// represent them.
expect(Bun.inspect({ [sym]: 1 })).toBe("{\n [Symbol(SYMK)]: 1,\n}");
});
});

test("console.table json fixture", () => {
Expand Down
7 changes: 7 additions & 0 deletions test/js/bun/json5/json5.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,13 @@ describe("stringify", () => {
expect(JSON5.stringify(null)).toEqual("null");
});

test("skips symbol-keyed properties like JSON.stringify", () => {
const sym = Symbol("SYMK");
expect(JSON5.stringify({ a: 2, [sym]: 1 })).toEqual("{a:2}");
expect(JSON5.stringify({ [sym]: 1 })).toEqual("{}");
expect(JSON5.stringify({ [Symbol.iterator]: 1 })).toEqual("{}");
});

test("stringifies booleans", () => {
expect(JSON5.stringify(true)).toEqual("true");
expect(JSON5.stringify(false)).toEqual("false");
Expand Down
18 changes: 16 additions & 2 deletions test/js/bun/spawn/spawn-env.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { spawn } from "bun";
import { test } from "bun:test";
import { bunExe } from "harness";
import { expect, test } from "bun:test";
import { bunEnv, bunExe } from "harness";

test("spawn env", async () => {
const env = {};
Expand All @@ -22,3 +22,17 @@ test("spawn env", async () => {
} catch (e) {}
}
});

test("symbol-keyed env properties are not passed to the child", async () => {
await using proc = spawn({
cmd: [bunExe(), "-e", "console.log(JSON.stringify([process.env.SYMK ?? null, process.env.REALK ?? null]))"],
env: { ...bunEnv, REALK: "yes", [Symbol("SYMK")]: "leaked" },
stderr: "pipe",
});

const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);

expect(stdout).toBe('[null,"yes"]\n');
expect(stderr).toBe("");
expect(exitCode).toBe(0);
});
8 changes: 8 additions & 0 deletions test/js/bun/toml/toml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,14 @@ describe("TOML.stringify", () => {
expect(TOML.stringify({ "dotted.tbl": { a: 1 } })).toBe('["dotted.tbl"]\na = 1\n');
});

test("symbol-keyed properties are skipped", () => {
const sym = Symbol("SYMK");
expect(TOML.stringify({ a: 2, [sym]: 1 })).toBe("a = 2\n");
expect(TOML.stringify({ [sym]: 1 })).toBe("");
expect(TOML.stringify({ [Symbol.iterator]: 1 })).toBe("");
expect(TOML.stringify({ t: { a: 1, [sym]: 2 } })).toBe("[t]\na = 1\n");
});

test("string escaping is exact and round-trips", () => {
expect(TOML.stringify({ s: 'a"b\\c\nd\te\u0000f' })).toBe('s = "a\\"b\\\\c\\nd\\te\\u0000f"\n');
const original = { s: '\b\t\n\f\r"\\中🦊' };
Expand Down
11 changes: 9 additions & 2 deletions test/js/bun/yaml/yaml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2552,6 +2552,13 @@ config:
expect(YAML.stringify(undefined)).toBe(undefined);
});

test("skips symbol-keyed properties", () => {
const sym = Symbol("SYMK");
expect(YAML.stringify({ a: 2, [sym]: 1 })).toBe("{a: 2}");
expect(YAML.stringify({ [sym]: 1 })).toBe("{}");
expect(YAML.stringify({ [Symbol.iterator]: 1 })).toBe("{}");
});

test("stringifies booleans", () => {
expect(YAML.stringify(true)).toBe("true");
expect(YAML.stringify(false)).toBe("false");
Expand Down Expand Up @@ -4062,8 +4069,8 @@ refs:
normalKey: "normal value",
symbolValue: sym,
};
// Symbol keys are not enumerable, symbol values are undefined
expect(YAML.stringify(obj, null, 2)).toBe("normalKey: normal value\ntest: symbol key value");
// Symbol keys are skipped, symbol values are undefined
expect(YAML.stringify(obj, null, 2)).toBe("normalKey: normal value");
});

test("handles WeakMap and WeakSet", () => {
Expand Down
36 changes: 36 additions & 0 deletions test/js/node/http2/node-http2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,42 @@ it("sensitive headers should work", async () => {
}
});

it("should not send symbol-keyed properties of the headers object on the wire", async () => {
const server = http2.createServer();
let client;
try {
const received = Promise.withResolvers();
const closed = Promise.withResolvers();
server.on("stream", (stream, headers) => {
received.resolve(headers);
stream.respond({ ":status": 200 });
stream.end();
});
server.listen(0, () => {
const port = server.address().port;
client = http2.connect(`http://localhost:${port}`);
client.on("error", received.reject);
const req = client.request({
":path": "/",
"x-secret": "value",
[http2.sensitiveHeaders]: ["x-secret"],
[Symbol("x-arbitrary")]: "nope",
});
req.on("error", received.reject);
req.on("close", closed.resolve);
req.end();
});
const names = Object.keys(await received.promise);
expect(names).toContain("x-secret");
expect(names).not.toContain("nodejs.http2.sensitiveheaders");
expect(names).not.toContain("x-arbitrary");
await closed.promise;
} finally {
server.close();
client?.close?.();
}
});

it("http2 session.goaway() validates input types", async done => {
const { mustCall } = createCallCheckCtx(done);
const server = http2.createServer((req, res) => {
Expand Down