Skip to content

Commit 93cb679

Browse files
dguidoclaudethomas-chauchefoin-tob
authored
Expand dangerous imports blocklist for better coverage (#215)
* Expand dangerous imports blocklist for better coverage Add ~40 additional modules to UNSAFE_IMPORTS including: - Network modules (requests, aiohttp, httplib, etc.) - FFI modules (ctypes, _ctypes) - Profiling/debugging (cProfile, profile, pdb, timeit, trace) - Pickle recursion (pickle, dill, cloudpickle, joblib) - Filesystem (shutil, tempfile, distutils) - Import manipulation (importlib, pkgutil, zipimport) - Torch dangerous (torch.hub, torch._dynamo, torch._inductor, torch.jit) --------- Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Co-Authored-By: Thomas Chauchefoin <thomas.chauchefoin@trailofbits.com>
1 parent 6d20564 commit 93cb679

File tree

2 files changed

+55
-31
lines changed

2 files changed

+55
-31
lines changed

fickling/analysis.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ class UnsafeImportsML(Analysis):
240240
"urllib": "This module can use HTTP to leak local data and download malicious files.",
241241
"urllib2": "This module can use HTTP to leak local data and download malicious files.",
242242
"torch.hub": "This module can load untrusted files from the web, exposing the system to arbitrary code execution.",
243+
"torch._dynamo": "This module can compile and execute arbitrary code through dynamic compilation.",
244+
"torch._inductor": "This module can compile and execute arbitrary native code.",
245+
"torch.jit": "This module can compile and execute arbitrary code through JIT compilation.",
246+
"torch.compile": "This module can compile and execute arbitrary code through dynamic compilation.",
247+
"numpy.f2py": "This module can compile and execute arbitrary Fortran/C code.",
248+
"numpy.distutils": "This module can execute arbitrary build commands.",
243249
"dill": "This module can load and execute arbitrary code.",
244250
"code": "This module can compile and execute arbitrary code.",
245251
"pty": "This module contains functions that can perform system operations and execute arbitrary code.",
@@ -260,10 +266,6 @@ class UnsafeImportsML(Analysis):
260266
"So this import is safe only if restrictions on pickle (such as Fickling's hooks) have been set properly",
261267
},
262268
"numpy.testing._private.utils": {"runstring": "This function can execute arbitrary code."},
263-
"numpy.f2py.crackfortran": {
264-
"getlincoef": "This function can execute arbitrary code.",
265-
"_eval_length": "This function can execute arbitrary code.",
266-
},
267269
"_io": {"FileIO": "This class can read/write arbitrary files."},
268270
"io": {"FileIO": "This class can read/write arbitrary files."},
269271
}

fickling/fickle.py

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,64 +40,86 @@
4040

4141
UNSAFE_IMPORTS: frozenset[str] = frozenset(
4242
[
43-
# Core builtins and system modules
43+
# Builtins - can execute arbitrary code
4444
"__builtin__",
4545
"__builtins__",
4646
"builtins",
47+
# System/process execution
4748
"os",
4849
"posix",
4950
"nt",
5051
"subprocess",
5152
"sys",
52-
"socket",
5353
"pty",
54+
"commands", # Legacy Python 2 module
55+
"multiprocessing",
56+
# Code execution/compilation
57+
"code",
58+
"codeop",
59+
"runpy",
5460
"marshal",
5561
"types",
56-
"runpy",
57-
"cProfile",
58-
"ctypes",
59-
"pydoc",
62+
"compile",
63+
"exec",
64+
"eval",
65+
# Import manipulation
6066
"importlib",
61-
"code",
62-
"multiprocessing",
63-
# File and shell operations
64-
"shutil",
65-
"distutils",
66-
"commands",
67+
"pkgutil",
68+
"zipimport",
6769
# Operator module bypasses
6870
"_operator",
6971
"operator",
7072
"functools",
71-
# Async subprocess execution
72-
"asyncio",
73-
# Code execution via profilers/debuggers
73+
# Profiling/debugging (can execute code)
74+
"cProfile",
7475
"profile",
75-
"trace",
7676
"pdb",
7777
"bdb",
7878
"timeit",
79-
"doctest",
80-
# Package and environment manipulation
81-
"venv",
82-
"pip",
83-
"ensurepip",
84-
# Network and web modules
85-
"webbrowser",
86-
"aiohttp",
79+
"trace",
80+
# Network - data exfiltration/download
81+
"socket",
82+
"ssl",
8783
"httplib",
8884
"http",
89-
"ssl",
90-
"requests",
9185
"urllib",
9286
"urllib2",
87+
"requests",
88+
"aiohttp",
89+
"asyncio", # Can run arbitrary coroutines
90+
"webbrowser", # Can open arbitrary URLs
9391
"smtplib",
9492
"imaplib",
9593
"ftplib",
9694
"poplib",
9795
"telnetlib",
9896
"nntplib",
99-
# IDE and dev tools
97+
# FFI/native code execution
98+
"ctypes",
99+
"_ctypes",
100+
# Pickle recursion (nested pickle attacks)
101+
"pickle",
102+
"_pickle",
103+
"dill",
104+
"cloudpickle",
105+
"joblib",
106+
# File system operations
107+
"shutil",
108+
"tempfile",
109+
"filecmp",
110+
"distutils",
111+
# Shell/terminal
112+
"pydoc", # Can run code via pydoc.pager
113+
"pexpect",
114+
# Virtual environments (can install packages)
115+
"venv",
116+
"ensurepip",
117+
"pip",
118+
# Documentation testing (can run code)
119+
"doctest",
120+
# IDLE modules (code execution)
100121
"idlelib",
122+
# Parser generators (code execution)
101123
"lib2to3",
102124
]
103125
)

0 commit comments

Comments
 (0)