Repository navigation
🔒 fix(services): sanitize unit names to prevent command injection - #165
Conversation
Validate systemd unit names against an allowlist pattern (`^[a-zA-Z0-9_.:@-]+$`) and ensure they do not start with a leading hyphen before executing systemctl commands. Invalid unit names produce a StatusError finding during Audit and are skipped during Plan. Co-authored-by: jackby03 <70082129+jackby03@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
I'll help you find a solution for this failing job. Let me first get the job logs to understand what's going wrong.Now let me get the failing file to see the issue:## Solution The golangci-lint linter detected an empty branch (SA9003 staticcheck error) at line 305 in The Issue: if runnerCalled {
// Note: runnerCalled would be true for the second item (valid.service), but for the first item it shouldn't be called.
}This is flagged as code smell because the conditional does nothing. The Fix: Remove the empty // Note: runnerCalled would be true for the second item (valid.service), but for the first item it shouldn't be called.
changes, err := m.Plan(context.Background(), cfg)Alternative (if the check is intentional): If you want to keep an assertion to verify the runner wasn't called for invalid unit names, add actual logic: if runnerCalled {
t.Error("runner should not be called for invalid unit names")
}Either approach will resolve the staticcheck SA9003 error and allow the CI to pass. |
Thank you. The empty if branch in module_test.go has been fixed with an assertion check, and the validation order in Plan() has also been corrected. |
Validate systemd unit names against an allowlist pattern (`^[a-zA-Z0-9_.:@-]+$`) and ensure they do not start with a leading hyphen before executing systemctl commands. Invalid unit names produce a StatusError finding during Audit and are skipped during Plan. Also fix staticcheck SA9003 warning in test assertion. Co-authored-by: jackby03 <70082129+jackby03@users.noreply.github.com>
🎯 What:
Validates user-configured service/unit names in
internal/modules/services/module.goagainst a strict systemd unit name pattern (^[a-zA-Z0-9_.:@-]+$) and disallows leading hyphens.Without unit name validation, unsanitized strings supplied via user configuration could lead to command or flag injection when passed directly to
systemctl disable --now <unit>.🛡️ Solution:
isValidUnitNamehelper to validate unit names.Auditto return aFindingwithStatusErrorif an invalid unit name is encountered.Planto skip creatingChangeobjects for invalid unit names.internal/modules/services/module_test.go.PR created automatically by Jules for task 17949466509601655490 started by @jackby03