{"id":"CVE-2026-32611","aliases":["CVE-2026-32611","GHSA-49g7-2ww7-3vf5","PYSEC-2026-2170"],"related":[],"kind":"vulnerability","state":"published","title":"Glances has a SQL Injection in DuckDB Export via Unparameterized DDL Statements","summary":"Glances is an open-source system cross-platform monitoring tool. The GHSA-x46r fix (commit 39161f0) addressed SQL injection in the TimescaleDB export module by converting all SQL operations to use parameterized queries and `psycopg.sql` composable objects. However, the DuckDB export module (`glances/exports/glances_duckdb/__init__.py`) was not included in this fix and contains the same class of vulnerability: table names and column names derived from monitoring statistics are directly interpolated into SQL statements via f-strings. While DuckDB INSERT values already use parameterized queries (`?` placeholders), the DDL construction and table name references do not escape or parameterize identifier names. Version 4.5.3 provides a more complete fix.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Glances is an open-source system cross-platform monitoring tool. The GHSA-x46r fix (commit 39161f0) addressed SQL injection in the TimescaleDB export module by converting all SQL operations to use parameterized queries and `psycopg.sql` composable objects. However, the DuckDB export module (`glances/exports/glances_duckdb/__init__.py`) was not included in this fix and contains the same class of vulnerability: table names and column names derived from monitoring statistics are directly interpolated into SQL statements via f-strings. While DuckDB INSERT values already use parameterized queries (`?` placeholders), the DDL construction and table name references do not escape or parameterize identifier names. Version 4.5.3 provides a more complete fix.","source":"cvelist"},{"lang":"en","text":"## Summary\n\nThe GHSA-x46r fix (commit 39161f0) addressed SQL injection in the TimescaleDB export module by converting all SQL operations to use parameterized queries and `psycopg.sql` composable objects. However, the DuckDB export module (`glances/exports/glances_duckdb/__init__.py`) was not included in this fix and contains the same class of vulnerability: table names and column names derived from monitoring statistics are directly interpolated into SQL statements via f-strings. While DuckDB INSERT values already use parameterized queries (`?` placeholders), the DDL construction and table name references do not escape or parameterize identifier names.\n\n## Details\n\nThe DuckDB export module constructs SQL DDL statements by directly interpolating stat field names and plugin names into f-strings.\n\n**Vulnerable CREATE TABLE construction** (`glances/exports/glances_duckdb/__init__.py:156-162`):\n\n```python\ncreate_query = f\"\"\"\nCREATE TABLE {plugin} (\n{', '.join(creation_list)}\n);\"\"\"\nself.client.execute(create_query)\n```\n\nThe `creation_list` is built from stat dictionary keys in the `update()` method (`glances/exports/glances_duckdb/__init__.py:117-118`):\n\n```python\nfor key, value in plugin_stats.items():\n    creation_list.append(f\"{key} {convert_types[type(self.normalize(value)).__name__]}\")\n```\n\nThe INSERT statement also uses the unescaped `plugin` name (`glances/exports/glances_duckdb/__init__.py:172-174`):\n\n```python\ninsert_query = f\"\"\"\nINSERT INTO {plugin} VALUES (\n{', '.join(['?' for _ in values])}\n);\"\"\"\n```\n\nWhile INSERT values use `?` placeholders (safe), the table name `{plugin}` is directly interpolated in both CREATE TABLE and INSERT INTO statements. Column names in creation_list are also directly interpolated without quoting.\n\n**Comparison with the TimescaleDB fix (commit 39161f0):**\n\nThe TimescaleDB fix addressed this exact pattern by:\n1. Using `psycopg.sql.Identifier()` for table and column names\n2. Using `psycopg.sql.SQL()` for composing queries\n3. Using `%s` placeholders for all values\n\nThe DuckDB module was not part of this fix despite having the same vulnerability class.\n\n**Attack vector:**\n\nThe primary attack vector is through stat dictionary keys. While most keys come from hardcoded psutil field names (e.g., `cpu_percent`, `memory_usage`), any future plugin that introduces dynamic keys from external data (container labels, custom metrics, user-defined sensor names) would create an exploitable injection path. Additionally, the table name (`plugin`) comes from the internal plugins list, but any custom plugin with a crafted name could inject SQL.\n\n## PoC\n\nThe injection is demonstrable when column or table names contain SQL metacharacters:\n\n```python\n# Simulated injection via a hypothetical plugin with dynamic keys\n# If a stat dict contained a key like:\n#   \"cpu_percent BIGINT); DROP TABLE cpu; --\"\n# The creation_list would produce:\n#   \"cpu_percent BIGINT); DROP TABLE cpu; -- VARCHAR\"\n# Which in the CREATE TABLE f-string becomes:\n#   CREATE TABLE plugin_name (\n#     time TIMETZ,\n#     hostname_id VARCHAR,\n#     cpu_percent BIGINT); DROP TABLE cpu; -- VARCHAR\n#   );\n```\n\n```bash\n# Verify with DuckDB export enabled:\n# 1. Configure DuckDB export in glances.conf:\n# [duckdb]\n# database=/tmp/glances.duckdb\n\n# 2. Start Glances with DuckDB export and debug logging\nglances --export duckdb --debug 2>&1 | grep \"Create table\"\n\n# 3. Observe the unescaped SQL in debug output\n```\n\n## Impact\n\n- **Defense-in-depth gap:** The identical vulnerability pattern was identified and fixed in TimescaleDB (GHSA-x46r) but the fix was not applied to the sibling DuckDB module. This represents an incomplete patch that leaves the same attack surface open through a different code path.\n\n- **Future exploitability:** If any Glances plugin is added or modified to produce stat dictionary keys from external/user-controlled data (e.g., container metadata, custom metric names, SNMP OID labels), the DuckDB export would become immediately exploitable for SQL injection without any additional code changes.\n\n- **Data integrity:** A successful injection in the CREATE TABLE statement could corrupt the DuckDB database, create unauthorized tables, or modify schema in ways that affect other applications reading from the same database file.\n\n## Recommended Fix\n\nApply the same parameterization approach used in the TimescaleDB fix. DuckDB supports identifier quoting with double quotes:\n\n```python\n# glances/exports/glances_duckdb/__init__.py\n\ndef _quote_identifier(name):\n    \"\"\"Quote a SQL identifier to prevent injection.\"\"\"\n    # DuckDB uses double-quote escaping for identifiers\n    return '\"' + name.replace('\"', '\"\"') + '\"'\n\ndef export(self, plugin, creation_list, values_list):\n    \"\"\"Export the stats to the DuckDB server.\"\"\"\n    logger.debug(f\"Export {plugin} stats to DuckDB\")\n\n    table_list = [t[0] for t in self.client.sql(\"SHOW TABLES\").fetchall()]\n    if plugin not in table_list:\n        # Quote table and column names to prevent injection\n        quoted_plugin = _quote_identifier(plugin)\n        quoted_fields = []\n        for item in creation_list:\n            parts = item.split(' ', 1)\n            col_name = _quote_identifier(parts[0])\n            col_type = parts[1] if len(parts) > 1 else 'VARCHAR'\n            quoted_fields.append(f\"{col_name} {col_type}\")\n\n        create_query = f\"CREATE TABLE {quoted_plugin} ({', '.join(quoted_fields)});\"\n        try:\n            self.client.execute(create_query)\n        except Exception as e:\n            logger.error(f\"Cannot create table {plugin}: {e}\")\n            return\n\n    self.client.commit()\n\n    # Insert with quoted table name\n    quoted_plugin = _quote_identifier(plugin)\n    for values in values_list:\n        insert_query = f\"INSERT INTO {quoted_plugin} VALUES ({', '.join(['?' for _ in values])});\"\n        try:\n            self.client.execute(insert_query, values)\n        except Exception as e:\n            logger.error(f\"Cannot insert data into table {plugin}: {e}\")\n\n    self.client.commit()\n```","format":"markdown","source":"ghsa"},{"lang":"es","text":"Glances es una herramienta de monitoreo de sistema multiplataforma de código abierto. La corrección GHSA-x46r (commit 39161f0) abordó la inyección SQL en el módulo de exportación de TimescaleDB al convertir todas las operaciones SQL para usar consultas parametrizadas y objetos componibles psycopg.sql. Sin embargo, el módulo de exportación de DuckDB (glances/exports/glances_duckdb/__init__.py) no fue incluido en esta corrección y contiene la misma clase de vulnerabilidad: los nombres de tabla y los nombres de columna derivados de las estadísticas de monitoreo se interpolan directamente en las sentencias SQL a través de f-strings. Si bien los valores INSERT de DuckDB ya usan consultas parametrizadas (marcadores de posición ?), la construcción DDL y las referencias a nombres de tabla no escapan ni parametrizan los nombres de identificador. La versión 4.5.3 proporciona una corrección más completa.","source":"nvd"}],"published":"2026-03-16T16:34:03.000Z","modified":"2026-07-13T07:26:20.779Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:L/A:L","score":7,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:L/A:L","score":7,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:L/A:L","score":7,"rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N","score":9.1,"rating":"CRITICAL"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N","score":9.1,"rating":"CRITICAL"}],"cwes":["CWE-89"],"affected":[{"ranges":[{"version":"< 4.5.2","status":"affected"}],"vendor":"nicolargo","product":"glances","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"4.5.2"}],"ecosystem":"PyPI","package":"glances","purl":"pkg:pypi/glances","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"4.5.2"}],"vendor":"nicolargo","product":"glances","cpe":"cpe:2.3:a:nicolargo:glances:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"4.5.2"}],"ecosystem":"PyPI","package":"glances","purl":"pkg:pypi/glances","source":"pysec"}],"references":[{"url":"https://github.com/nicolargo/glances/security/advisories/GHSA-49g7-2ww7-3vf5","tags":["evidence","exploit","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/nicolargo/glances/commit/63b7da28895249d775202d639e5531ba63491a5c","tags":["fix","patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/nicolargo/glances/releases/tag/v4.5.2","tags":["advisory","release-notes","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-32611","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/nicolargo/glances","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-03-18T18:50:55.560Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-32611","url":"https://www.cve.org/CVERecord?id=CVE-2026-32611","licence":"CVE Terms of Use","modified":"2026-03-18T18:51:23.479Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-49g7-2ww7-3vf5","url":"https://github.com/advisories/GHSA-49g7-2ww7-3vf5","licence":"CC-BY-4.0","modified":"2026-07-13T07:26:20.779Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-32611","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-32611","licence":"Public domain","modified":"2026-06-17T10:36:05.850Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-2170","url":"https://osv.dev/vulnerability/PYSEC-2026-2170","licence":"CC-BY-4.0","modified":"2026-07-13T07:15:31.590Z"}],"updatedAt":"2026-11-25T22:59:16.129Z","epss":{"score":0.00334,"percentile":0.28687,"date":"2026-12-01T12:00:22.000Z"}}