Summary
A critical SQL injection vulnerability in GeoTools affects the PostGIS DataStore implementation when processing OGC Filters that use the jsonArrayContains function. If an attacker can influence the function's value input and the datastore uses a qualifying PostGIS String or JSON field, crafted data may alter generated SQL and access or modify database information.
Affected context
The issue occurs in GeoTools deployments using the PostGIS DataStore implementation with PostGIS 12 or later and a String or JSON field. It is associated with OGC Filter processing through the jsonArrayContains function, where a supplied value can be incorporated into generated SQL without adequate escaping.
Exploit preconditions
- Attack surface: Applications or services that expose OGC Filter processing through GeoTools
- Required access: Ability to submit or influence filter input, directly or through an integrating application
- Trigger point: Evaluation of
jsonArrayContainsagainst a qualifying PostGIS field - Environmental requirement: PostGIS 12 or later with a String or JSON field
- Why exploitation is possible: The function places the value into generated SQL without sufficient escaping or parameterization
Why this happens
The underlying flaw is the construction of SQL from externally influenced function values without reliably treating those values as data. This behavior maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'). The insecure pattern is direct interpolation or concatenation of input into database statements instead of using parameterized queries, safe query-building abstractions, or equivalent context-aware encoding.
Potential impact
- An attacker may read unauthorized database records
- An attacker could alter or delete geospatial or application data
- Database-level permissions may allow access to additional tables or schemas
- Compromised data could affect downstream mapping, analytics, or business workflows
- Application availability could be disrupted through destructive or resource-intensive queries
General mitigation guidance
Mitigation generally focuses on ensuring that all dynamic values are passed through parameterized database interfaces or trusted query-construction abstractions.
Common defensive patterns include:
- Avoiding SQL string concatenation for filter-controlled values
- Applying strict type, length, and schema validation before query generation
- Reducing trust in client-supplied OGC Filter expressions
- Configuring PostGIS connection pools with the minimum required database privileges
- Separating read-only workloads from operations that can modify data
- Restricting database roles, schemas, and network access to the smallest necessary scope
How teams detect issues like this
Organizations can look for this class of issue through:
- Static analysis rules identifying string concatenation or interpolation in SQL-building code
- Code review checks for datastore functions that place filter values directly into generated statements
- Tests using benign boundary characters and structured input to verify parameterization behavior
- Database monitoring for unusual queries, unexpected schema access, or abnormal query volumes
- API policy enforcement that limits accepted OGC Filter functions, field types, and input sizes
- Neutral automated security review tools that flag injection-prone query construction patterns

