fix(settings): create the identity key file with owner-only mode from the outset - #287
Open
kiwipaulrob wants to merge 1 commit into
Open
kiwipaulrob wants to merge 1 commit into
kiwipaulrob wants to merge 1 commit into
Conversation
… the outset The Noise identity private key was written with Path.write_text() and only then chmod-ed to 0600, leaving a window where it was readable by group/other under a permissive umask. Create the file via os.open(..., 0o600) so the restrictive mode applies from creation.
This branch has not been deployed
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.
Problem
_load_identity()persists the generated Noise identity private key with:The file is created with the process umask (commonly
0644) and only then restricted, so the private key is briefly readable by group/other — a write-then-chmod (TOCTOU) window. This key is the client's cryptographic identity and must stay stable across restarts, so an exposure is worth avoiding.Fix
Create the file with
os.open(..., 0o600)and write through the returned descriptor, so the restrictive mode applies atomically at creation.0600has no group/other bits for the umask to clear, so the result is owner-only on any normal umask.Verification
tests/test_settings.py:st_mode & 0o077 == 0);peer_idon reload.pytest— 148 passed;ruff check,ruff format --check,mypy sendspinclean.