Summary
The Flow Import endpoint in eosphoros-ai db-gpt 0.7.5 unsafely loads user-supplied files using Python's dynamic import machinery, enabling arbitrary code execution.
When an attacker can remotely supply or influence a flow file that is imported through importlib.machinery.SourceFileLoader.exec_module, they may inject and run arbitrary code on the server.
Affected context
This vulnerability occurs in the Flow Import endpoint of db-gpt 0.7.5, where "flow" definitions are uploaded or referenced and then imported as executable Python modules.
It is relevant in deployments where:
- Users can upload or provide paths/URLs to flow files, and
- Those files are loaded via
SourceFileLoader.exec_modulewithout strict validation or isolation.
The risk is highest when the server is internet-accessible or exposed to untrusted or semi-trusted users.
Exploit preconditions
- Attack surface: HTTP(S) API exposed by the Flow Import endpoint (
/api/v1/serve/awel/flow/import). - Required access: Ability to invoke the flow import functionality and supply or control the imported file (e.g., uploaded file, file path, or repository content).
- Trigger point: The server calls
importlib.machinery.SourceFileLoader.exec_moduleon attacker-controlled source content. - Why exploitation is possible: The application treats flow files as trusted Python source, performing dynamic execution without robust validation, sandboxing, or strict separation between configuration and code.
Why this happens
The flaw stems from treating user-supplied or externally controlled flow definitions as executable Python modules.
By calling SourceFileLoader.exec_module on files derived from untrusted input, the application directly evaluates attacker-controlled code within the server's process.
This maps to:
- CWE-94: Improper Control of Generation of Code, because user-controllable input is incorporated into executable code without sufficient constraints.
- CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component, as the downstream component (Python interpreter/import system) executes content that was not neutralized or constrained to a safe subset.
Conceptually, the design conflates data (flow description) with code (Python source), leading to an unsafe dynamic execution pattern.
Potential impact
- Execution of arbitrary Python code with the privileges of the db-gpt service account.
- Reading or modification of application data, model configurations, and flow definitions.
- Lateral movement to other internal systems reachable from the compromised server.
- Deployment of backdoors, cryptominers, or additional malicious services on the host.
- Full compromise of the underlying OS account and potential privilege escalation depending on local configuration.
General mitigation guidance
Effective mitigation focuses on eliminating or strictly controlling dynamic execution of user-influenced code and separating configuration from executable logic:
- Prefer a declarative flow format (e.g., structured YAML/JSON schemas) instead of importing arbitrary Python files.
- If dynamic behavior is needed, restrict it to a curated set of safe operations or plugins loaded from a trusted, administrator-managed directory only.
- Enforce strict validation and schema checking on imported flow definitions so only data structures (not raw code) are processed.
- Use sandboxing or process isolation (e.g., separate, locked-down worker processes or containers) for any unavoidable execution of potentially unsafe logic, with minimal filesystem and network privileges.
- Apply principle of least privilege to the db-gpt runtime account, limiting file system access, environment secrets, and outbound network capabilities to reduce blast radius.
- Introduce approval workflows or restricted roles for flow import operations so that untrusted users cannot directly provide executable content.
How teams detect issues like this
Organizations can identify and monitor this pattern using a combination of static and operational techniques:
- Static analysis and SAST rules to flag uses of
importlib.machinery.SourceFileLoader,exec_module,exec,eval, or similar dynamic-import patterns where inputs can be traced to HTTP request parameters or user-uploaded files. - Code review checklists that explicitly ask reviewers to locate any dynamic code loading or execution and verify that only trusted, controlled inputs are used.
- Configuration and policy enforcement that disallows runtime imports from user-writable directories or paths influenced by client data.
- Runtime monitoring and logging of flow imports, including file origin, caller identity, and anomalies such as imports from unexpected locations.
- Optional use of automated code review tools or custom linters to detect and gate unsafe dynamic execution patterns in CI/CD pipelines before deployment.

