Summary
OpenPLC Runtime v3 contains a path traversal flaw in the Structured Text compilation workflow. An attacker who can upload a crafted .st program may cause attacker-controlled content to be written outside the intended ./core directory, potentially enabling remote code execution through writable operating-system-managed files.
Affected context
The vulnerability occurs in the OpenPLC webserver's compile_program() function when uploaded Structured Text files contain special file-writing directives. The referenced path is joined with ./core without confirming that the resulting location remains within that directory. Exploitability depends on access to the program-upload workflow and on the runtime account having permission to write to a security-sensitive filesystem location. Default credentials may reduce the barrier where they remain enabled.
Exploit preconditions
- Attack surface: OpenPLC webserver program-upload and compilation workflow
- Required access: Ability to authenticate to, or otherwise reach, the upload functionality; shipped default credentials may make access easier if unchanged
- Trigger point: Processing of a file-writing directive during
compile_program() - Why exploitation is possible: The supplied path is used in a filesystem write without containment validation, allowing traversal outside the intended
./coredirectory - Additional condition: The OpenPLC process must have write permission for the selected target path or for a file that influences later execution
Why this happens
The underlying bug is failure to enforce a trusted path boundary before writing attacker-influenced content. compile_program() combines a user-controlled path with the intended base directory but does not canonicalize and verify that the resulting path remains beneath that directory. This is a path traversal weakness mapped to CWE-22, and it can become an arbitrary file-write or code-execution issue when the process has access to executable, scheduled-task, authentication, or other security-sensitive files. Although a path-validation helper exists elsewhere in the codebase, the vulnerable write path does not invoke it.
Potential impact
- An attacker may write arbitrary content to files outside the intended application directory.
- The OpenPLC process may be compromised through files that are later executed or interpreted.
- System integrity, scheduled tasks, or service configuration may be altered.
- Credentials, access controls, or authorized access mechanisms could be affected.
- The host or connected industrial environment could be exposed to further compromise.
General mitigation guidance
Mitigation generally focuses on enforcing a strict destination boundary for every file-writing operation.
Common defensive patterns include:
- Resolve and canonicalize the candidate path before writing, then require it to remain beneath a fixed, trusted base directory.
- Reuse a centralized path-validation function consistently at the actual filesystem sink.
- Prefer application-managed filenames or opaque identifiers over user-supplied paths.
- Reject absolute paths, traversal components, symbolic-link escapes, and unexpected path formats.
- Restrict the runtime account to the minimum filesystem permissions required for operation.
- Disable or rotate shipped default credentials and require unique, strong authentication secrets.
- Store uploaded files in an isolated, non-executable location and apply restrictive filesystem and container policies.
How teams detect issues like this
Detection can combine source analysis, runtime monitoring, and deployment policy checks:
- Use static analysis to identify filesystem writes that combine a trusted directory with request-derived or uploaded path components.
- Review code for canonicalization, containment checks, symbolic-link handling, and validation immediately before the write sink.
- Monitor OpenPLC processes for writes outside approved application directories and for unexpected changes to system-managed files.
- Add CI policy checks that reject default credentials and unvalidated path construction in upload handlers.
- Test upload and compilation workflows with traversal-oriented path variations in controlled security testing.
- Neutral automated code-review tools may help identify inconsistent use of existing validation helpers.

