fix: guard os.chmod(path.parent, 0o700) against system directories#26003
Closed
zccyman wants to merge 1 commit into
Closed
fix: guard os.chmod(path.parent, 0o700) against system directories#26003zccyman wants to merge 1 commit into
zccyman wants to merge 1 commit into
Conversation
os.chmod("/", 0o700) strips world-traversable permission from the root
inode, breaking DNS, networking, journald, Docker, and most system
services. This can happen when path.parent resolves to / (e.g. writing
to /.hermes_tokens).
Add safe_chmod_parent() in agent/file_safety.py that:
- Blocks chmod on / and 13 well-known system directories
- Verifies parent exists and is a directory
- Silently skips on failure (logs warning, no exception)
Replace all 5 os.chmod(path.parent, 0o700) call sites:
- agent/google_oauth.py: credentials path
- tools/mcp_oauth.py: OAuth token path
- hermes_cli/auth.py: auth store, Qwen CLI, Nous shared store
Closes NousResearch#25821
Collaborator
Contributor
Author
|
Thanks @alt-glitch for the catch. Duplicate of #25841/#25831 — both guard os.chmod(path.parent, 0o700) against system directories. Closing in favor of #25841. |
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
os.chmod("/", 0o700)strips world-traversable permission from the root inode, breaking DNS, networking, journald, Docker, and most system services. This can happen whenpath.parentresolves to/(e.g. writing to/.hermes_tokens).Fix
Add
safe_chmod_parent()inagent/file_safety.pythat:/and 13 well-known system directoriesReplace all 5
os.chmod(path.parent, 0o700)call sites:agent/google_oauth.py: Google OAuth credentials pathtools/mcp_oauth.py: MCP OAuth token pathhermes_cli/auth.py: auth store, Qwen CLI tokens, Nous shared storeTesting
Closes #25821