diff --git a/fickling/fickle.py b/fickling/fickle.py index f167c46..a81bf2d 100644 --- a/fickling/fickle.py +++ b/fickling/fickle.py @@ -768,6 +768,7 @@ def unsafe_imports(self) -> Iterator[Union[ast.Import, ast.ImportFrom]]: "builtins", "os", "posix", + "pty", "nt", "subprocess", "sys", diff --git a/test/test_hook.py b/test/test_hook.py index aa740eb..4b924b4 100644 --- a/test/test_hook.py +++ b/test/test_hook.py @@ -39,13 +39,19 @@ def __reduce__(self): return (os.system, ("echo 'I should have been stopped by the hook'",)) payload = Payload() + # Validate that pty-based execution is captured + payload_pty = b'''(cpty\nspawn\nS"id"\no.''' + # Save the payload in a pickle file with open("unsafe.pickle", "wb") as f: pickle.dump(payload, f) + with open("unsafe_pty.pickle", "wb") as f: + f.write(payload_pty) try: numpy.load("unsafe.pickle", allow_pickle=True) + numpy.load("unsafe_pty.pickle", allow_pickle=True) except UnpicklingError as e: if isinstance(e.__cause__, UnsafeFileError): pass