Summary
A SQL injection vulnerability in MapServer's PostGIS filter translation can treat attacker-controlled filter values as numeric without confirming that they are valid numeric literals. An unauthenticated remote attacker with access to an affected CGI or OGC API Features query endpoint may bypass predicates, retrieve unintended records, or influence database query behavior.
Affected context
The issue occurs in MapServer deployments that use the PostGIS connection type and configure item metadata indicating an Integer field. It becomes risky when attacker-controlled CGI query strings or OGC API Features feature identifiers reach the runtime filter translation path and are incorporated into generated PostgreSQL/PostGIS predicates without numeric validation.
Exploit preconditions
- Attack surface: An exposed MapServer CGI or OGC API Features query endpoint backed by PostGIS
- Required access: Unauthenticated network access to a vulnerable query interface
- Trigger point: Processing a filter or featureId value associated with a field configured as an integer
- Why exploitation is possible: The value is treated as numeric and concatenated into a database predicate without verifying that it is a numeric literal
Why this happens
The underlying bug is insufficient validation of attacker-controlled input before SQL expression generation. When metadata identifies a filter item as an integer, the translation logic assumes the input is safe for unquoted insertion into a PostgreSQL/PostGIS predicate instead of validating its syntax and preserving parameter boundaries. This behavior maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Potential impact
- An attacker may bypass intended query predicates
- Unauthorized records could be enumerated or disclosed
- Boolean-based or time-based SQL injection may be possible
- Database resources could be consumed through expensive queries
- Downstream GIS services may experience degraded availability
- Database modification is not inherently established by this issue
General mitigation guidance
Mitigation generally focuses on ensuring that external filter values cannot become SQL syntax.
Common defensive patterns include:
- Using parameterized queries or structured query-builder APIs instead of string concatenation
- Validating integer fields with strict, canonical numeric parsing before query generation
- Rejecting values that contain unexpected syntax, delimiters, or trailing content
- Applying allowlisted field and operator mappings for externally supplied filters
- Limiting database credentials to the minimum read and schema permissions required
- Restricting public access to query endpoints and applying suitable request and resource policies
- Preserving consistent validation across CGI and OGC API Features request paths
How teams detect issues like this
Organizations can look for this class of issue through:
- Static analysis rules identifying concatenation of request parameters into SQL or PostGIS predicates
- Code review checks for numeric type assumptions that do not perform strict parsing
- Tests using malformed, boundary, boolean-like, and time-delay-oriented values against query interfaces
- Monitoring for unusual predicate patterns, repeated query failures, excessive query duration, or unexpected record volumes
- Database auditing that correlates application requests with abnormal query structures or resource consumption
- Policy enforcement requiring parameterized database access and approved input-validation helpers
Automated application security and code review tools may help identify unsafe query construction patterns.

