Summary
The DuckDB export module in Glances constructs SQL statements using f-strings with table and column names derived from monitoring statistics, without properly sanitizing or parameterizing these identifiers.
An attacker who can influence these names may inject arbitrary SQL into DDL and table reference statements, potentially altering the DuckDB database, tampering with monitoring data, or disrupting export operations.
Affected context
This vulnerability occurs in Glances deployments that use the DuckDB export backend (glances/exports/glances_duckdb/__init__.py) to persist system monitoring metrics.
In such setups, Glances dynamically creates tables and columns based on metric names and uses these identifiers directly in SQL statements via Python f-strings.
If metric-derived identifiers can be influenced—through configuration, plugins, or upstream data sources—these unsanitized names become a vector for SQL injection within the DuckDB database used by Glances.
Exploit preconditions
- Attack surface: The DuckDB exporter path within a running Glances process.
- Required access: Ability to control or significantly influence the values used to derive table names, column names, or other SQL identifiers (for example, metric keys or labels that Glances passes to the DuckDB exporter).
- Trigger point: Execution of DuckDB-related export logic that builds DDL (CREATE/ALTER TABLE) or table reference SQL via f-strings using attacker-controlled identifier fragments.
- Why exploitation is possible: Identifier names are directly interpolated into SQL strings without robust escaping or use of composable SQL objects, so crafted values can break out of the intended identifier context and inject additional SQL tokens or clauses.
Why this happens
The core issue is a form of SQL injection (CWE-89) stemming from dynamic SQL construction that treats externally influenced values as trusted identifiers.
In the DuckDB export module, Glances composes CREATE TABLE, ALTER TABLE, and INSERT-adjacent statements by embedding table and column names with f-strings instead of using safe abstractions like parameterized identifiers or composable SQL objects.
While value placeholders (?) are used for INSERT parameters, the surrounding DDL and identifier references remain vulnerable because most database drivers only parameterize literal values, not structural components such as table or column names.
This pattern allows attacker-controlled identifier fragments to alter the shape or meaning of the executed SQL, enabling unintended operations on the DuckDB database.
Potential impact
- Arbitrary modification of the DuckDB schema (creation, alteration, or deletion of tables).
- Tampering with or deletion of monitoring data stored in DuckDB.
- Insertion of misleading or crafted records that corrupt monitoring or reporting outputs.
- Disruption of Glances export functionality via malformed schema or conflicting SQL.
- Under some deployments, potential pivot into other components that rely on the compromised DuckDB data for downstream processing or alerting.
General mitigation guidance
Effective mitigation focuses on eliminating dynamic string-based SQL construction for identifiers and reducing trust in metric-derived names:
- Use database-specific mechanisms or composable SQL helpers to safely construct identifiers (e.g., composable objects or dedicated identifier-quoting APIs when available).
- Centralize and strictly validate any identifier-generation logic, ensuring only a constrained character set and known-safe patterns are allowed for table and column names.
- Decouple user- or configuration-facing names from raw SQL identifiers by mapping them to internal, sanitized identifiers (for example, hashing or canonical slugging).
- Keep the DuckDB database used for monitoring running with minimal privileges appropriate to the exporter's needs and isolate it from other critical data stores or processes.
- Apply defense-in-depth around configuration and plugins so untrusted parties cannot arbitrarily introduce new metric keys or labels that flow into SQL construction.
How teams detect issues like this
Detection generally involves both code-centric and runtime-oriented approaches:
- Static analysis: Configure linters or SAST tools to flag direct string interpolation into SQL statements, especially usages of f-strings or string concatenation that combine SQL keywords with non-constant variables.
- Code review: During review, scrutinize all export backends and database adapters for dynamic DDL or identifier construction; look for patterns like
f"CREATE TABLE {name}"or similar constructs. - Policy enforcement: Introduce secure coding guidelines requiring the use of composable SQL builders or explicit identifier-escaping utilities and ban ad-hoc f-string SQL in shared libraries.
- Runtime monitoring: Where feasible, log executed SQL statements from the DuckDB interface and inspect for anomalous patterns, such as unexpected multiple statements, unusual keywords, or identifiers not generated by the normal metric pipeline.

