The vulnerability in Picklescan allows for a remote code execution (RCE) by failing to detect a malicious pickle that uses the numpy.f2py.crackfortran._eval_length function. The root cause of this vulnerability is an incomplete blocklist and a flawed detection logic in the scanner.
The analysis of the patch in commit 70c1c6c31beb6baaf52c8db1b6c3c0e84a6f9dab reveals two key changes:
- The
_unsafe_globals dictionary in src/picklescan/scanner.py was updated to include "numpy.f2py": "*". This explicitly marks the numpy.f2py module as dangerous.
- The logic in the
_build_scan_result_from_raw_globals function was improved to recursively check for dangerous parent modules. The original logic only checked the top-level module, which allowed the dangerous numpy.f2py.crackfortran._eval_length to go undetected because numpy itself was not on the blocklist.
The vulnerable function is _build_scan_result_from_raw_globals because it contained the flawed logic that failed to detect the malicious pickle. When Picklescan analyzes a pickle file, this function is called to determine the safety of the globals used. Due to the vulnerability, it would incorrectly classify the malicious pickle as safe, leading to a potential RCE when the pickle is loaded by the user.