Summary
NanoCMS 0.4 contains an authenticated file upload flaw in its page creation mechanism that allows attackers to upload PHP files with arbitrary code into the pages directory.
When an authenticated user can create or modify page content without proper validation, this can lead to remote code execution on the server whenever the uploaded PHP file is requested.
Affected context
This vulnerability arises in NanoCMS 0.4 deployments where authenticated users are allowed to create or manage pages and the application stores page content as executable PHP files or allows PHP code within uploaded content.
The risk is present when:
- Page creation or editing accepts input that can be saved as a PHP file (or within a PHP context),
- The resulting files are written into a web-accessible directory (e.g., a pages directory),
- The web server is configured to execute PHP in that directory.
In such setups, user-supplied content effectively becomes server-side executable code if not sanitized.
Exploit preconditions
- Attack surface: Web application interface for page creation and content management.
- Required access: Valid authenticated account with permissions to create or modify pages.
- Trigger point: Submitting crafted page content or file data that is saved as a PHP file in the pages directory.
- Why exploitation is possible: The application does not sufficiently sanitize or restrict the content or file type during the page creation process, allowing user-controlled data to be stored as executable PHP, which the server then interprets as code when accessed via HTTP.
Why this happens
The underlying issue is improper control over dynamically generated code, aligning with CWE-94: Improper Control of Generation of Code ('Code Injection').
The page creation functionality accepts user input that can end up in a PHP file or within a PHP execution context without robust validation, encoding, or restriction of executable constructs.
As a result, user-controlled data can become server-side code that is executed when the file is requested, effectively granting the attacker the ability to run arbitrary commands within the web server's execution environment.
This is a design and validation flaw where content intended to be treated as data is instead handled as executable code by the platform.
Potential impact
- Remote code execution with the privileges of the web server process.
- Installation of web shells for persistent access and further attacks.
- Reading or modification of application configuration and data.
- Pivoting to other internal systems or services reachable from the server.
- Defacement or manipulation of website content served from the CMS.
- Potential escalation to full server compromise depending on environment hardening.
General mitigation guidance
Effective mitigation focuses on preventing user-supplied content from becoming executable code and constraining the effects of any uploaded content.
Recommended patterns include:
- Treating user-supplied page content strictly as data: store content in a database or non-executable templates rather than as raw PHP files.
- Enforcing strict content validation and sanitization for page bodies, disallowing PHP tags and other executable constructs.
- Restricting upload destinations to directories that are not configured for code execution (e.g., serve uploads from a static file host or non-PHP-enabled path).
- Applying server-side configuration controls (such as disabling PHP execution in upload or pages directories via web server configuration).
- Applying least-privilege principles to the web server user and file system permissions so that it cannot create or modify executable code paths unnecessarily.
- Using templating engines or rendering layers that separate presentation logic from user-provided content and do not directly evaluate user input as code.
How teams detect issues like this
Detection efforts can combine code-focused analysis with runtime monitoring:
- Static analysis: Search for code paths where user input from page creation forms is written directly to disk as
.phpor other executable files without content filtering or file-type checks. - Code review: During manual review, flag any functionality that:
- Writes user input into PHP files,
- Uses
include,require, or dynamic file execution on user-controllable paths, - Lacks checks on MIME type, file extension, and content for uploaded or generated files.
- Configuration review: Inspect web server and PHP-FPM configuration to identify directories where uploads or generated pages are stored and verify whether those paths allow code execution.
- Runtime monitoring: Look for unusual file creation events in web-accessible directories, requests to unexpected new PHP files, or outbound network activity originating from the web server process.
- Automated tools: Employ SAST/DAST tools or CMS-specific security scanners configured to detect code injection and unsafe file upload patterns.

