Summary
WWBN AVideo's ImageGallery::saveFile() method accepts uploaded images based on MIME type detection but preserves user-controlled file extensions when saving.
An attacker can upload a polyglot file that looks like a JPEG to the MIME checker but has a .php extension and embedded PHP code, resulting in a web-accessible executable script and enabling remote code execution under typical PHP configurations.
Affected context
This vulnerability appears in AVideo deployments that:
- Allow users to upload images through the Image Gallery feature.
- Use
ImageGallery::saveFile()to persist uploaded content. - Run PHP in the same web-accessible directory (or subdirectories) used for storing uploaded files.
- Rely on MIME type detection alone to validate uploads while preserving the original filename extension.
In such contexts, user-supplied filenames can determine the final file extension despite server-side file content checks, creating an inconsistency between perceived file type and server execution behavior.
Exploit preconditions
- Attack surface: HTTP(S) file upload endpoints exposed by the AVideo Image Gallery.
- Required access: Ability to upload image files (e.g., an authenticated user role allowed to upload images, or any public upload point if misconfigured).
- Trigger point: Submission of a crafted upload request containing:
- A polyglot payload with valid JPEG magic bytes so
finforeports an image MIME type. - A filename ending in
.php(or another executable extension interpreted by the server). - Why exploitation is possible:
- The application validates content with
finfobut does not constrain or normalize the output filename extension. - The uploaded file is stored in a directory where the web server executes
.phpfiles. - When an attacker accesses the uploaded
.phpfile via HTTP, the embedded code is interpreted by the PHP engine.
Why this happens
The underlying bug is a form of unrestricted file upload where validation is applied to file content but not to the resulting filename or execution context.
Specifically, ImageGallery::saveFile():
- Uses
finfoto check that the file content appears to be an image. - Still derives the stored filename (including extension) from user input without enforcing an allowlist of safe extensions or normalizing to a non-executable type.
This mismatch between content-based validation and extension-based execution maps directly to CWE-434: Unrestricted Upload of File with Dangerous Type, because files that the server can execute are allowed to be uploaded and placed in executable paths.
Potential impact
- Execution of arbitrary PHP code on the server, leading to full remote code execution.
- Reading or modification of sensitive data accessible to the web application.
- Installation of web shells or backdoors for persistent access.
- Use of the compromised server as a pivot point to attack internal systems.
- Defacement, data exfiltration, or manipulation of hosted video and media content.
General mitigation guidance
Effective mitigation centers on aligning upload validation with how the web server treats stored files:
- Enforce a strict allowlist of file extensions (e.g.,
.jpg,.jpeg,.png,.gif) regardless of user-supplied filenames. - Generate server-side filenames independent of user input, using random identifiers and fixed safe extensions.
- Store uploaded files in directories that are not executable by the web server, such as dedicated storage paths or outside the document root, and serve them through controlled endpoints or proxies.
- Combine MIME type validation using
finfowith additional checks such as validating file headers and size to reduce malformed or polyglot uploads. - Apply least-privilege configuration for the web server and PHP runtime so that compromise of file upload handling yields minimal additional privileges.
How teams detect issues like this
Detection often involves reviewing how file uploads are processed and where they are stored:
- Static analysis and code review:
- Look for file upload handlers that:
- Use
$_FILESor equivalent to save user-supplied files. - Preserve the original filename or extension when saving to disk.
- Write files into web-accessible and executable directories.
- Flag code paths that validate only MIME type or magic bytes without constraining extensions.
- Configuration and policy checks:
- Verify web server and PHP configurations so that upload directories do not allow code execution.
- Enforce policies requiring random, safe filenames and non-executable storage for all user uploads.
- Runtime and log analysis:
- Monitor web server logs for requests to uploaded paths with executable extensions (e.g.,
.php,.phtml) or unusual access patterns. - Use intrusion detection or web application firewalls to flag access to newly uploaded executable files.

