fix(workflow): isolate local scripts in bounded QuickJS runtime
This commit is contained in:
1 parent
fac81b08e8
commit
2844fd49dd
7 files changed
+771
-696
No files matched your search
@@ -224,3 +224,34 @@ describe("MVEL lexical boundaries", () => {
|
||||
expect(result.allValid).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("isolated script runtime boundaries", () => {
|
||||
for (const code of [
|
||||
'return Object.constructor("return typeof process")();',
|
||||
'return console.log.constructor("return typeof Bun")();',
|
||||
'return items.constructor.constructor("return typeof fetch")();',
|
||||
]) {
|
||||
it(`does not expose the host through ${code}`, async () => {
|
||||
const result = await executeJavaScriptSandbox(code, { items: [] });
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.returnValue).toBe("undefined");
|
||||
});
|
||||
}
|
||||
it("does not mutate inputs or host prototypes", async () => {
|
||||
const inputs = { items: [{ amount: 1 }] };
|
||||
const result = await executeJavaScriptSandbox('items[0].amount = 9; Object.prototype.hoseProof = true; return items;', inputs);
|
||||
expect(result.returnValue).toEqual([{ amount: 9 }]);
|
||||
expect(inputs.items[0].amount).toBe(1);
|
||||
expect(({} as any).hoseProof).toBeUndefined();
|
||||
});
|
||||
it("bounds logs, allocations and synchronous return values", async () => {
|
||||
const logs = await executeJavaScriptSandbox('for (let i = 0; i < 1000; i++) console.log(i);');
|
||||
expect(logs.success).toBe(false);
|
||||
expect(logs.logs.length).toBeLessThanOrEqual(500);
|
||||
const memory = await executeJavaScriptSandbox('return "x".repeat(64 * 1024 * 1024);');
|
||||
expect(memory.success).toBe(false);
|
||||
expect((await executeJavaScriptSandbox('return Promise.resolve(1);')).success).toBe(false);
|
||||
expect((await executeJavaScriptSandbox('return 1;')).returnValue).toBe(1);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user