Summary
A GeoDjango spatial lookup issue can cause attacker-controlled values to be interpreted as raster data sources, enabling arbitrary file creation or outbound network requests through GDAL handlers. The risk is present when untrusted lookup values reach the GDALRaster constructor, such as through a Django admin query string, and a written file is later loaded or imported by the application.
Affected context
The issue occurs in Django deployments using GeoDjango spatial lookups against GeometryField or RasterField values. A relevant input may be supplied through an administrative filtering interface by a staff user with view permission, although the exact exposure depends on application routing, permissions, and enabled GDAL drivers. The risk is greater when the application process can write to sensitive locations or when GDAL virtual filesystem handlers permit outbound connections.
Exploit preconditions
- Attack surface: GeoDjango spatial lookup handling, including administrative changelist filters
- Required access: Access sufficient to submit a value used in a spatial-field lookup, such as staff-level view permission in the Django admin
- Trigger point: Processing the lookup's right-hand-side value through the GDALRaster constructor
- Why exploitation is possible: Dictionary values or JSON-formatted strings may be treated as writable raster sources, while other strings may be interpreted as GDAL data sources capable of network access
- Additional impact condition: Arbitrary file write may become code execution if the destination is later imported or executed by the application
Why this happens
GeoDjango optimistically interprets the right-hand side of spatial lookups as raster input before sufficiently constraining its type, source, or destination. Passing attacker-influenced values to GDALRaster can activate file-backed drivers in write mode or virtual filesystem handlers that perform network access. This reflects CWE-73: External Control of File Name or Path, because untrusted input can influence filesystem targets, and is also related to CWE-918: Server-Side Request Forgery when datasource processing causes outbound requests.
Potential impact
- An attacker may write files with chosen names and contents
- The application may make outbound requests to attacker-selected or internal destinations
- Sensitive local or cloud services could be reached through GDAL network handlers
- A written file could enable remote code execution if it is later imported or executed
- Application data or deployment integrity could be compromised
General mitigation guidance
Mitigation generally focuses on reducing trust in spatial lookup inputs and preventing parser or driver behavior from selecting arbitrary resources.
Common defensive patterns include:
- Restricting spatial lookup values to explicitly validated geometry or raster types
- Avoiding implicit conversion of arbitrary strings and mappings into GDAL data sources
- Allowing only approved GDAL drivers and disabling unnecessary virtual filesystem handlers
- Constraining file operations to dedicated, non-executable directories with controlled permissions
- Applying outbound network restrictions to application and worker processes
- Running Django processes with least-privilege filesystem and network access
- Separating uploaded or generated files from Python import paths and executable locations
How teams detect issues like this
Organizations can look for this issue through:
- Static analysis rules identifying untrusted values passed to GDALRaster or similar datasource constructors
- Code review checks for spatial lookup coercion that occurs before type, path, or driver validation
- Tests using hostile path-like, JSON-like, and remote datasource values in GeometryField and RasterField filters
- Runtime monitoring for unexpected file creation, GDAL virtual filesystem access, and outbound connections from web or worker processes
- Policy enforcement that restricts writable directories, executable imports, approved GDAL drivers, and application egress
Automated security review tools may help identify dangerous dataflow paths, but deployment-level filesystem and network controls remain important.

