Summary
Apache Airflow 2 allows a DAG Author with existing elevated permissions to manipulate internal database entries related to log template history in a way that results in arbitrary code execution within the web-server context.
When a user later views historical task information, the web server may render attacker-controlled template data, enabling remote code execution on the server side.
Affected context
This vulnerability arises in Apache Airflow 2 deployments where:
- DAG Authors have direct or indirect influence over database content related to log template history,
- The log template history functionality is enabled, and
- Historical task information is rendered within the web UI by the web server.
It particularly affects environments where the Airflow web server trusts and processes template-related data from the database without sufficient isolation or validation. In such setups, changes in log template metadata can influence how server-side code paths are evaluated when historical logs are viewed.
Exploit preconditions
- Attack surface: Airflow web UI and backend processing of historical task log templates.
- Required access: A legitimate DAG Author role (or equivalent) with the ability to manipulate Airflow's database content related to log templates.
- Trigger point: A user, which may be the attacker or another operator, viewing historical task information/logs that reference the manipulated template entries.
- Why exploitation is possible: The web server processes template or log-related data from the database in a way that can lead to dynamic code evaluation. Because this data can be indirectly controlled by a DAG Author, crafted entries can cause server-side code execution when rendered.
Why this happens
The core issue is a code injection pattern where data sourced from the Airflow database is treated as trusted input during server-side rendering of log template history.
Instead of strictly treating template-related database fields as inert data, the implementation allows them to influence or form part of executable code paths or templated expressions in the web server. This reflects CWE-94: Improper Control of Generation of Code ('Code Injection'), where user-controllable content (via a privileged role) is incorporated into dynamically interpreted or evaluated constructs.
The vulnerability is not about basic text display; it stems from combining dynamic template logic with insufficient separation between "data" and "code," allowing an attacker with existing DAG Author privileges to craft database state that the web server later executes.
Potential impact
- Execution of arbitrary code in the Airflow web server process.
- Compromise of Airflow web UI session data and application secrets accessible from the web server.
- Modification, theft, or corruption of DAG definitions and operational metadata.
- Lateral movement inside the hosting environment, depending on web server permissions and network reach.
- Disruption of workflow orchestration, including tampering with logs and run histories.
General mitigation guidance
Effective mitigation focuses on eliminating dynamic code evaluation from template-related data flows and tightening privilege and trust boundaries:
- Treat all template-related entries from the database as untrusted data, ensuring they are never interpreted as executable code or dynamically evaluated expressions.
- Use a strict templating engine configuration that does not allow arbitrary code execution and isolates template logic from underlying runtime constructs.
- Separate "template configuration" from "template content," and ensure only predefined, static templates are used for log rendering where possible.
- Apply least-privilege principles to Airflow roles so operational accounts cannot modify internal structures in ways that affect server-side code paths.
- Introduce robust validation and sanitization for any database-backed configuration or metadata that influences server rendering logic, rejecting or neutralizing unsafe constructs instead of attempting to interpret them.
- Prefer secure-by-default feature flags: disable high-risk, dynamically interpreted features unless there is a clear operational need and compensating controls are in place.
How teams detect issues like this
High-level detection typically includes:
- Static analysis: Scan Airflow customizations, plugins, and extensions for patterns where database fields or user-controlled template values are passed into dynamic evaluation functions, dangerous Jinja features, or any API that compiles or executes code at runtime.
- Code review signals: Flag areas where:
- Log templates or history metadata are assembled into code strings or expressions,
- Database-backed configuration is used as part of template logic,
- The boundary between configuration data and executable template logic is unclear.
- Runtime monitoring: Track unusual modifications to log template–related tables or metadata, especially out-of-band changes that do not match normal DAG development workflows.
- Policy enforcement: Use CI/CD gates and organizational policies to prohibit the introduction of new features that perform runtime code generation from configuration or database content. Automated code review tools can assist by enforcing rules around dangerous evaluation or templating constructs.

