Summary
FreeScout's file upload denylist fails to block the .pht extension, allowing authenticated agents to upload executable PHP files into a web-accessible directory.
On typical Apache + mod_php deployments, this oversight can let an attacker run arbitrary commands as the web server user simply by uploading a crafted .pht file.
Affected context
This vulnerability occurs in FreeScout installations where:
- The application is deployed on Apache with
libapache2-mod-php(or equivalent PHP handler using<FilesMatch ".+\.ph(ar|p[3457]?|t|tml)$">). - User-uploaded files are stored under
storage/app/public/uploads/and served via/storage/uploads/. - The upload feature is available to authenticated agents via
POST /uploads/upload.
In such setups, any unblocked PHP-like extension (such as .pht) written into a web-accessible directory can be treated as executable code by the web server.
Exploit preconditions
- Attack surface: Authenticated file upload endpoint
POST /uploads/upload(SecureController@upload). - Required access: Valid FreeScout agent account with permission to upload attachments.
- Trigger point: Uploading a file with a
.phtextension, which is then stored unmodified understorage/app/public/uploads/and served at/storage/uploads/. - Why exploitation is possible: The denylist
Helper::$restricted_extensionsomits.pht, and Apache's default PHP handler matches.phtvia<FilesMatch ".+\.ph(ar|p[3457]?|t|tml)$">, causing the uploaded file to be executed as PHP rather than treated as inert content.
Why this happens
The underlying issue is an incomplete validation of uploaded file types, a classic example of CWE-434: Unrestricted Upload of File with Dangerous Type.
FreeScout relies on a denylist (Helper::$restricted_extensions) to neutralize risky uploads, but only some PHP-related extensions (like .phar, .phtml) were added in response to earlier fixes.
Because .pht and similar extensions remain allowed, the application stores these files with their original extension in a web-accessible directory, effectively turning the upload feature into a code deployment mechanism whenever the web server interprets those extensions as PHP.
Potential impact
- An authenticated agent may upload a
.phtweb shell and execute arbitrary commands as thewww-datauser. - Attackers could read or modify application configuration files and data accessible to the web server process.
- Session takeover or impersonation through direct manipulation of stored session data or cookies if accessible.
- Lateral movement within the server environment or pivoting to internal services reachable from the web host.
- Full application compromise, including tampering with help desk content or customer communication records.
General mitigation guidance
Effective mitigation focuses on limiting which file types can be uploaded and on decoupling uploaded content from code execution paths.
Common defensive patterns include:
- Prefer an allowlist of safe, non-executable file types (e.g., images, PDFs, plain text) instead of a denylist of dangerous extensions.
- Normalize or rewrite uploaded filenames to non-interpretable extensions (e.g.,
.bin) and serve them via a separate static file handler that never passes them through the PHP engine. - Store uploads outside the web root and expose them through controlled download endpoints that stream file contents rather than executing them.
- Introduce server-side checks that inspect MIME types and content signatures in addition to extensions, while still treating all uploads as untrusted.
- Apply least privilege to the web server user, ensuring that even if an upload is executed, it has minimal access to system resources.
How teams detect issues like this
Detection generally involves combining application-level review with infrastructure-level monitoring:
- Use static code analysis or manual review to identify upload paths that write files directly into web-accessible directories while preserving user-controlled extensions.
- Look for denylist-based validation of file uploads in controllers and helper classes, and verify whether all PHP-like and scriptable extensions are covered or replaced by an allowlist.
- Implement security policies or automated tests that enforce separation between uploaded content directories and directories where server-side code resides.
- Monitor web server logs for requests to atypical PHP-like extensions (e.g.,
.pht,.phtm,.phps) and unusual access patterns from authenticated users shortly after uploads. - Incorporate periodic penetration tests or DAST scans that attempt to upload and access executable file types through user-facing upload endpoints.

