mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(Code Node): Upgrade pyodide, sandbox it, and prevent JS sandbox escape (#14356)
This commit is contained in:
committed by
GitHub
parent
9021e195fa
commit
6c9c720ae9
@@ -1,4 +1,5 @@
|
||||
import { dirname } from 'node:path';
|
||||
import { createContext, runInContext } from 'node:vm';
|
||||
import type { PyodideInterface } from 'pyodide';
|
||||
|
||||
let pyodideInstance: PyodideInterface | undefined;
|
||||
@@ -6,8 +7,22 @@ let pyodideInstance: PyodideInterface | undefined;
|
||||
export async function LoadPyodide(packageCacheDir: string): Promise<PyodideInterface> {
|
||||
if (pyodideInstance === undefined) {
|
||||
const { loadPyodide } = await import('pyodide');
|
||||
const { XMLHttpRequest } = await import('xmlhttprequest-ssl');
|
||||
const indexURL = dirname(require.resolve('pyodide'));
|
||||
pyodideInstance = await loadPyodide({ indexURL, packageCacheDir });
|
||||
const context = createContext({
|
||||
loadPyodide,
|
||||
indexURL,
|
||||
packageCacheDir,
|
||||
jsglobals: {
|
||||
Object,
|
||||
console,
|
||||
XMLHttpRequest,
|
||||
},
|
||||
});
|
||||
pyodideInstance = (await runInContext(
|
||||
'loadPyodide({ indexURL, packageCacheDir, jsglobals })',
|
||||
context,
|
||||
)) as PyodideInterface;
|
||||
|
||||
await pyodideInstance.runPythonAsync(`
|
||||
from _pyodide_core import jsproxy_typedict
|
||||
|
||||
Reference in New Issue
Block a user