Summary
Glances contains an OS command injection vulnerability in its administrator-configured action templates. When nested process data containing pipe characters is rendered without complete sanitization, an attacker may influence command execution if they can control or cause malicious process metadata to be processed.
Affected context
The issue occurs in Glances versions that use _sanitize_mustache_dict() before rendering action templates with Chevron and executing them through secure_popen(). It is most relevant when monitoring data includes nested lists or dictionaries, such as process command-line values, and administrators have configured actions that incorporate rendered values into shell commands.
Exploit preconditions
- Attack surface: Glances action-template processing and command execution
- Required access: Ability to influence monitored process metadata or another value incorporated into an action template
- Trigger point: Rendering and execution of an administrator-configured action
- Why exploitation is possible: Sanitization does not consistently inspect strings nested inside lists and dictionaries, allowing shell metacharacters to reach the command execution path
Why this happens
The vulnerability results from incomplete recursive input sanitization before template rendering and process execution. Nested collection values are not handled with the same protections as top-level strings, so attacker-influenced data can retain shell control characters that are later interpreted by a command execution function. This behavior maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command.
Potential impact
- An attacker could execute commands with the privileges of the Glances process
- The monitoring host or container could be compromised
- Sensitive system or application data may be accessed
- Malicious commands could alter monitored systems or disrupt services
- Compromised hosts could potentially be used for lateral movement
General mitigation guidance
Mitigation generally focuses on preventing monitored data from becoming executable command syntax.
Defensive patterns include:
- Avoiding shell interpretation when invoking actions, using structured argument arrays instead
- Applying recursive validation and context-appropriate escaping to all rendered values
- Treating process metadata and other monitoring data as untrusted input
- Restricting action templates to approved commands and fixed argument patterns
- Running monitoring services with the least privileges necessary
- Separating display-oriented templating from command execution workflows
How teams detect issues like this
Detection can include:
- Static analysis for shell execution APIs receiving template-rendered or monitoring-derived values
- Code review checks for sanitization functions that process only top-level dictionary entries
- Tests using nested lists and dictionaries containing shell metacharacters
- Runtime monitoring for unexpected child processes spawned by Glances
- Policy enforcement requiring structured process invocation and approved action commands
- Automated security review tools that flag command construction from externally influenced data

