Summary
Sharp's file upload endpoint in vulnerable versions allows authenticated users to override server-side validation by supplying their own validation_rule parameter, effectively disabling MIME type and extension checks.
When combined with a publicly accessible storage disk, this can enable arbitrary file uploads, including executable PHP files, which may lead to remote code execution or content tampering.
Affected context
This vulnerability appears in Sharp deployments using versions prior to 9.20.0 where:
- The
ApiFormUploadControllerendpoint is exposed to authenticated users - Client-supplied
validation_ruleparameters are accepted and passed into Laravel's validator - Uploaded files are stored on a disk that may be publicly accessible (e.g., web-root–served or CDN-exposed)
Under default private-disk configurations, uploaded PHP files typically cannot be executed directly, but the upload of unsafe file types is still possible.
Exploit preconditions
- Attack surface: HTTP(S) file upload endpoint handled by
ApiFormUploadController - Required access: Authenticated access to any Sharp form or feature that uses the upload API
- Trigger point: Intercepting and modifying the upload request to include
validation_rule[]=fileor similar client-controlled rules - Why exploitation is possible: The server trusts client-controlled validation rules and passes them directly into Laravel's validator, allowing attackers to weaken or remove file-type restrictions and bypass MIME/extension checks.
Why this happens
The core issue is trusting client-controlled validation metadata for security-critical checks.
Instead of defining upload constraints exclusively on the server, the endpoint accepts a validation_rule parameter from the client and feeds it directly into Laravel's validation layer.
This design effectively delegates security policy to the requester, enabling them to choose permissive rules like file that bypass MIME type and extension restrictions.
This maps to CWE-434: Unrestricted Upload of File with Dangerous Type, where an application accepts file uploads without enforcing robust, server-side validation of file content and type.
Potential impact
- Upload of arbitrary file types, including PHP, shell scripts, or other executable formats
- Potential remote code execution if uploaded executable files are placed on a publicly served, interpreter-enabled disk
- Hosting of malicious content (e.g., malware, phishing pages, defacement content) on the affected site or storage
- Abuse of storage for data exfiltration or staging of further attacks
- Circumvention of organizational file-type policies and content controls
General mitigation guidance
Effective mitigation focuses on enforcing upload security policies exclusively on the server and isolating uploaded content:
- Define strict, whitelisted validation rules server-side for each upload endpoint (e.g., allowed MIME types, extensions, and size limits) and ignore any client-supplied validation hints.
- Treat all client-provided validation or configuration parameters as untrusted and purely advisory, never as authoritative for security decisions.
- Store uploaded files on private or non-executable storage locations that are not directly served by the web server or interpreter.
- Separate upload storage from application code directories and disable script execution in upload paths.
- Apply least-privilege access controls so that uploaded content requires explicit, controlled mechanisms to be accessed or transformed.
- Where feasible, add secondary checks such as content-type sniffing, magic-byte inspection, or transformation (e.g., re-encoding images) to reduce the risk of disguised file types.
How teams detect issues like this
Organizations can detect and monitor for this class of issue through:
- Static analysis: Rules that flag use of client-controlled input (e.g., request parameters) being passed into validation or policy APIs without sanitization, especially around upload logic.
- Code review signals: Upload endpoints where validation rules are constructed from user input, or where server-side whitelists are absent or optional.
- Configuration and policy checks: Automated reviews of storage configuration to ensure upload disks are private, non-executable, and not mapped under the web root.
- Runtime monitoring: Logging and alerting on unusual file upload patterns, such as executable extensions, overly large files, or uploads from unusual accounts or IP ranges.
- Security testing: Regular API-focused penetration tests and fuzzing of upload endpoints, including manipulation of hidden parameters and client-side validation artifacts.

