Django GIS RasterField SQL Injection (CVE-2026-1207)
by sw0rd1ight · 2026-07-05
- Severity
- High
- CVE
- CVE-2026-1207
- Category
- web
- Affected product
- Django django.contrib.gis (GeoDjango) RasterField queries
- Affected versions
- Django versions using GeoDjango RasterField with __contains raster lookups (specific patched version not stated in source)
- Disclosed
- 2026-07-05
- Patch status
- unpatched
References
Archive entry
intelseclab/poc-archiveMetadata
| Field | Value |
|---|---|
| Date Added | 2026-07-05 |
| Last Updated | 2026-04 |
| Author / Researcher | sw0rd1ight |
| CVE / Advisory | CVE-2026-1207 |
| Category | web |
| Severity | High |
| CVSS Score | Not specified in source |
| Status | PoC |
| Tags | django, gis, geodjango, sql-injection, rasterfield, postgis, python |
| Related | N/A |
Affected Target
| Field | Value |
|---|---|
| Software / System | Django django.contrib.gis (GeoDjango) RasterField queries |
| Versions Affected | Django versions using GeoDjango RasterField with __contains raster lookups (specific patched version not stated in source) |
| Language / Platform | Python / Django, PostgreSQL + PostGIS backend |
| Authentication Required | No |
| Network Access Required | Yes |
Summary
The reproduction project demonstrates a SQL injection flaw in GeoDjango’s raster query handling. When a view builds a RasterField lookup such as rast__contains=(rast, band), the band value taken directly from an HTTP query parameter is concatenated into the generated SQL rather than being passed as a bound parameter. An attacker can therefore inject arbitrary SQL through the band parameter of the demo book/search endpoint. The included Django project (models, views, migrations) reproduces the vulnerable raster comparison end-to-end against a PostGIS-backed database inside a devcontainer.
Vulnerability Details
Root Cause
The band component of a raster __contains lookup is inserted into the raw SQL query string without parameterization when GeoDjango builds the ST_ContainsParam fragment, allowing attacker-controlled input to break out of the intended value context.
Attack Vector
- Stand up the vulnerable Django project (
vulnapp withRasterModel) behind PostgreSQL/PostGIS. - Send a GET request to the
book/searchendpoint with a craftedbandquery parameter, e.g. a value that closes the current clause and appends a stacked query. - The unsanitized
bandvalue is spliced into the SQL executed against the raster table. - Use a boolean/time-based technique (e.g.
pg_sleep) to confirm and extract data through the injected SQL.
Impact
Full SQL injection against the application’s database, enabling data disclosure, blind data extraction, and potential further compromise depending on database privileges.
Environment / Lab Setup
Target: Django + django.contrib.gis (GeoDjango) with PostGIS-backed PostgreSQL
Attacker: Any HTTP client (curl/browser) able to reach the exposed Django dev server
Proof of Concept
PoC Script
See
manage.py,vuln/, andweb/in this folder.
| |
The provided Django project stands up a minimal app exposing a vulnerable raster search view; the request above injects a time-delay payload into the band parameter and the resulting ~3 second response delay confirms the injection.
Detection & Indicators of Compromise
"GET /book/search?band=" combined with SQL keywords (select, union, sleep) in query string
Signs of compromise:
- Abnormally slow responses to
book/searchrequests correlating withpg_sleep-style payloads in thebandparameter - PostgreSQL logs showing malformed or stacked queries originating from the raster lookup
- Unexpected raw SQL fragments appearing in application query logs (
qs.queryoutput)
Remediation
| Action | Detail |
|---|---|
| Primary fix | No vendor patch confirmed as of 2026-07-05 — monitor for advisory |
| Interim mitigation | Validate/whitelist the band parameter to numeric-only values before use in raster lookups, and avoid passing unsanitized user input into RasterField queries |
References
Notes
Mirrored from https://github.com/sw0rd1ight/CVE-2026-1207 on 2026-07-05.
| |