Summary
Admidio versions 5.0.6 and below contain an unrestricted file upload vulnerability that allows authenticated users with upload permissions to bypass file type restrictions by abusing CSRF token handling logic.
By submitting an intentionally invalid CSRF token, an attacker can upload arbitrary files such as PHP scripts, which can then be executed on the server and may lead to full remote code execution.
Affected context
This vulnerability exists in the Documents & Files module of Admidio when:
- The application is running version 5.0.6 or earlier
- Users are granted permissions to upload files through the module
- The UploadHandlerFile.php logic performs CSRF token validation and file extension checks in a way that allows them to be bypassed together
It primarily affects environments where uploaded content is stored on a web-accessible path and where uploaded scripts can be interpreted by the server.
Exploit preconditions
- Attack surface: Web interface of the Admidio Documents & Files upload endpoint (UploadHandlerFile.php).
- Required access: Valid authenticated account with permissions to upload files in the target module.
- Trigger point: Submitting a crafted upload request that includes an intentionally invalid CSRF token alongside a disallowed file type (e.g., server-side executable script).
- Why exploitation is possible: A design flaw in how CSRF verification interacts with file extension checks causes the normal file type restrictions to be skipped or misapplied when CSRF validation fails in a particular way, allowing arbitrary file types to be accepted.
Why this happens
The core issue is improper enforcement of file type restrictions in the upload workflow, falling under CWE-434: Unrestricted Upload of File with Dangerous Type.
In UploadHandlerFile.php, CSRF token validation and file extension verification are coupled in a way that allows the logic to diverge from the intended security model: when a CSRF token is deliberately set to an invalid value, the code path that should reject the upload instead leads to incomplete or bypassed file extension validation.
This violates the principle of "fail closed," where any security check failure should result in a hard denial of the request, and demonstrates a systemic flaw in how trust decisions are sequenced and enforced in the upload handler.
Potential impact
- Upload and execution of arbitrary server-side scripts (e.g., PHP), which can lead to remote code execution.
- Full compromise of the underlying web application and potentially the hosting server.
- Unauthorized access to or exfiltration of sensitive user and application data.
- Installation of web shells or backdoors for persistent access.
- Use of the compromised server as a pivot point for lateral movement within the network.
- Tampering with application content, user data, or configuration.
General mitigation guidance
Reducing the risk of unrestricted file upload in this context generally involves hardening both the upload logic and the runtime environment:
- Enforce strict file type validation independent of CSRF status:
- Ensure that file extension and MIME-type verification are always applied and cannot be bypassed due to CSRF or other ancillary checks.
- Implement an explicit allowlist of safe, non-executable file types (e.g., specific document and image formats).
- Design upload handling to fail closed:
- Treat any CSRF token failure or other validation failure as an unconditional rejection of the upload.
- Avoid branching logic where security checks can be skipped or only partially executed based on intermediate states.
- Segregate uploaded content from executable contexts:
- Store uploaded files outside of web server document roots when possible.
- Configure the web server to disallow execution of scripts from upload directories (e.g., disabling PHP, CGI, or script handlers there).
- Constrain application privileges:
- Run the web application and file system permissions with least privilege, so that compromise of upload functionality has limited reach.
- Restrict write permissions to only necessary directories and prevent uploads from overwriting critical application files.
- Harden business logic around uploads:
- Limit who can upload files and in which modules, aligning permissions with actual business requirements.
- Add size limits, content-type checks, and optional content scanning to reduce abuse potential.
How teams detect issues like this
Identifying and monitoring for similar vulnerabilities and exploitation attempts typically involves:
- Code-level detection:
- Manual code review focusing on upload handlers (e.g., UploadHandlerFile.php) to verify:
- Strict separation and ordering of CSRF validation, authentication checks, and file validation.
- Consistent enforcement of allowlisted file types and MIME types.
- "Fail closed" behavior for any failed security check.
- Static analysis rules or custom linters that flag:
- Direct handling of file uploads without centralized validation.
- Upload directories that are under webroot and not explicitly marked as non-executable.
- Security testing and QA:
- Targeted penetration tests and fuzzing of upload endpoints to:
- Attempt uploads with invalid or missing CSRF tokens combined with disallowed extensions.
- Test uploads of script files, polyglot files, and files with double extensions or malformed headers.
- Automated security scanning in CI that exercises file upload workflows with various malformed requests.
- Operational monitoring:
- Web server logs analysis to detect:
- Serving of unexpected file types from upload directories (e.g., .php, .jsp, .aspx).
- Unusual patterns of upload requests from single user accounts.
- File integrity monitoring for webroot and upload directories to spot newly created or modified executable files.
These approaches can be integrated into ongoing secure development and operations practices, and may be supported by commercial or open-source SAST/DAST and log analysis tools.

