Skip to content

Fix insecure default temp file path in session dump/load#751

Open
eddieran wants to merge 1 commit intouqfoundation:masterfrom
eddieran:fix/secure-session-tempfile
Open

Fix insecure default temp file path in session dump/load#751
eddieran wants to merge 1 commit intouqfoundation:masterfrom
eddieran:fix/secure-session-tempfile

Conversation

@eddieran
Copy link
Copy Markdown

Summary

Fixes #749 — the default /tmp/session.pkl path used by dump_module(), load_module(), and load_module_asdict() is insecure because /tmp is world-writable and shared, making it vulnerable to symlink attacks and race conditions.

Changes

  • Symlink rejection: Added _check_symlink() that uses os.lstat() to reject symlinks before reading or writing session files.
  • Safe file creation: Added _safe_open_for_writing() that uses os.open() with O_CREAT | O_EXCL | O_WRONLY and mode 0o600 for race-free exclusive file creation. If the file already exists, it verifies it is not a symlink before opening.
  • SecurityWarning: Emits a SecurityWarning when the default shared /tmp/session.pkl path is used, advising users to pass an explicit filename.
  • Tests: Added test_symlink_rejected() and test_default_path_warning() to test_session.py.

Files changed

  • dill/session.py — security helpers and warning in dump_module, load_module, load_module_asdict
  • dill/tests/test_session.py — new security tests

Test plan

  • Existing dump_module/load_module/load_module_asdict behavior unchanged for explicit paths and stream objects
  • New test_symlink_rejected verifies symlinks are rejected by all three functions
  • New test_default_path_warning verifies SecurityWarning is emitted for the default path

The default /tmp/session.pkl path used by dump_module(), load_module(),
and load_module_asdict() is insecure because /tmp is world-writable and
shared, making it vulnerable to symlink attacks, pickle substitution,
and information disclosure.

- Add _check_symlink() using os.lstat() to reject symlinks
- Add _safe_open_for_writing() using O_CREAT|O_EXCL|O_WRONLY with 0o600
- Emit SecurityWarning when the default path is used
- Add test_symlink_rejected() and test_default_path_warning() tests

Fixes uqfoundation#749
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] Insecure default temp file path /tmp/session.pkl in dump_module/load_module

1 participant