B614 False Positive when using torch.jit.load
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.3k
- Forks
- 836
- Avg merge
- 5d 3h
- Merged PRs (30d)
- 1
Description
Describe the bug
B614 checks for the unsafe use of torch.load with the weights_only parameter omitted or set to False.
model = torch.load('model_weights.pth')
A false positive is triggered when loading the equivalent TorchScript load function which has no equivalent weights_only parameter.
https://docs.pytorch.org/docs/stable/generated/torch.jit.load.html
model = torch.jit.load('model_weights.pth')
Note also that torch.load uses weights_only=True by default as of version 2.6 and so B614 should query the torch version and allow torch.load without a user-set weights_only parameter as of version 2.6.
https://docs.pytorch.org/docs/stable/notes/serialization.html#weights-only
Reproduction steps
import torch
model = torch.jit.load('model_weights.pth')
Expected behavior
The code above should not trigger B614.
Bandit version
1.8.3 (Default)
Python version
3.13 (Default)
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the B614 check and reproduce the reported false positive with torch.jit.load. Update the check so TorchScript loading is not flagged, and account for torch.load's weights_only default from version 2.6; done means the reproduction no longer triggers B614 while unsafe older behavior remains covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- security
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100