Summary
Grav contains a path traversal vulnerability in its media deletion logic, allowing an authenticated user with media management permissions to target files outside the intended media directory.
The issue becomes risky when attacker-controlled filenames are used to construct deletion paths without validating the complete resolved path.
Affected context
The vulnerability occurs in Grav's media management functionality, specifically the file deletion behavior implemented by MediaUploadTrait::deleteFile(). It may affect deployments where authenticated users can manage media and where filenames containing directory components are accepted before the resulting path is passed to the filesystem deletion operation.
Exploit preconditions
- Attack surface: Authenticated media management functionality
- Required access: A user account with permissions to manage or delete media
- Trigger point: Processing of a user-supplied filename during file deletion
- Why exploitation is possible: The basename is checked, but directory components may remain unvalidated and influence the final path passed to
unlink()
Why this happens
The underlying bug is incomplete path validation. The application validates only part of a user-controlled filename while retaining untrusted directory components, allowing the final filesystem path to escape the intended media storage directory.
This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where input is used in filesystem operations without canonicalizing and constraining the complete resolved path.
Potential impact
- Arbitrary files within the application's operating environment may be deleted
- Application availability could be disrupted by removal of required files
- Stored media, configuration artifacts, or user data may be lost
- Deletion of security-relevant files could weaken monitoring or system integrity
- The impact may be amplified by the permissions of the application process
General mitigation guidance
Mitigation generally focuses on treating filenames and paths as untrusted input and enforcing the intended storage boundary.
Common defensive patterns include:
- Resolve candidate paths canonically and verify they remain beneath the configured media directory
- Prefer server-generated identifiers or basenames over user-controlled path components
- Reject directory separators and traversal components where subdirectories are not required
- Use filesystem APIs that separate trusted directories from untrusted names
- Apply least-privilege permissions to the application process and media storage
- Restrict media-management privileges to users who require them
- Maintain backups and recovery controls for important application files
How teams detect issues like this
Organizations can look for path traversal risks through:
- Static analysis rules that flag user-controlled values passed to file deletion or file access APIs
- Code review checks for basename-only validation, string-prefix checks, and missing canonical-path containment checks
- Tests using normalized and non-normalized path inputs to verify storage-boundary enforcement
- Runtime monitoring of deletion operations outside approved media directories
- Authorization and policy checks ensuring media-management permissions are narrowly assigned
Automated security review tools may help identify filesystem operations that receive insufficiently constrained input.

