T09 · Insecure Skill Coding Practices
Error
- Location
src/index.ts:38- Finding
Host-Realm Constructors Permit JavaScript Sandbox Escape
- Content
View full analysis
{ // Capture console methods const consoleMock = { log: (...args: unknown[]) => { logs.push(args.map(a => typeof a === 'object' ? JSON.stringify(a) : String(a)).join(' ')); }, warn: (...args: unknown[]) => { logs.push('[warn] ' + args.map(a => typeof a === 'object' ? JSON.stringify(a) : String(a)).join(' ')); }, error: (...args: unknown[]) => { logs.push('[error] ' + args.map(a => typeof a === 'object' ? JSON.stringify(a) : String(a)).join(' ')); }, }; return { INPUT: input, console: consoleMock, JSON, Math, Date, Array, Object, String, Number, RegExp, Map, Set, parseInt, parseFloat, isNaN, isFinite, encodeURIComponent, decodeURIComponent, atob: (s: string) => Buffer.from(s, 'base64').toString('binary'), btoa: (s: string) => Buffer.from(s, 'binary').toString('base64'), // Explicitly undefined — blocked require: undefined, process: undefined, globalThis: undefined, global: undefined, }; } ``` The globals are then placed into contexts that execute user-controlled code: ```ts const globals = createSandboxGlobals(input, logs); const context = vm.createContext(globals, { codeGeneration: { strings: false, wasm: false }, }); // Wrap code so the last expression is returned const wrapped = `(function() {\n${code}\n})()`; const script = new vm.Script(wrapped, { filename: 'sandbox.js' }); const result = script.runInContext(context, { timeout: timeoutMs }); ``` The same vulnerable globals are used by `eval_expression`: ```ts const globals = createSandboxGlobals(undefined, []); co ...[truncated 4031 chars]- Remediation
View remediation
