GHSA-2JRW-HP8Q-5VQW
Upload validators bypassed by an unknown Content-Type, allowing stored XSS
Texto original en inglés · Ver en español
CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Remediación | Parche 3.5.1 | django-filer · -51 d desde divulgación | |
| Divulgación | Publicada | GHSA-2JRW-HP8Q-5VQW divulgada · CVSS 5.4 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Impact
The AJAX upload endpoint (`filer-ajax_upload`) validated an upload against the MIME type in the client-supplied `Content-Type` of the multipart part. If that type was unknown to Python's `mimetypes` module, the upload skipped both the
check that the file extension matches the declared type and the validators configured in `FILER_FILE_VALIDATORS`. The file was then stored and served under the MIME type derived from its file name.
An authenticated user holding the `filer.add_file` permission could therefore upload, for example, an HTML or SVG file containing script by declaring an arbitrary unregistered type such as `foo/bar`. With the default `FILER_IS_PUBLIC_DEFAULT = True` the file is served publicly from the media origin, giving stored cross-site scripting against anyone who opens the file
URL. `FILER_MIME_TYPE_WHITELIST` did not prevent this.
Because `ajax_upload` was not wrapped in `admin_site.admin_view()`, it did not check `is_staff`: a non-staff user with filer.add_file` could reach the upload URL for files without a folder.
The endpoint was also decorated with `@csrf_exempt`. Django's default `SESSION_COOKIE_SAMESITE = "Lax"` stops a cross-site POST from carrying the session cookie in current browsers, so on a default install this is defense in depth. Deployments that relax `SameSite` were exposed to cross-site uploads.
Separately, a `Content-Type` without a slash, or a mismatch between extension and declared type, raised an uncaught exception and returned HTTP 500.
Patches
Fixed in 3.5.1 (#1610):
- The MIME type of an upload is always derived from the file name (`mimetypes.guess_type(filename)[0] or "application/octet-stream"`). The client-supplied `Content-Type` is no longer used. The validated type is now the same type that is stored and served. Unknown extensions become `application/octet-stream`, which the default validators reject.
- `ajax_upload` is wrapped in `admin_site.admin_view()` (it requires an active staff user) and is no longer `@csrf_exempt`. The bundled uploaders send `X-CSRFToken`.
- Malformed MIME types no longer raise. Upload errors return a JSON error with a 4xx status code instead of HTTP 500 or HTTP 200.
Upgrade to 3.6.0 or later if you use the "Upload Files" button in the folder view: in 3.5.1 that uploader did not yet send the CSRF token, so its uploads failed (#1617).
Behavior changes in 3.5.1: uploads with an extension unknown to `mimetypes` are rejected by the default validators; register the extension with `mimetypes.add_type()` if you need it. Custom clients posting to
`filer-ajax_upload` must send a CSRF token, log in as a staff user, and handle non-2xx responses.
Workarounds
If you cannot upgrade, restrict `filer.add_file` to trusted users, and serve media from a separate origin with `Content-Disposition: attachment` or a restrictive `Content-Security-Policy` for user-uploaded files.
Credits
Reported by Miguel Rafael Martín de Nicolás Acedo (@miguel-hub1).
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
pypidjango-filer |
Corregida | 3.5.1 | -51 d | 3.6.0 no afectada |
3.5.1Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/django-cms/django-filer/security/advisories/GHSA-2jrw-hp8q-5vqwLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
