CVE-2026-72695: Grav Path Traversal Vulnerability

HIGH
Advisory Identifier: GHSA-jq29-c7v8-rg55
CVSS 8.1
CWE-22
Published
Advisory Summary

CVE-2026-72695 is a HIGH (CVSS 8.1) path traversal vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Grav libraries in the Packagist ecosystem. The issue involves path traversal in mediauploadtrait::deletefile() allows arbitrary file deletion. Remediation is available by upgrading affected packages to version 2.0.16.

CVE-2026-72695 at a Glance

CVE Identifier CVE-2026-72695
GHSA Identifier GHSA-jq29-c7v8-rg55
Severity HIGH
CVSS v3.1 Base Score 8.1
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Grav
Package Ecosystem Packagist
Published Date
Last Updated

Security Impact

CVSS: 8.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required Low (PR:L)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2026-72695

To remediate this vulnerability, upgrade all affected Grav dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

getgrav/grav fixed: 2.0.16
Upgrade getgrav/grav to 2.0.16
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for getgrav/grav

How to Check if You Are Affected

To determine whether your application is affected by CVE-2026-72695, inspect your project dependencies for Grav:

inspect dependencies for getgrav/grav

Analyze the terminal output to locate any version of Grav in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.0.16), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In Grav, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

# Path Traversal in MediaUploadTrait::deleteFile() Allows Arbitrary File Deletion ## Summary A path traversal vulnerability in `MediaUploadTrait::deleteFile()` allows an authenticated user with media management permissions to delete arbitrary files on the server. The method validates only the basename portion of the filename using `Utils::checkFilename()`, while the directory path (which may contain `../` sequences) is preserved and passed unvalidated to `unlink()`. This enables directory escape from the intended media storage path. ## Severity **High (8.1)** - CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:H ## CWE CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') ## Details In `system/src/Grav/Common/Media/Traits/MediaUploadTrait.php`, the `deleteFile()` method (lines 332-365) performs filename validation only on the basename, not the full path: ```php public function deleteFile(string $filename, ?array $settings = null): void { $settings = $this->getUploadSettings($settings); $filesystem = Filesystem::getInstance(false); // Line 339-340: Only the BASENAME is validated $basename = $filesystem->basename($filename); // e.g. "evil.jpg" from "../../evil.jpg" if (!Utils::checkFilename($basename)) { // passes - no traversal in basename throw new RuntimeException(/* ... */); } $path = $settings['destination'] ?? $this->getPath(); // ... // Line 353: Full pathname (with traversal) is preserved $pathname = $filesystem->pathname($filename); // "../../" // Line 356-357: Traversal path reconstructed [$base, $ext,,] = $this->getFileParts($basename); $name = "{$pathname}{$base}.{$ext}"; // "../../evil.jpg" // Line 360: Passed to doRemove() $this->doRemove($name, $path); } ``` `doRemove()` (line 521-582) then calls: ```php // Line 538 unlink("{$folder}/{$filename}"); // e.g. unlink("/var/www/grav/user/pages/mypage/../../config/system.yaml") ``` `Utils::checkFilename()` (lines 1022-1044) properly checks for `/`, `\`, and `..`, but it is applied to `$filesystem->basename($filename)` (the last path component only), so traversal sequences in the directory portion are never validated. ### Data flow from user input The vulnerability is reachable through the Flex media handling pipeline: 1. `FlexMediaTrait::setUpdatedMedia()` (line 386) iterates form flash data where `$filename` is the array key - user-controlled 2. For file deletions (`$file` is null, line 396), NO upload validation is performed (the `checkUploadedFile()` call at line 401 only executes when `$file` is truthy) 3. The raw filename is stored in `$this->_uploads` at line 414 4. `saveUpdatedMedia()` (line 499) calls `$media->deleteFile($filename, $settings)` with the unsanitized filename ### Sibling: renameFile() The same pattern exists in `renameFile()` (lines 374-405) which has even weaker validation - it performs NO `checkFilename()` call at all. While `renameFile()` currently has no callers in the core codebase, it is part of the public `MediaUploadInterface` and should be fixed as defense-in-depth. ## Proof of Concept **Environment**: Grav CMS 2.0.16 with admin plugin The attack requires an authenticated admin user with page/media editing permissions (not super-admin). 1. Create a target file: ```bash echo "DELETE_ME" > /var/www/grav/user/data/target.txt ``` 2. Submit a Flex object form (e.g. page edit) with a crafted media deletion where the filename key contains path traversal: ``` POST /admin/pages/mypage/task:save Content-Type: multipart/form-data # The form flash data includes a media deletion entry with key: # "../../data/target.txt" -> null (deletion marker) ``` 3. When `saveUpdatedMedia()` processes the deletion queue: - `$filename` = `../../data/target.txt` - `deleteFile("../../data/target.txt")` is called - `$basename` = `target.txt` (passes `checkFilename()`) - `$pathname` = `../../data/` - `$name` = `../../data/target.txt` - `doRemove()` calls `unlink("/var/www/grav/user/pages/mypage/../../data/target.txt")` - Which resolves to `unlink("/var/www/grav/user/data/target.txt")` 4. The file is deleted outside the intended media directory. ### Impact An authenticated user with media management permissions can: - Delete configuration files (`user/config/system.yaml`, `user/config/security.yaml`) - Delete other pages' content files - Delete authentication-related files (user account YAML files) - Cause denial of service by removing critical application files - Potentially escalate privileges by removing security configuration ## Suggested Fix Apply `Utils::checkFilename()` to the full `$filename` parameter before decomposing it, or reject any filename containing directory separators or `..` sequences: ```php public function deleteFile(string $filename, ?array $settings = null): void { $settings = $this->getUploadSettings($settings); $filesystem = Filesystem::getInstance(false); // Validate the FULL filename, not just the basename if (!Utils::checkFilename($filename)) { throw new RuntimeException(/* ... */); } // ... rest unchanged } ``` The same fix should be applied to `renameFile()` for both `$from` and `$to` parameters. ## References - Vulnerable file: `system/src/Grav/Common/Media/Traits/MediaUploadTrait.php` lines 332-365, 521-582 - Caller: `system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php` lines 386-414, 490-499 - Sibling: `system/src/Grav/Common/Media/Traits/MediaUploadTrait.php` lines 374-405 (renameFile) - Related GHSA: GHSA-g6j3-8jv9-ch5f (path traversal in PagesController::batchCopy - different file, same bug class) ## Disclosure This vulnerability was discovered using AI-assisted security research tools.

CVE-2026-72695 Affected Grav Versions

1 component(s)
Fixed Versions:
2.0.16
Product / Package Ecosystem Affected Versions Fixed Version
getgrav/grav
Packagist
< 2.0.16
2.0.16

References

Frequently Asked Questions

What is CVE-2026-72695?
CVE-2026-72695 is a security vulnerability in Grav involving Path Traversal in MediaUploadTrait::deleteFile() Allows Arbitrary File Deletion under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Grav versions are affected?
Affected versions include releases prior to 2.0.16 across affected packages: getgrav/grav.
What version fixes CVE-2026-72695?
Upgrading to 2.0.16 (or the latest patched release for your respective branch) resolves the vulnerability.
Is getgrav/grav affected?
Yes, getgrav/grav is affected in releases prior to 2.0.16. Upgrade your dependency to 2.0.16 or later.
What is the CVSS score of CVE-2026-72695?
CVE-2026-72695 has a CVSS v3.1 base score of 8.1 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:H.
What CWE is associated with CVE-2026-72695?
CVE-2026-72695 is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.).
How can I check Packagist dependencies for CVE-2026-72695?
Run the dependency tree command: 'inspect dependencies for getgrav/grav'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-jq29-c7v8-rg55",
  "modified" : "2026-09-17T20:34:05Z",
  "published" : "2026-09-17T20:34:05Z",
  "aliases" : [ "CVE-2026-72695" ],
  "summary" : "Grav: Path Traversal in MediaUploadTrait::deleteFile() Allows Arbitrary File Deletion",
  "details" : "# Path Traversal in MediaUploadTrait::deleteFile() Allows Arbitrary File Deletion\n\n## Summary\n\nA path traversal vulnerability in `MediaUploadTrait::deleteFile()` allows an authenticated user with media management permissions to delete arbitrary files on the server. The method validates only the basename portion of the filename using `Utils::checkFilename()`, while the directory path (which may contain `../` sequences) is preserved and passed unvalidated to `unlink()`. This enables directory escape from the intended media storage path.\n\n## Severity\n\n**High (8.1)** - CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:H\n\n## CWE\n\nCWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')\n\n## Details\n\nIn `system/src/Grav/Common/Media/Traits/MediaUploadTrait.php`, the `deleteFile()` method (lines 332-365) performs filename validation only on the basename, not the full path:\n\n```php\npublic function deleteFile(string $filename, ?array $settings = null): void\n{\n    $settings = $this->getUploadSettings($settings);\n    $filesystem = Filesystem::getInstance(false);\n\n    // Line 339-340: Only the BASENAME is validated\n    $basename = $filesystem->basename($filename);  // e.g. \"evil.jpg\" from \"../../evil.jpg\"\n    if (!Utils::checkFilename($basename)) {         // passes - no traversal in basename\n        throw new RuntimeException(/* ... */);\n    }\n\n    $path = $settings['destination'] ?? $this->getPath();\n    // ...\n\n    // Line 353: Full pathname (with traversal) is preserved\n    $pathname = $filesystem->pathname($filename);   // \"../../\"\n\n    // Line 356-357: Traversal path reconstructed\n    [$base, $ext,,] = $this->getFileParts($basename);\n    $name = \"{$pathname}{$base}.{$ext}\";            // \"../../evil.jpg\"\n\n    // Line 360: Passed to doRemove()\n    $this->doRemove($name, $path);\n}\n```\n\n`doRemove()` (line 521-582) then calls:\n\n```php\n// Line 538\nunlink(\"{$folder}/{$filename}\");\n// e.g. unlink(\"/var/www/grav/user/pages/mypage/../../config/system.yaml\")\n```\n\n`Utils::checkFilename()` (lines 1022-1044) properly checks for `/`, `\\`, and `..`, but it is applied to `$filesystem->basename($filename)` (the last path component only), so traversal sequences in the directory portion are never validated.\n\n### Data flow from user input\n\nThe vulnerability is reachable through the Flex media handling pipeline:\n\n1. `FlexMediaTrait::setUpdatedMedia()` (line 386) iterates form flash data where `$filename` is the array key - user-controlled\n2. For file deletions (`$file` is null, line 396), NO upload validation is performed (the `checkUploadedFile()` call at line 401 only executes when `$file` is truthy)\n3. The raw filename is stored in `$this->_uploads` at line 414\n4. `saveUpdatedMedia()` (line 499) calls `$media->deleteFile($filename, $settings)` with the unsanitized filename\n\n### Sibling: renameFile()\n\nThe same pattern exists in `renameFile()` (lines 374-405) which has even weaker validation - it performs NO `checkFilename()` call at all. While `renameFile()` currently has no callers in the core codebase, it is part of the public `MediaUploadInterface` and should be fixed as defense-in-depth.\n\n## Proof of Concept\n\n**Environment**: Grav CMS 2.0.16 with admin plugin\n\nThe attack requires an authenticated admin user with page/media editing permissions (not super-admin).\n\n1. Create a target file:\n```bash\necho \"DELETE_ME\" > /var/www/grav/user/data/target.txt\n```\n\n2. Submit a Flex object form (e.g. page edit) with a crafted media deletion where the filename key contains path traversal:\n\n```\nPOST /admin/pages/mypage/task:save\nContent-Type: multipart/form-data\n\n# The form flash data includes a media deletion entry with key:\n# \"../../data/target.txt\" -> null (deletion marker)\n```\n\n3. When `saveUpdatedMedia()` processes the deletion queue:\n   - `$filename` = `../../data/target.txt`\n   - `deleteFile(\"../../data/target.txt\")` is called\n   - `$basename` = `target.txt` (passes `checkFilename()`)\n   - `$pathname` = `../../data/`\n   - `$name` = `../../data/target.txt`\n   - `doRemove()` calls `unlink(\"/var/www/grav/user/pages/mypage/../../data/target.txt\")`\n   - Which resolves to `unlink(\"/var/www/grav/user/data/target.txt\")`\n\n4. The file is deleted outside the intended media directory.\n\n### Impact\n\nAn authenticated user with media management permissions can:\n- Delete configuration files (`user/config/system.yaml`, `user/config/security.yaml`)\n- Delete other pages' content files\n- Delete authentication-related files (user account YAML files)\n- Cause denial of service by removing critical application files\n- Potentially escalate privileges by removing security configuration\n\n## Suggested Fix\n\nApply `Utils::checkFilename()` to the full `$filename` parameter before decomposing it, or reject any filename containing directory separators or `..` sequences:\n\n```php\npublic function deleteFile(string $filename, ?array $settings = null): void\n{\n    $settings = $this->getUploadSettings($settings);\n    $filesystem = Filesystem::getInstance(false);\n\n    // Validate the FULL filename, not just the basename\n    if (!Utils::checkFilename($filename)) {\n        throw new RuntimeException(/* ... */);\n    }\n\n    // ... rest unchanged\n}\n```\n\nThe same fix should be applied to `renameFile()` for both `$from` and `$to` parameters.\n\n## References\n\n- Vulnerable file: `system/src/Grav/Common/Media/Traits/MediaUploadTrait.php` lines 332-365, 521-582\n- Caller: `system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php` lines 386-414, 490-499\n- Sibling: `system/src/Grav/Common/Media/Traits/MediaUploadTrait.php` lines 374-405 (renameFile)\n- Related GHSA: GHSA-g6j3-8jv9-ch5f (path traversal in PagesController::batchCopy - different file, same bug class)\n\n## Disclosure\n\nThis vulnerability was discovered using AI-assisted security research tools.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "getgrav/grav"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.0.16"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 2.0.15"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/getgrav/grav/security/advisories/GHSA-jq29-c7v8-rg55"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-72695"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/getgrav/grav"
  }, {
    "type" : "WEB",
    "url" : "https://www.vulncheck.com/advisories/grav-before-path-traversal-via-mediauploadtrait-deletefile"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-09-17T20:34:05Z",
    "nvd_published_at" : null
  }
}