mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 02:32:44 +00:00
fix: harden config prototype-key guards (#22968) (thanks @Clawborn)
This commit is contained in:
23
src/config/legacy.shared.test.ts
Normal file
23
src/config/legacy.shared.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { mergeMissing } from "./legacy.shared.js";
|
||||
|
||||
describe("mergeMissing prototype pollution guard", () => {
|
||||
afterEach(() => {
|
||||
delete (Object.prototype as Record<string, unknown>).polluted;
|
||||
});
|
||||
|
||||
it("ignores __proto__ keys without polluting Object.prototype", () => {
|
||||
const target = { safe: { keep: true } } as Record<string, unknown>;
|
||||
const source = JSON.parse('{"safe":{"next":1},"__proto__":{"polluted":true}}') as Record<
|
||||
string,
|
||||
unknown
|
||||
>;
|
||||
|
||||
mergeMissing(target, source);
|
||||
|
||||
expect((target.safe as Record<string, unknown>).keep).toBe(true);
|
||||
expect((target.safe as Record<string, unknown>).next).toBe(1);
|
||||
expect(target.polluted).toBeUndefined();
|
||||
expect((Object.prototype as Record<string, unknown>).polluted).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user