Skip to content

Allow user to specify weights_only=True to tighten security#10666

Open
zaz wants to merge 7 commits intopyg-team:masterfrom
zaz:fix/torch-load-weights-only-param
Open

Allow user to specify weights_only=True to tighten security#10666
zaz wants to merge 7 commits intopyg-team:masterfrom
zaz:fix/torch-load-weights-only-param

Conversation

@zaz
Copy link
Copy Markdown

@zaz zaz commented Apr 11, 2026

Fixes #10665.

The first two commits allow users of the function to pass weights_only=True, but has no existing changes other than a security clarification in an error message.

The second two commits add a deprecation warning and a test. The idea behind this is that we would eventually follow upstream's convention of preventing arbitrary code execution by default, only allowing it if the user explicitly opts in. This addresses the ever-increasing threat of cyber-attacks in this domain. Users may want to use PyG on untrusted or semi-trusted data; prior to this PR, this was totally unsafe.

Add a `weights_only` parameter to `fs.torch_load` so callers can
control the security-sensitive fallback behavior:

- `weights_only=None` (default): preserve current fallback behavior
- `weights_only=True`: strict mode, raise on failure (no fallback)
- `weights_only=False`: skip the weights_only=True attempt entirely

The default behavior is unchanged, keeping full backward compatibility.
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 11, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.20%. Comparing base (c211214) to head (b899cf5).
⚠️ Report is 194 commits behind head on master.

Files with missing lines Patch % Lines
torch_geometric/io/fs.py 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10666      +/-   ##
==========================================
- Coverage   86.11%   84.20%   -1.91%     
==========================================
  Files         496      510      +14     
  Lines       33655    36029    +2374     
==========================================
+ Hits        28981    30339    +1358     
- Misses       4674     5690    +1016     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

zaz added 5 commits April 11, 2026 16:45
Emit a FutureWarning when the weights_only=True attempt fails and
torch_load silently falls back to weights_only=False. In a future
release this fallback will be removed - callers should pass an
explicit weights_only value.
@zaz zaz force-pushed the fix/torch-load-weights-only-param branch from b899cf5 to 3d262f3 Compare April 11, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SECURITY] Users have no way to enforce weights_only=True

1 participant