Summary
EPyT-Flow's REST API and JSON file loader use a custom deserializer that dynamically imports and instantiates classes based on attacker-controlled JSON fields.
If an attacker can send crafted JSON requests or supply malicious JSON files, they may trigger arbitrary class instantiation (e.g., subprocess.Popen) and achieve OS command execution during JSON parsing.
Affected context
This vulnerability occurs in EPyT-Flow deployments that:
- Expose the EPyT-Flow REST API to network clients, or
- Load scenario or configuration data from JSON files that may be influenced by external parties
The risk is present when:
- JSON request bodies or files are parsed using the custom
my_load_from_jsondeserializer, and - The JSON includes a
typefield that the application does not strictly constrain to a safe allowlist.
Exploit preconditions
- Attack surface: EPyT-Flow REST API endpoints and any code paths that load JSON files via
my_load_from_json. - Required access: Ability to send HTTP requests with crafted JSON bodies, or to provide JSON files that the application will load.
- Trigger point: Invocation of
my_load_from_jsonon attacker-controlled JSON containing atypefield referencing a dangerous or unexpected class. - Why exploitation is possible: The deserializer trusts the
typefield, dynamically imports modules/classes based on attacker input, and instantiates them with attacker-controlled arguments, enabling execution of side-effectful constructors such assubprocess.Popen.
Why this happens
The core issue is EPyT-Flow's use of a custom JSON deserializer that treats untrusted input as instructions for object construction.
The my_load_from_json function interprets a user-controlled type field as a directive to dynamically import and instantiate arbitrary classes, effectively turning data into code.
This maps directly to CWE-502: Unsafe Deserialization, where serialized data is deserialized into live objects without sufficient validation, allowing attackers to trigger code execution via constructors or special methods during the deserialization process.
Potential impact
- Execution of arbitrary OS commands under the privileges of the EPyT-Flow process
- Full compromise of the host running EPyT-Flow, depending on its permissions and environment
- Manipulation or destruction of hydraulic and water quality scenario data
- Unauthorized access to sensitive configuration, credentials, or datasets used by EPyT-Flow
- Use of the compromised server as a pivot point for further attacks within the network
General mitigation guidance
Effective mitigation centers on eliminating data-driven object construction and tightening trust boundaries around JSON input.
Common defensive patterns include:
- Treating JSON strictly as data: parse into primitive types and explicit data-transfer objects rather than arbitrary classes.
- Removing or disabling any generic
type-based instantiation logic for untrusted input. - If polymorphic behavior is required, using a strict allowlist of known-safe types and mapping them explicitly rather than via dynamic imports.
- Separating configuration and runtime code so that configuration files cannot cause code execution when loaded.
- Running EPyT-Flow with least-privilege OS accounts and, where possible, within sandboxed or containerized environments to limit blast radius.
How teams detect issues like this
Organizations can detect similar unsafe deserialization patterns by:
- Static analysis rules that flag:
- Dynamic imports based on user-controlled strings
- Constructors or factory functions invoked with unvalidated data
- Custom deserialization functions that interpret
typeor similar fields to select classes - Code review checklists that call out:
- Any custom JSON/YAML/XML loader functions
- Use of reflection or
importlibin request/JSON parsing code paths - Security linters or automated review tools configured to:
- Identify usages of dangerous APIs (e.g.,
subprocess.Popen, OS command execution) reachable from input-handling code - Enforce policies that forbid data-driven class loading from external inputs

