GHSA-33P4-W7J3-33MW
Langflow 1.0.16 - 1.11.6: unsafe eval() on Tool-Mode input options in schema.py
CVSS:4.0/AV:N/AC:H/AT:P/PR:H/UI:N/VC:L/VI:L/VA:L/SC:N/SI:N/SA:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Remediación | Parche 1.12.0 | langflow · -27 d desde divulgación | |
| Divulgación | Publicada | GHSA-33P4-W7J3-33MW divulgada · CVSS 2.1 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
From Langflow 1.0.16 through 1.11.6, `create_input_schema()` and `create_input_schema_from_dict()` in `schema.py` built a `typing.Literal` type for inputs with an `options` list (for example `DropdownInput`) by interpolating the list into a string and passing it to `eval()`:
literal_string = f"Literal{input_model.options}"
field_type = eval(literal_string, {"Literal": Literal}) # noqa: S307The sink runs whenever a component is converted into a LangChain tool (`ComponentToolkit.get_tools()`), for example when a custom component with `tool_mode=True` is saved through Check & Save (`POST /api/v1/custom_component`), or when a Tool-Mode component or flow-as-tool is built.
This was fixed in Langflow 1.12.0 by #14502 https://github.com/langflow-ai/langflow/pull/14502, which replaces `eval()` with `Literal[tuple(options)]`.
Affected versions
| Package (PyPI) | Vulnerable | Patched |
|---|---|---|
| `langflow` | `>= 1.0.16, < 1.12.0` | `1.12.0` |
| `langflow-base` | `>= 0.0.94, < 1.12.0` | `1.12.0` |
| `lfx` | `< 1.12.0` (all releases before 1.12.0) | `1.12.0` |
- Introduced by #3411
https://github.com/langflow-ai/langflow/pull/3411(commit `868933351c`, "feat: add function to create input schema from component inputs"), first shipped in `langflow 1.0.16` / `langflow-base 0.0.94` (`src/backend/base/langflow/io/schema.py`). - The code moved to `src/lfx/src/lfx/io/schema.py` when the `lfx` package was introduced. Both call sites (`create_input_schema` and `create_input_schema_from_dict`) were present in every release up to and including `1.11.6`.
- The original report stated "<= 1.7.0". The `eval()` sink was actually present until 1.12.0.
Details
Call path (as reported)
- `POST /api/v1/custom_component` (`src/backend/base/langflow/api/v1/endpoints.py`) builds the frontend node and calls `Component.run_and_validate_update_outputs(field_name="tool_mode", ...)`.
- When `tool_mode` is true, `run_and_validate_update_outputs()` calls `_build_tools_metadata_input()` (`src/lfx/src/lfx/custom/custom_component/component.py`).
- `_build_tools_metadata_input()` calls `_get_tools()`, which calls `ComponentToolkit(component=self).get_tools(...)` (`src/lfx/src/lfx/base/tools/component_tool.py`).
- `get_tools()` calls `create_input_schema(tool_mode_inputs)`, or `create_input_schema_from_dict(flow_mode_inputs)` for flow-as-tool.
- In `src/lfx/src/lfx/io/schema.py`, both functions evaluate `f"Literal{input_model.options}"` with `eval()`.
Exploitability analysis (maintainers)
The string passed to `eval()` is built from `repr()` of each element of `options`. That affects who can exploit it:
- Data-only input is not exploitable. When `options` come from JSON (flow import, template edits, the API), every element is a `str`, `int`, `float`, `bool`, `None`, `list` or `dict`. Their `repr()` is always a well-formed, escaped Python literal, so an attacker who controls only data cannot break out of the literal. We fuzzed the old sink with more than 20,000 JSON-derived strings built from quotes, backslashes, parentheses, `#`, newlines and `__import__(...)` payloads. None executed code and every value round-tripped unchanged. The only non-literal case is `Infinity`/`inf`, which raises `NameError` (schema build fails, nothing executes).
- Code execution requires a Python object with a malicious `__repr__`. Placing such an object in `options` requires authoring component code, and a user who can author component code can already run arbitrary Python on the server, because custom components are executable Python by design.
- The PoC below runs its payload before `eval()`. In `options = [(__import__('os').system('touch /tmp/weblover'), 'OK')[1], "HACKED"]`, the `os.system` call runs when the component class body is executed during Check & Save. By the time the list reaches `create_input_schema()`, it is already `['OK', 'HACKED']` and `eval()` is harmless. The same file would be created without any Tool-Mode or `options` involvement.
In practice, the `eval()` call did not give an attacker any capability they did not already have through custom component code. It was still an unsafe `eval()` on values that flow through the component system (CWE-95), and removing it is defense in depth. Severity is set to Low accordingly.
Operators who need to stop untrusted users from running Python on the server should keep `LANGFLOW_ALLOW_CUSTOM_COMPONENTS=false`, grant code-editing rights only to trusted users, and isolate the Langflow process (container, least-privilege service account). This applies regardless of this issue.
PoC (original report)
We used the default Simple Agent flow. (Only components exposed by the tool set are eligible for RCE.)
Add the following to inputs that use `options` (e.g., DropdownInput) in the URL or Calculator tool.
options = [(__import__('os').system('touch /tmp/weblover'), 'OK')[1], "HACKED"]When the Check & Save button is clicked, an arbitrary file is created locally.
> Maintainer note: see "Exploitability analysis" above. The command runs when the component code is executed, before `eval()`. A PoC that reaches code execution specifically through the `eval()` sink requires an `options` element whose `__repr__` returns Python code, for example:
>
> ```python
> class R:
> def __repr__(self):
> return "__import__('os').system('touch /tmp/poc') and 'x'"
>
> options = [R()]
> ```
Fix
Fixed in Langflow 1.12.0 by #14502 https://github.com/langflow-ai/langflow/pull/14502 ("fix(security): replace eval() with safe Literal construction in schema.py", merge commit `ab5d776fbb9bd425228873b42e5b6a0dccfbc253`). The two `eval()` calls are replaced with direct `Literal` subscription, which never evaluates strings:
--- a/src/lfx/src/lfx/io/schema.py
+++ b/src/lfx/src/lfx/io/schema.py
@@ def create_input_schema(inputs: list["InputTypes"]) -> type[BaseModel]:
and len(input_model.options) <= MAX_OPTIONS_FOR_TOOL_ENUM
):
- literal_string = f"Literal{input_model.options}"
- field_type = eval(literal_string, {"Literal": Literal}) # noqa: S307
+ field_type = Literal[tuple(input_model.options)]
@@ def create_input_schema_from_dict(inputs: list[dotdict], param_key: str | None = None) -> type[BaseModel]:
and len(input_model.options) <= MAX_OPTIONS_FOR_TOOL_ENUM
):
- literal_string = f"Literal{input_model.options}"
- field_type = eval(literal_string, {"Literal": Literal}) # noqa: S307
+ field_type = Literal[tuple(input_model.options)]Regression tests were added in `src/lfx/tests/unit/schema/test_input_schema.py`.
Remediation
- Upgrade to `langflow >= 1.12.0` (or `langflow-base >= 1.12.0` / `lfx >= 1.12.0`).
- Independently of this issue, only grant custom-component and code-editing rights to trusted users, and set `LANGFLOW_ALLOW_CUSTOM_COMPONENTS=false` on deployments where users must not run arbitrary Python.
References
- Fix: https://github.com/langflow-ai/langflow/pull/14502
- Introducing change: https://github.com/langflow-ai/langflow/pull/3411
- CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection')
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
pypilangflow |
Corregida | 1.12.0 | -27 d | 1.13.2 no afectada |
pypilangflow-base |
Corregida | 1.12.0 | -27 d | 1.13.2 no afectada |
pypilfx |
Corregida | 1.12.0 | -27 d | 1.13.2 no afectada |
1.12.0Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/langflow-ai/langflow/security/advisories/GHSA-33p4-w7j3-33mwLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
