Summary
A path traversal vulnerability in phpMyFAQ's media browser file deletion logic allows user input to be concatenated directly into filesystem paths without proper validation.
Combined with missing CSRF protection, an attacker can trick an authenticated user into issuing crafted requests that may delete arbitrary files within the web server's accessible directories.
Affected context
This vulnerability occurs in the MediaBrowserController::index() method, specifically when handling the fileRemove action in phpMyFAQ's media browser.
The issue is present when:
- File deletion is driven by a user-supplied
nameparameter - The application concatenates this
namedirectly with the base upload directory path - There is no normalization or rejection of directory traversal sequences (e.g.,
../) - CSRF protection is not enforced for this endpoint
It primarily affects deployments where authenticated users can access the media browser and the underlying PHP process has permission to delete files in the target directories.
Exploit preconditions
- Attack surface: HTTP endpoint for the media browser's
fileRemoveaction. - Required access: A victim user must be authenticated with permissions to use the media browser; the attacker can be unauthenticated if they rely on CSRF.
- Trigger point: A crafted HTTP request (or malicious web page) that supplies a
nameparameter containing path traversal sequences, such as../. - Why exploitation is possible:
- The
nameparameter is concatenated to the base upload path with no directory traversal validation or canonicalization. - The FILTER_SANITIZE_SPECIAL_CHARS filter only encodes HTML special characters, leaving filesystem metacharacters (
.,/,\) untouched. - The endpoint does not enforce CSRF tokens, allowing an attacker to cause state-changing requests via a victim's browser session.
Why this happens
The root cause aligns with CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
The application treats a user-controlled name parameter as if it were a safe relative path and directly concatenates it with the base upload directory, without:
- Normalizing the path
- Rejecting
..components - Enforcing that the resolved path stays within the intended upload directory
Additionally, the absence of CSRF validation on the file deletion endpoint allows cross-origin sites to trigger this unsafe file deletion behavior on behalf of authenticated users.
Potential impact
- Deletion of media files managed by the phpMyFAQ application
- Deletion of other files within directories writable or deletable by the PHP process, depending on server configuration
- Disruption of site content, including FAQs that rely on media assets
- Potential deletion of configuration, cache, or log files if they are located under or reachable from the upload path
- Increased impact of CSRF attacks, turning a simple link or embedded resource into a destructive action against the application's filesystem
General mitigation guidance
Effective mitigation focuses on both path handling and request integrity:
- Constrain file operations to whitelisted locations:
- Use server-side lookup keys or IDs rather than accepting raw filenames or paths from clients.
- When paths must be accepted, normalize and canonicalize them, then verify that the resolved path remains strictly under the intended base directory.
- Strictly validate filenames:
- Reject any input containing directory separators (
/,\),.., or other traversal-related characters. - Enforce an allowlist-based filename pattern (e.g., alphanumeric plus a small set of safe characters and an expected extension).
- Apply defense-in-depth for filesystem access:
- Run the application under a dedicated OS user with limited filesystem permissions, restricting what can be deleted.
- Separate upload directories from configuration and application code to reduce potential damage.
- Enforce CSRF protection on state-changing endpoints:
- Require and validate CSRF tokens on all file deletion and modification actions.
- Prefer same-site cookies and CSRF defenses that do not depend solely on headers under attacker control.
How teams detect issues like this
Detection typically combines code-focused and behavior-focused approaches:
- Static analysis and code scanning:
- Flag patterns where user input is concatenated into filesystem paths, especially in delete, move, or write operations.
- Look for the presence of
../or other traversal markers in input handling logic without subsequent validation or canonicalization. - Identify state-changing endpoints (e.g., delete operations) lacking CSRF token verification.
- Targeted code review:
- Review controllers and upload handlers for direct use of request parameters in filesystem APIs (
unlink,fopen,rename, etc.). - Check that any path sanitization is robust and not limited to HTML-oriented filters like
FILTER_SANITIZE_SPECIAL_CHARS. - Verify that CSRF protections are uniformly applied to all administrative and content-modifying routes.
- Runtime and log analysis:
- Monitor server logs for repeated access to file deletion endpoints with unusual
namevalues (containing../or deeply nested paths). - Configure alerts for anomalous spikes in file deletion activity or unexpected 404s following intensive delete operations.
Automated SAST or security-focused code review tools can be configured to flag these patterns as part of continuous integration pipelines.

