mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(Code Node): Only Block os.system vs Blocking import os (#16885)
This commit is contained in:
@@ -28,30 +28,18 @@ export async function LoadPyodide(packageCacheDir: string): Promise<PyodideInter
|
||||
)) as PyodideInterface;
|
||||
|
||||
await pyodideInstance.runPythonAsync(`
|
||||
blocked_modules = ["os"]
|
||||
import os
|
||||
|
||||
import sys
|
||||
for module_name in blocked_modules:
|
||||
del sys.modules[module_name]
|
||||
def blocked_system(*args, **kwargs):
|
||||
raise RuntimeError("os.system is blocked for security reasons.")
|
||||
|
||||
os.system = blocked_system
|
||||
|
||||
from importlib.abc import MetaPathFinder
|
||||
from importlib.machinery import ModuleSpec
|
||||
from types import ModuleType
|
||||
from typing import Sequence, Optional
|
||||
|
||||
class ImportBlocker(MetaPathFinder):
|
||||
def find_spec(
|
||||
self,
|
||||
fullname: str,
|
||||
path: Sequence[bytes | str] | None,
|
||||
target: ModuleType | None = None,
|
||||
) -> Optional[ModuleSpec]:
|
||||
if fullname in blocked_modules:
|
||||
raise ModuleNotFoundError(f"Module {fullname!r} is blocked", name=fullname)
|
||||
return None
|
||||
|
||||
sys.meta_path.insert(0, ImportBlocker())
|
||||
|
||||
from _pyodide_core import jsproxy_typedict
|
||||
from js import Object
|
||||
`);
|
||||
|
||||
Reference in New Issue
Block a user