Security: Insecure PyTorch model loading in file_utils.py (weights_only=False)
Hey team,
I noticed that in flair/file_utils.py, the load_torch_state function explicitly calls PyTorch's torch.load with weights_only=False.
return torch.load(f, map_location="cpu", weights_only=False)As you probably know, standard pickle-based PyTorch models can contain arbitrary executable python code. By hardcoding weights_only=False, any user who downloads and loads a malicious .pt model via Flair will unknowingly execute arbitrary code on their machine. PyTorch recently changed their default to weights_only=True to prevent this exact supply chain attack vector.
If backwards compatibility is required, it might be worth explicitly warning the user, or providing a safer default that requires the user to opt-in to loading unsafe models.
Let me know if there's a private channel where I should have reported this, or if you'd like a PR to help address it.
Thanks, Siva Aditya
Source: flairNLP/flair