T09 · Insecure Skill Coding Practices
- Location
api_monitor.py:82- Finding
Overbroad Process Matching Can Terminate Unrelated Processes
- Content
View full analysis
Vulnerability Details
File Location:
api_monitor.py, lines 82–89
Vulnerability Type: Overbroad process termination
Risk Level: MediumComplete Code Snippet
python # Restart Gateway (requires corresponding permissions) subprocess.run(["pkill", "-f", "openclaw-gateway"], capture_output=True) time.sleep(2) subprocess.Popen( ["nohup", "openclaw", "gateway", "start"], stdout=open(OPENCLAW_LOG, "a"), stderr=subprocess.STDOUT )Technical Analysis
The model-switching function uses
pkill -f openclaw-gatewayto stop the existing Gateway. The-foption compares the supplied pattern against each process's entire command line rather than identifying one verified Gateway process.Consequently, the command may terminate any process accessible to the invoking user if its command line contains
openclaw-gateway, including unrelated applications or multiple Gateway instances. The implementation does not verify the matched process's executable, owner, PID, start time, or relationship to the OpenClaw installation.The return code from
pkillis also ignored. The code attempts to start another Gateway after a fixed two-second delay regardless of whether termination succeeded. This may leave duplicate instances or an inconsistent service state. The use of an argument-list subprocess call prevents shell command injection here, but it does not mitigate the unsafe breadth of the process match.Attack Path
- An attacker or another local workload starts a process whose command line contains the text
openclaw-gateway. - A user or agent invokes the Skill with
--confirmor--model, causingset_model()to run. - The Skill executes
pkill -f openclaw-gateway. - The operating system terminates every accessible process whose full command line matches the pattern, including the unrelated process.
- The Skill waits two seconds and attempts to start a new Gateway without checking whether the intended process was stopped su ...[truncated 928 chars]
- An attacker or another local workload starts a process whose command line contains the text
- Remediation
View remediation
Remediation Suggestions
- Replace
pkill -fwith OpenClaw's supported restart command or a service-manager operation scoped to the exact Gateway service. - If no supported service interface exists, record the Gateway PID in a protected PID file and validate all of the following before signaling it:
- The PID is numeric and currently active.
- The process is owned by the expected account.
- The executable resolves to the expected OpenClaw binary.
- The process start time matches the managed instance, preventing PID-reuse errors.
- Send a graceful termination signal to only the verified PID, wait with a bounded timeout, and escalate only when explicitly necessary.
- Check and handle the termination command's return status.
- Confirm that the prior Gateway has exited before starting a replacement.
- Check startup success and report failures rather than returning success immediately after
Popen. - Avoid running the Skill with elevated privileges; use a dedicated, least-privileged account with access only to the required OpenClaw configuration and service.
- Where concurrent invocations are possible, use a lock file to prevent overlapping restarts and duplicate Gateway instances.
- Replace
