Move debug log defaults out of /tmp and reject symlinks - #38
Merged
Conversation
The default debug_log_path and resolver_debug_log_path were in /tmp, which is world-writable on shared hosts. An attacker who pre-creates a symlink at /tmp/historian-debug.log pointing at e.g. an authorized_keys file could trick Historian (with debug mode on) into overwriting an arbitrary file, because _prepare_private_file opened with O_CREAT and no O_NOFOLLOW/O_EXCL. Two defenses, per the issue: - Move defaults under the XDG data dir (~/.local/share/historian/), which is not world-writable, matching how database_path already works. - Add O_NOFOLLOW to _prepare_private_file so a symlinked target is rejected at open time rather than followed, even for custom paths. Updates config.py, config.example.json, and docs/debugging.md. Adds tests for the new defaults and symlink rejection.
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
The default
debug_log_pathandresolver_debug_log_pathlived in/tmp(world-writable on shared hosts). An attacker who pre-creates a symlink at/tmp/historian-debug.log→ e.g.~/.ssh/authorized_keyscould trick Historian, with debug mode on, into overwriting an arbitrary file, because_prepare_private_fileopened withO_CREATand noO_NOFOLLOW/O_EXCL.This applies the issue's recommended Option 1 plus Option 2 as defense-in-depth:
~/.local/share/historian/), which is not world-writable — matching howdatabase_pathalready works. Updated inconfig.py,config.example.json, anddocs/debugging.md.O_NOFOLLOWto_prepare_private_fileso a symlinked target is rejected at open time rather than followed, even when a user sets a custom path.New tests verify the defaults no longer point at
/tmpand that a symlink target is refused (and the pointed-at file left untouched).Closes #23.
Test commands run
All 70 tests pass; compile check clean.