Skip to content

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

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

Fix insecure default temp file path in session dump/load#750
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 test_session.py tests pass
  • 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 is shared and world-writable, making
it vulnerable to symlink attacks. This commit:

- Adds _check_symlink() to reject symlinks before reading files
- Adds _safe_open_for_writing() using O_CREAT|O_EXCL for race-free
  file creation with 0o600 permissions
- Emits SecurityWarning when using the default shared temp path
- Adds tests for symlink rejection and the security warning

Closes #749

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

2 participants