Spaces:
Sleeping
Sleeping
One more attempt at nerfing sys
Browse files
restrictedpython_code_eval.py
CHANGED
|
@@ -21,6 +21,7 @@ import copy
|
|
| 21 |
import faulthandler
|
| 22 |
import itertools
|
| 23 |
import importlib
|
|
|
|
| 24 |
import io
|
| 25 |
import multiprocessing
|
| 26 |
import os
|
|
@@ -407,7 +408,10 @@ ALLOWED_SYS_NAMES = ['maxsize']
|
|
| 407 |
class AllowListImporter:
|
| 408 |
def __init__(self, allowed_imports: List[str]):
|
| 409 |
self.allowed_imports = allowed_imports
|
| 410 |
-
|
|
|
|
|
|
|
|
|
|
| 411 |
for key in list(dir(inner_sys)):
|
| 412 |
if key not in ALLOWED_SYS_NAMES:
|
| 413 |
delattr(inner_sys, key)
|
|
|
|
| 21 |
import faulthandler
|
| 22 |
import itertools
|
| 23 |
import importlib
|
| 24 |
+
import importlib.util
|
| 25 |
import io
|
| 26 |
import multiprocessing
|
| 27 |
import os
|
|
|
|
| 408 |
class AllowListImporter:
|
| 409 |
def __init__(self, allowed_imports: List[str]):
|
| 410 |
self.allowed_imports = allowed_imports
|
| 411 |
+
sys_spec = importlib.util.find_spec('sys')
|
| 412 |
+
inner_sys = importlib.util.module_from_spec(sys_spec) # type: ignore
|
| 413 |
+
sys_spec.loader.exec_module(inner_sys) # type: ignore
|
| 414 |
+
|
| 415 |
for key in list(dir(inner_sys)):
|
| 416 |
if key not in ALLOWED_SYS_NAMES:
|
| 417 |
delattr(inner_sys, key)
|