Summary
Glances performs unsafe pickle deserialization on a version-check cache file stored at a predictable, world-accessible path, without integrity or format validation.
An attacker with write access to this cache location can plant a malicious pickle and gain arbitrary code execution as the OS user running Glances when version checking is triggered.
Affected context
This vulnerability appears in environments where Glances runs with version checking enabled (the default) and relies on a cache file located under the user's XDG cache directory or ~/.cache/glances/.
It is most relevant on multi-user systems, shared workstations, and containerized setups where other processes or users may influence files in the Glances cache directory.
The issue manifests when Glances trusts the contents of the cache file and deserializes it with pickle.load() without verifying authenticity or enforcing a restricted data format.
Exploit preconditions
- Attack surface: Local, via the filesystem path to the Glances cache (
~/.cache/glances/glances-version.dbor$XDG_CACHE_HOME/glances/glances-version.db). - Required access: Ability to write or replace the Glances version cache file as the same user or via broader filesystem permissions (e.g., shared home directory, misconfigured mounts, or compromised container).
- Trigger point: Glances startup (or subsequent runs) with version checking enabled, when it calls
pickle.load()on the cache file. - Why exploitation is possible: Python pickle deserialization executes attacker-controlled opcodes embedded in the pickle stream, and Glances does not perform signature checks, integrity validation, or enforce a safe serialization format before calling
pickle.load().
Why this happens
The root cause is reliance on Python's pickle module for persisting and restoring application state without treating the serialized data as untrusted input.
Pickle is a general-purpose object serialization mechanism that can invoke arbitrary constructors and code paths during deserialization; when used on data from a world-accessible or otherwise writeable location, it becomes an unsafe deserialization primitive.
In Glances, the version-check cache file is stored at a predictable filesystem path and read back with pickle.load() without any authenticity or integrity guarantees, mapping directly to CWE-502: Deserialization of Untrusted Data.
Potential impact
- An attacker could execute arbitrary Python or OS-level commands in the context of the user running Glances.
- Malicious code can be used to install local malware or backdoors on the affected system.
- Attackers may access or modify user data available to the Glances process.
- Local privilege escalation may be possible if combined with other vulnerabilities or misconfigurations.
- Compromise of monitoring workflows and integrity of system metrics collection.
General mitigation guidance
Effective mitigation centers on eliminating unsafe deserialization patterns and tightening trust boundaries around cached state.
Recommended design patterns include:
- Avoiding
picklefor persistent storage of data that may be influenced by untrusted actors, favoring simple, structured formats such as JSON or plain text. - Adding integrity checks or cryptographic signatures when cached data must be trusted, ensuring only data produced by the application is accepted.
- Storing sensitive cache files in directories with restricted permissions and avoiding world-accessible or shared locations for executable state.
- Implementing defensive defaults: disable non-essential features that rely on executable serialization formats unless explicitly needed and validated.
- Applying least-privilege principles so that Glances runs with minimal filesystem access, limiting the damage if deserialization issues occur.
How teams detect issues like this
Detection often involves a combination of static inspection, configuration review, and behavioral monitoring:
- Use static analysis or linters to flag calls to
pickle.load()and similar deserialization APIs where input originates from disk, network, or other untrusted sources. - During code review, treat serialization and cache-handling logic as sensitive, looking for predictable paths, world-accessible directories, and lack of integrity checks.
- Incorporate security-focused test cases that attempt to deserialize crafted, non-conforming data and validate that the application rejects or safely handles it.
- Apply organizational policies that discourage or restrict the use of executable serialization formats (like pickle) in production codebases, backed by automated scanning tools in CI pipelines.

