fix(security): guard os.chmod(parent) against / and system dirs (#25821)#25841
fix(security): guard os.chmod(parent) against / and system dirs (#25821)#25841vanthinh6886 wants to merge 1 commit into
Conversation
…Research#25821) Add safe_chmod_parent() to hermes_constants.py that refuses to chmod root or well-known system directories (/etc, /var, /usr, /home, etc.). Replace all 5 unprotected os.chmod(path.parent, 0o700) call sites: - hermes_cli/auth.py (3 sites: _save_auth_store, _save_qwen_cli_tokens, _save_nous_shared_token) - tools/mcp_oauth.py (_write_json) - agent/google_oauth.py (save_credentials) Also add a startup warning in get_hermes_home() when HERMES_HOME resolves to a protected directory. Without this guard, a malformed HERMES_HOME=/ causes chmod("/", 0o700) which bricks every non-root user on the host (systemd-resolved, journald, Docker containers, etc.).
|
Drop-by The blocklist in your
Also worth a Either way, the fix shape is sound; happy to see it land with regression coverage on the canonical PR. |
|
Merged via PR #29670 — we went with @liuhao1024's #25831 as the base since it was submitted first (16:29 vs 16:54) and shipped with 5 unit tests. Your version's explicit |
Summary
Prevents
os.chmod(path.parent, 0o700)from running on/or well-known system directories, which bricks every non-root user on the host.Fixes #25821
Changes
safe_chmod_parent()tohermes_constants.py— refuses to chmod root or system dirs (/etc,/var,/usr,/home,/root,/opt,/tmp,/proc,/sys,/dev,/run,/boot)os.chmod(path.parent, 0o700)call sites:hermes_cli/auth.py(3 sites:_save_auth_store,_save_qwen_cli_tokens,_save_nous_shared_token)tools/mcp_oauth.py(_write_json)agent/google_oauth.py(save_credentials)get_hermes_home()whenHERMES_HOMEresolves to a protected directoryWhy
Without this guard, a malformed
HERMES_HOME=/causeschmod("/", 0o700)which breaks systemd-resolved, journald, Docker containers, and every non-root service. See issue for production incident report.