Repository navigation
power-guard: run the sleep command as argv, never through a shell - #11461
Merged
Merged
Conversation
) POWER_GUARD_SLEEP_CMD was passed to subprocess.run(..., shell=True) in a daemon that runs as root, so any shell metacharacters in the environment value were executed. Parse it once at startup with shlex.split, fail closed (named error, exit 2, no polling) on an empty or unparseable value, and run the resulting argv with no shell. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dezren39
marked this pull request as ready for review
November 18, 2026 00:53
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
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.
Closes #9602
Before: power-guard ran
POWER_GUARD_SLEEP_CMDwithsubprocess.run(SLEEP_CMD, shell=True)as root, so;,&&,$(...)and friends in that environment value were executed by a root shell. An empty value also ran an empty shell line instead of being refused.After: the value is split into argv once at startup with
shlex.splitand run with no shell. Metacharacters reach the command as literal arguments. An empty, blank or unparseable value (for example an unbalanced quote) stops the daemon before it polls, with onepower-guard: error: POWER_GUARD_SLEEP_CMD=...line and exit 2, the same fail-closed path the timing overrides already use. The defaultsystemctl hybrid-sleepbehaves as before.How: new
parse_sleep_cmd/sleep_argv_from_envbesidetiming_from_env;SLEEP_CMDbecomesSLEEP_ARGV; the docstring notes the argv rule.Testing:
python3 nixos/services/power-guard/test_power_guard.pypasses (21 tests). New tests cover the default, shell-style quoting, metacharacters kept literal, refusal of empty and unbalanced input, a daemon run that exits named on a bad value, and a daemon run where; touch X && $(touch X)reaches the command as arguments andXis never created.ruff formatapplied.Generated by Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.