Fix insecure default temp file path in session dump/load#751
Open
eddieran wants to merge 1 commit intouqfoundation:masterfrom
Open
Fix insecure default temp file path in session dump/load#751eddieran wants to merge 1 commit intouqfoundation:masterfrom
eddieran wants to merge 1 commit intouqfoundation:masterfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #749 — the default
/tmp/session.pklpath used bydump_module(),load_module(), andload_module_asdict()is insecure because/tmpis world-writable and shared, making it vulnerable to symlink attacks and race conditions.Changes
_check_symlink()that usesos.lstat()to reject symlinks before reading or writing session files._safe_open_for_writing()that usesos.open()withO_CREAT | O_EXCL | O_WRONLYand mode0o600for race-free exclusive file creation. If the file already exists, it verifies it is not a symlink before opening.SecurityWarningwhen the default shared/tmp/session.pklpath is used, advising users to pass an explicit filename.test_symlink_rejected()andtest_default_path_warning()totest_session.py.Files changed
dill/session.py— security helpers and warning indump_module,load_module,load_module_asdictdill/tests/test_session.py— new security testsTest plan
dump_module/load_module/load_module_asdictbehavior unchanged for explicit paths and stream objectstest_symlink_rejectedverifies symlinks are rejected by all three functionstest_default_path_warningverifiesSecurityWarningis emitted for the default path