T09 · Insecure Skill Coding Practices
- Location
scripts/emergency_recovery.py:141- Finding
Overbroad Gateway Process Termination
- Content
View full analysis
Vulnerability Details
File Locations:
scripts/emergency_recovery.py:141-155config_validator.py:460-464
Vulnerability Type: Unscoped process termination
Risk Level: MediumVulnerable Code
python # scripts/emergency_recovery.py:141-155 subprocess.run( ["pkill", "-f", "openclaw.*gateway"], capture_output=True ) # Wait for the port to be released import time time.sleep(2) # Start Gateway log("Starting Gateway...") subprocess.Popen( ["openclaw", "gateway", "start"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL )python # config_validator.py:460-464 subprocess.run( ["pkill", "-f", "openclaw.*gateway"], capture_output=True, timeout=10 ) time.sleep(2) subprocess.Popen( ["openclaw", "gateway", "start"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL )Technical Analysis
Both restart implementations use
pkill -fwith the regular expressionopenclaw.*gateway. The-foption matches against the entire process command line rather than a verified executable name or trusted process identifier.The expression can therefore match processes other than the intended OpenClaw Gateway. The code does not verify:
- The path of the matched executable.
- The process owner.
- Whether the process was started by this OpenClaw installation.
- Whether the process is listening on the expected Gateway port.
- Whether a matched PID came from a trusted Gateway PID file.
- Whether more than one process matched before termination.
The subprocess calls do not use a shell, so this is not shell command injection. The vulnerability is instead an insufficiently scoped process-management operation.
Attack Path
- A local process is started with a command line containing text that matches
openclaw.*gateway. - A user or automated agent invokes Gateway recovery or restart.
- The Skill executes
pkill -f openclaw.*gateway. - The unrelated matching process receives a terminati ...[truncated 1139 chars]
- Remediation
View remediation
Remediation Suggestions
-
Prefer the application's supported lifecycle interface:
python subprocess.run( ["openclaw", "gateway", "stop"], check=True, capture_output=True, timeout=10 ) -
If direct signaling is necessary, use a trusted PID file created by the Gateway. Parse the PID as an integer and reject invalid or stale values.
-
Before signaling a PID, verify all of the following:
- The process is owned by the expected user.
- Its executable resolves to the expected OpenClaw binary.
- Its start time matches the managed instance where possible.
- Its command-line arguments represent the intended Gateway instance.
- It is associated with the expected configuration or port.
-
Signal only the verified PID rather than performing a regular-expression search across all process command lines.
-
Attempt graceful termination first, wait for a bounded period, and use forced termination only after explicit verification.
-
Check and report the return codes of both stop and start operations. Do not suppress all startup diagnostics; write errors to a protected log.
-
Add tests demonstrating that similarly named unrelated processes are not terminated.
-
