Summary
A documentation example for using XComs in Apache Airflow demonstrated an unsafe pattern that could let a UI user with permission to modify XCom values trigger arbitrary code execution on a worker.
While the example DAGs are not intended for production and UI users are generally highly trusted, copying this pattern into real workflows can create a hidden code injection risk.
Affected context
This issue arises in Airflow environments where:
- Example DAGs from the documentation are enabled, or
- Production DAGs have been implemented by copying the unsafe example_xcom pattern.
The vulnerable context involves tasks that:
- Read XCom values and interpret them as executable code or dynamically evaluated expressions, and
- Run in worker processes with permissions to access Airflow resources and potentially connected systems.
It does not affect Airflow core logic directly but rather any user pipelines that replicate the documented anti-pattern.
Exploit preconditions
- Attack surface: Airflow web UI or any interface that allows modification or injection of XCom values.
- Required access: Authenticated UI user or operator role with permissions to view and edit XComs or otherwise control their content.
- Trigger point: A task that consumes an XCom value using an evaluation mechanism (e.g., dynamic execution of the XCom content) during DAG run on a worker.
- Why exploitation is possible: The example pattern treats XCom contents as trusted executable input instead of as plain data, allowing an attacker with XCom write access to craft values that are interpreted as code.
Why this happens
The underlying issue reflects CWE-94: Improper Control of Generation of Code ('Code Injection').
The documentation example showed how to pull data from XCom and then process it in a way that effectively executed or dynamically evaluated the retrieved value.
XComs are a general-purpose data channel and may be modified by privileged UI users or automation, but the example implicitly trusted the XCom payload as safe code rather than untrusted data.
This conflation of data and executable logic is the core insecure pattern, and reproducing it in user DAGs embeds a code injection sink into worker tasks.
Potential impact
- Arbitrary code execution within Airflow worker processes using malicious XCom payloads.
- Unauthorized access to data sources and sinks reachable by the compromised worker.
- Lateral movement inside the Airflow deployment or broader infrastructure, depending on worker permissions.
- Data exfiltration, tampering with workflow outputs, or manipulation of task behavior.
- Abuse of the worker environment to run unintended compute workloads.
General mitigation guidance
Mitigation should focus on treating XCom values as untrusted data and eliminating dynamic code execution based on their content.
Common defensive patterns include:
- Avoiding
eval, dynamic import, or any direct execution of strings or serialized structures pulled from XCom. - Designing tasks so that XComs carry parameters or data only, with code paths defined statically in the DAG or operator configuration.
- Constraining acceptable XCom formats (e.g., JSON, typed objects) and validating them before use.
- Applying least-privilege principles to worker environments so that, if misuse occurs, the blast radius is limited.
- Encouraging documentation and internal guidelines that explicitly forbid dynamic execution patterns based on runtime XCom content.
How teams detect issues like this
Detection efforts can focus on identifying code patterns where XCom values influence executable code paths:
- Static analysis rules that flag usage of
eval,exec, dynamic imports, or template rendering where the source isxcom_pullor similar APIs. - Code review practices that scrutinize any logic bridging XCom content and dynamic execution or reflection features.
- Policy checks in CI/CD pipelines that fail builds when known dangerous constructs are combined with XCom access.
- Periodic review of DAG repositories to find legacy examples copied from documentation that treat XCom data as code rather than as pure data.

