Summary
OpenPLC Runtime v3's legacy web UI allows authenticated users to control the filesystem path where uploaded program files are stored, without validation or restriction.
By supplying an absolute or crafted path, an attacker can write files anywhere the webserver can, and in default builds may escalate this into arbitrary native code execution via malicious C++ sources.
Affected context
This vulnerability occurs in OpenPLC Runtime v3 deployments using the legacy web UI's program-upload workflow.
It is relevant when the application:
- Persists attacker-supplied filenames directly in the Programs.File database field
- Uses these stored values as destination paths for file uploads
- Runs with filesystem write access to sensitive directories, such as the runtime core source tree
Risk is heightened in environments where uploaded C++ source files are automatically included in the build pipeline and compiled into the runtime executable.
Exploit preconditions
- Attack surface: HTTP interface of the legacy OpenPLC web UI program-upload endpoint
- Required access: Valid authenticated user session capable of uploading PLC programs
- Trigger point: Submission of a crafted
prog_filevalue and corresponding file upload, followed by operator-initiated compilation and runtime start - Why exploitation is possible: The application trusts the attacker-supplied filename, storing it in the database and later using it as a destination path via
os.path.join()without enforcing a safe base directory, normalization, or path restrictions. Python's path handling honors absolute paths, enabling writes outside the intended upload directory and into the core runtime source tree.
Why this happens
The underlying bug is an improper neutralization of special elements used in a file path, mapped to CWE-73.
Instead of treating the filename as untrusted input and constraining it to a specific directory, the application:
- Stores the raw attacker-provided
prog_filevalue in the database - Uses this value directly as the target path for saving an uploaded file
- Relies on
os.path.join()without enforcing that the result stays within an allowed directory
This pattern allows absolute paths or traversal sequences to escape expected locations and reach arbitrary filesystem locations, including directories that participate in the compilation pipeline.
Because the OpenPLC build process compiles all C++ source files in the runtime core directory into the executable, a malicious file placed there turns the file write primitive into native code execution when a normal compilation and start sequence is performed.
Potential impact
- Authenticated users may write arbitrary files to any location writable by the OpenPLC webserver process.
- Attackers could plant malicious C++ source files that are compiled into the runtime binary.
- Successful exploitation can lead to arbitrary native code execution under the privileges of the OpenPLC runtime.
- Runtime compromise may allow modification of PLC logic, unsafe system behavior, or further lateral movement within the control network.
- Attackers could overwrite configuration, logs, or auxiliary scripts, affecting availability and integrity of the control system.
General mitigation guidance
Effective mitigation focuses on restricting file-write behavior and decoupling uploaded content from sensitive build pipelines.
General defensive patterns include:
- Constraining all uploaded file paths to a single, fixed base directory and rejecting absolute paths or traversal components.
- Separating user-uploaded program files from the runtime core source tree so they are not automatically compiled into privileged binaries.
- Normalizing and validating filenames against an allowlist pattern (e.g., alphanumeric plus simple extensions) before storage and use.
- Using derived, server-side filenames (such as UUIDs) instead of trusting client-supplied names for filesystem operations.
- Running the webserver and build processes with least privilege and limiting write access only to directories explicitly needed for uploads and compilation.
- Applying defense-in-depth around build workflows, such as requiring explicit review or signed sources before inclusion in the runtime.
How teams detect issues like this
Detection commonly involves examining both application code and operational behavior:
- Static analysis or manual review for patterns where user-controlled filename or path values are persisted and later passed to file APIs (e.g.,
open,os.path.join,shutiloperations) without path validation. - Look for missing checks that enforce a canonical upload directory, absence of normalization, or acceptance of absolute paths.
- Review database schemas and usage patterns where fields like
Programs.Fileare derived directly from HTTP request parameters. - Implement runtime monitoring and logging of file writes, especially in critical directories such as the runtime core source tree and configuration paths, and alert when unexpected writes occur.
- Enforce policy checks in CI/CD or security gateways around build inputs, rejecting new source files created from unreviewed or user-upload directories.
- Automated security testing tools can be configured to fuzz upload endpoints with crafted filenames to surface path traversal and arbitrary write behavior.

