Harden root FHS PATH guard against HOME privilege crossing#673
Conversation
There was a problem hiding this comment.
Code Review
This pull request improves security and robustness when probing and modifying shell configuration files for the root user. It resolves the root user's home directory directly from the system database instead of relying on the HOME environment variable. Additionally, it restricts the bash probe to a non-interactive shell with an explicit PATH, and introduces strict ownership and permission checks on .bashrc and .bash_profile to prevent modifying files that are symlinks, not owned by root, or group/world-writable. There are no review comments, so no feedback is provided.
🔎 Lint report:
|
| Rule | Count |
|---|---|
invalid-argument-type |
3 |
First entries
run_agent.py:7311: [invalid-argument-type] invalid-argument-type: Argument to function `build_anthropic_client` is incorrect: Expected `str`, found `str | dict[Unknown, Unknown] | Any | ... omitted 3 union elements`
run_agent.py:13565: [invalid-argument-type] invalid-argument-type: Argument to function `_is_oauth_token` is incorrect: Expected `str`, found `str | dict[Unknown, Unknown] | Any | ... omitted 3 union elements`
run_agent.py:13568: [invalid-argument-type] invalid-argument-type: Argument to function `len` is incorrect: Expected `Sized`, found `(str & ~AlwaysFalsy) | (dict[Unknown, Unknown] & ~AlwaysFalsy) | (Any & ~AlwaysFalsy) | ... omitted 3 union elements`
✅ Fixed issues (4):
| Rule | Count |
|---|---|
invalid-argument-type |
3 |
unresolved-reference |
1 |
First entries
run_agent.py:13565: [invalid-argument-type] invalid-argument-type: Argument to function `_is_oauth_token` is incorrect: Expected `str`, found `str | dict[Unknown | str, Unknown | str | dict[str, str]] | Any | ... omitted 3 union elements`
run_agent.py:13568: [invalid-argument-type] invalid-argument-type: Argument to function `len` is incorrect: Expected `Sized`, found `(str & ~AlwaysFalsy) | (dict[Unknown | str, Unknown | str | dict[str, str]] & ~AlwaysFalsy) | (Any & ~AlwaysFalsy) | ... omitted 3 union elements`
gateway/run.py:5544: [unresolved-reference] unresolved-reference: Name `team_id` used when not defined
run_agent.py:7311: [invalid-argument-type] invalid-argument-type: Argument to function `build_anthropic_client` is incorrect: Expected `str`, found `str | dict[Unknown | str, Unknown | str | dict[str, str]] | Any | ... omitted 3 union elements`
Unchanged: 4355 pre-existing issues carried over.
Diagnostics are surfaced as warnings — this check never fails the build.
Auto-merge: checks failingThe following checks did not pass:
Please fix the failing checks before this PR can be merged. |
|
@copilot, fix all failing checks. |
Fixed and pushed in I addressed the failing checks by fixing the |
Motivation
HOMEor startup file could be executed or modified as root.Description
scripts/install.sh: resolve root home viagetent passwd root(fallback/root), probe with a non-interactivebash -cunder a minimalenv(explicitPATH) so user~/.bashrcis not sourced, operate onROOT_HOMEinstead of environmentHOME, and restrict edits to startup files that are regular files (no symlink), root-owned, and not group/world-writable before appending PATH guard lines.hermes_cli/main.py: resolve root home viapwd.getpwuid(0)(fallback/root), run the probe usingbash -cwith an explicitPATHto avoid sourcing~/.bashrc, and refuse to modify candidate startup files if they are symlinks or fail ownership/permission checks (must be owned by root and not group/world-writable) before appending the PATH guard.HOMEand launching an interactivebash -ithat can execute attacker-controlled startup files, and appending to arbitrary files without ownership/mode/symlink checks.Testing
python -m py_compile hermes_cli/main.pyand the file compiled successfully.bash -n scripts/install.sh(shell syntax check) and the script passed-nvalidation.Codex Task