fix(system): spawn update commands without a shell (P2) - #1120
fix(system): spawn update commands without a shell (P2)#1120wjc2821296948 wants to merge 1 commit into
Conversation
`runShellCommand` invoked `spawn('sh', ['-c', commandString], ...)`, passing
the entire command as a single shell string. The current templates are all
literals, but the call shape is a footgun: any future change that splices
`appRoot`, `homeDirectory`, an environment variable, or any operator-controlled
string into the template becomes a classic shell command injection, with the
server process's privileges. A poisoned `$PATH` would already be enough to
substitute a malicious `npm`/`git` binary into the call.
Split the executor into (command, args) argv arrays and disable the shell.
The git workflow still legitimately chains three commands, so it falls back
to `sh -c` with a fully literal argument string (no string concatenation
with external values) — every other path now spawns the executable
directly with `shell: false`.
Update the service to plan each branch as `{ command, args }` and update the
existing service tests to match the new argv signature.
Co-authored-by: cgsdn <chaogeshuodiannao@users.noreply.github.com>
Severity summaryP2 — System update spawns commands through This PR is split out from the previous umbrella PR (#1106) per @blackmammoth's request that each finding be reviewed in isolation. 🤖 Generated with Claude Code |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe system update workflow now passes executables and argument arrays separately. ChangesSystem update command execution
Sequence Diagram(s)sequenceDiagram
participant SystemUpdateService
participant runShellCommand
participant Process
SystemUpdateService->>runShellCommand: command and args
runShellCommand->>Process: spawn with shell false
Process-->>runShellCommand: output and exit code
runShellCommand-->>SystemUpdateService: command result
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
P2 — System update spawns commands through
sh -cVulnerability description
runShellCommandinserver/modules/system/system.module.tsinvokedspawn('sh', ['-c', commandString], ...), parsing the entire update command as a single string passed to/bin/sh. ThecommandStringwas assembled insystem.service.ts updateSystem()from a fixed template that includedpatharguments, but any future caller that interpolated an external value into the template would have a shell-injection sink: a single; rm -rf /or backtick expansion is enough to execute arbitrary shell under the server's user.Fix
Replace the shell-string path with an explicit argv array. Each system action is now a
{ command, args }pair;runShellCommandinvokesspawn(command, args, { shell: false })so no shell parses the args and no metacharacter (;,&&,|, backtick,$(), glob,$IFS) is interpreted.updateSystem()builds the argv pairs directly from the system state. The test suite that previously asserted thesh -cbehaviour is updated to assert the new argv-based behaviour.Files
server/modules/system/system.module.tsserver/modules/system/system.service.tsserver/modules/system/tests/system.service.test.tsCommits
bbb350b—fix(system): spawn update commands without a shellCode snippet
🤖 Generated with Claude Code
Summary by CodeRabbit