/

CVE-2025-69662

Severity:

HIGH RISK

(8.6)

SQL Injection in GeoPandas to_postgis() Database Writer

CVE-2025-69662

Modified

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Information Disclosure and Potential Data Manipulation via SQL Injection

Severity:

HIGH RISK

(8.6)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

GeoPandas versions before 1.1.2 contain an SQL injection vulnerability in the to_postgis() helper used to write GeoDataFrames into PostgreSQL.

When untrusted values are interpolated into SQL statements generated by this function, an attacker may craft input that alters queries and exposes sensitive database information.

Affected context

The vulnerability arises when applications use GeoPandas (pre-1.1.2) to_postgis() to persist GeoDataFrames into a PostgreSQL/PostGIS database and include untrusted values (such as table names, schema names, or other query-affecting parameters) in the invocation.

In typical data pipelines, this occurs in ETL jobs, geospatial APIs, or batch processing scripts that dynamically construct or pass SQL-related parameters based on user or external input.

The issue becomes relevant when the database user used by the application has permissions to read or modify data beyond the intended scope of the GeoDataFrame operation.

Exploit preconditions

  • Attack surface: Application components that expose GeoPandas-powered write operations to PostgreSQL/PostGIS (e.g., web APIs, notebooks, ETL jobs, internal tools).
  • Required access: Ability to influence inputs consumed by to_postgis() (such as table name, schema, or other query-building parameters) or upstream data that ends up interpolated into SQL.
  • Trigger point: Invocation of GeoDataFrame.to_postgis() where untrusted input is concatenated or formatted into SQL rather than passed through safe parameter binding.
  • Why exploitation is possible: The vulnerable code path constructs SQL using string interpolation or otherwise blends raw input into the query without adequate sanitization, validation, or parameterization, enabling crafted input to break out of intended query structure.

Why this happens

This vulnerability maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').

The underlying bug is an unsafe SQL construction pattern in which inputs that can be influenced by an attacker are incorporated directly into SQL statements produced by to_postgis() instead of being treated as data through prepared statements or strict whitelisting.

Because SQL meta-characters (quotes, separators, comment markers) are not reliably neutralized, an attacker can alter the semantics of the query, expanding read scope or chaining multiple SQL operations under the privileges of the application's database account.

Potential impact

  • Access to sensitive data from other tables or schemas the database user can read.
  • Enumeration of database structure (tables, columns, schemas) and metadata.
  • Modification or deletion of records accessible to the database role used by the application.
  • Abuse of database functions to exfiltrate data through side channels (e.g., timing, error messages).
  • Potential chaining with other misconfigurations (e.g., overly privileged DB user) to escalate impact to broader data compromise.

General mitigation guidance

Effective mitigation focuses on eliminating unsafe SQL composition and tightening data trust boundaries around to_postgis() usage:

  • Prefer parameterized queries and query-building APIs that clearly separate code from data when customizing behavior around to_postgis() calls.
  • Constrain dynamic elements (e.g., table or schema names) to a predefined, validated whitelist rather than accepting arbitrary free-form input.
  • Apply strict input validation on any values that can influence query structure, rejecting unexpected characters and patterns rather than attempting ad-hoc escaping.
  • Run database operations under minimally privileged accounts that can access only the necessary schemas and tables, limiting potential blast radius.
  • Centralize SQL construction logic in well-reviewed utility functions so that geospatial write operations follow consistent safe patterns.

How teams detect issues like this

Organizations can surface and monitor for this class of issue using several complementary approaches:

  • Static analysis: Configure rules that flag string concatenation or formatting of SQL statements, especially around GeoPandas to_postgis() usage and any helper functions that wrap it.
  • Code review: Treat any dynamic table/schema name construction, raw SQL fragments, or user-controlled query modifiers as high-risk and require explicit validation and whitelisting.
  • Runtime monitoring: Inspect database logs for anomalous queries (e.g., unexpected UNIONs, stacked statements, or comment markers) originating from components that use GeoPandas.
  • Policy enforcement: Integrate secure coding guidelines into CI/CD pipelines, including checks that enforce parameterized queries and restrict the use of raw SQL APIs where safer abstractions exist.
  • Automated tooling: Use general-purpose SAST/DAST tools configured to recognize SQL injection patterns in Python data-access layers and geospatial data pipelines.

Sources

SourceLink
aydinnyunus.github.ioaydinnyunus.github.io/2025/12/27/sql-injection-geopandas/
github.comgithub.com/geopandas/geopandas/pull/3681
lists.debian.orglists.debian.org/debian-lts-announce/2026/04/msg00025.html

Frequently asked

questions

It can be, depending on architecture. If a remote user can influence values that flow into to_postgis() (for example via HTTP APIs or uploaded data), then the SQL injection can be triggered remotely through the application.

The attacker needs the ability to control or significantly influence inputs used by the vulnerable to_postgis() call—such as table names, schema identifiers, or other fields that affect query structure—and the application must use a database account with meaningful privileges.

The most robust fix is to ensure all SQL-related behavior around to_postgis() uses parameterized operations and strictly validated, whitelisted identifiers, combined with least-privilege database accounts so injected SQL cannot access or modify unintended data.

Establish secure coding standards that forbid dynamic SQL construction with untrusted input, enforce parameterized queries by default, and include automated checks plus targeted code review for any changes that affect database interaction, especially in shared helper utilities like GeoPandas integration points.

Find out what's already
exploitable in your codebase.