Summary
BookStack contains a high-severity unrestricted file upload vulnerability in its portable ZIP import functionality. An attacker with Import Content and Create Books permissions may upload a PHP polyglot disguised as a book cover, causing the file to be stored in the public web root and executed through an unauthenticated request.
Affected context
The vulnerability occurs in BookStack deployments that enable portable ZIP imports and allow users to import content and create books. It becomes risky when archive entries are validated as images without adequately preventing server-side executable content from being stored in a web-accessible directory.
Exploit preconditions
- Attack surface: Portable ZIP import functionality
- Required access: An authenticated account with Import Content and Create Books permissions
- Trigger point: Upload and processing of a book cover contained in an imported ZIP archive
- Execution condition: The uploaded file must be placed beneath a publicly served web root where the server interprets its content as PHP
- Why exploitation is possible: Image extension validation can be bypassed when archive content permits a PHP file with a
.phpfilename to be treated as a cover image
Why this happens
The underlying issue is insufficient control over uploaded archive contents and file types, mapping to CWE-434: Unrestricted Upload of File with Dangerous Type. The import process trusts an image-related filename or extension without reliably enforcing allowed content types, executable-file exclusions, and safe storage boundaries. Storing the resulting file in a web-accessible location allows the application server to interpret an attacker-controlled upload as executable code.
Potential impact
- An attacker could execute arbitrary PHP code on the application server
- The application or its underlying host may be compromised
- Sensitive application data or credentials could be accessed
- BookStack content may be modified, deleted, or used for further attacks
- The server could be used for lateral movement or malicious activity
General mitigation guidance
Mitigation generally focuses on treating archive uploads as untrusted content and preventing uploaded data from becoming executable.
Common defensive patterns include:
- Allowing only explicitly supported image formats after inspecting file content rather than trusting filenames or extensions
- Rejecting executable extensions and polyglot or ambiguous file formats
- Extracting archives into isolated, non-public storage
- Serving uploaded files through a controlled download path with non-executable response headers
- Configuring the web server to disable script execution in all upload directories
- Limiting import permissions according to least privilege
- Applying archive size, nesting, path, and file-count restrictions
- Separating uploaded content from application code and server-side runtime paths
How teams detect issues like this
Detection approaches can include:
- Static analysis and code review checks for archive extraction followed by filename-only type validation
- Searches for uploaded files being written beneath public web roots
- Review of server configuration for script execution enabled in upload directories
- Monitoring import events, archive extraction activity, and creation of unexpected executable extensions
- File integrity monitoring for new PHP or other server-side script files in media directories
- Policy enforcement requiring content-based file validation and isolated upload storage
- Automated security review tools that flag dangerous file upload and archive-processing patterns

