GitHub advisory · PyPI
Fickling MLAllowlist analysis can miss non-allowlisted imports
Description
The issue was confirmed and resolved in https://github.com/trailofbits/fickling/commit/41ce7cb01edd97072994039574a2301ebb3f463d. Users are affected when running the MLAllowlist analysis pass after another pass within the same analysis context, in which case it would fail to flag non-allowlisted imports.
This fix makes MLAllowlist functional again, and opt-in as originally intended, after upgrading to fix. If it is needed to scan ML pickles with an import allowlist, update calls to check_safety() to pass MLAllowlist in the analyzer parameter:
pickled = Pickled([ ... ])
analyzer = Analyzer([MLAllowlist()])
res = check_safety(pickled, analyzer=analyzer)
UnsafeImportsML.analyze() unconditionally calls context.shorten_code(node) on every import, even ones it doesn't flag. MLAllowlist.analyze() then sees already_reported=True and skips its allowlist check entirely. MLAllowlist is dead code for all imports for the shared-context/pass-order qualification; but a fresh independent pass can report the import. Not an UnusedVariables bypass. Tests 1–2 in the PoC demonstrate the defect independently. MLAllowlist flags ast.parse as LIKELY_UNSAFE on a fresh context, returns 0 findings after UnsafeImportsML pollutes the shared state. Test 3 shows the full pipeline result.
ast.parse: not in UNSAFE_IMPORTS, not in ML_ALLOWLIST. check_safety() returns LIKELY_SAFE with 0 findings on 0.1.11. 139 stdlib modules are unblocked. Root cause is AnalysisContext.reported_shortened_code shared across all passes with no per-analyzer namespace.
PoC (tested against 0.1.11 from PyPI):
""" fickling MLAllowlist bypass via shorten_code shared state
Tested: fickling 0.1.11 """
import sys
from fickling.analysis import ( AnalysisContext, UnsafeImportsML, check_safety, Severity ) from fickling.ml import MLAllowlist, ML_ALLOWLIST from fickling.fickle import Pickled, UNSAFE_IMPORTS import fickling.fickle as op
def build_payload(module:…
Manual fix · PyPI
pip install --upgrade "fickling>=0.1.12"Sources