Summary
An unsafe BashOperator pattern in the Apache Airflow documentation showed how to pass dag_run.conf directly into shell commands, allowing unsanitized user-controlled data to reach the command line.
If DAG authors copied this example without sanitization or proper quoting, an attacker who can influence dag_run.conf may escalate the Airflow UI user's privileges and execute arbitrary code on workers.
Affected context
This issue affects Airflow deployments where:
- DAGs use
BashOperator(or similar shell-based operators), dag_run.confvalues or other user-controlled parameters are interpolated directly into shell commands,- and those commands are executed with the privileges of the Airflow UI user or worker service account.
The vulnerability arises only when DAG authors adopted the unsafe documentation pattern and did not apply their own validation, escaping, or strict parameterization.
Exploit preconditions
- Attack surface: Airflow entry points that allow setting or influencing
dag_run.conf(e.g., API-triggered DAG runs, UI-triggered DAG runs with configuration, or external systems that populate these fields). - Required access: Ability to trigger DAG runs with controlled
dag_run.confvalues, or to modify upstream systems that supply these values. - Trigger point: Execution of a BashOperator (or similar) where the DAG code concatenates or interpolates
dag_run.confdirectly into a shell command. - Why exploitation is possible: Shell metacharacters and additional commands embedded in
dag_run.confare interpreted by the shell when input is not properly quoted or sanitized, leading to command injection (CWE-77).
Why this happens
The root cause is an unsafe example in the documentation that effectively treats dag_run.conf as trusted input and directly concatenates it into shell commands executed by BashOperator.
This reflects the CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection'), where user-controlled data is passed to a shell without robust quoting, escaping, or strict allow-list validation.
By constructing commands through string interpolation rather than structured parameters or safe APIs, the pattern allows attackers to inject shell syntax, alter command behavior, and execute additional commands under the worker's privileges.
Potential impact
- Execution of arbitrary commands on worker nodes with the privileges of the Airflow worker or UI user.
- Escalation of logical privileges within the Airflow environment (e.g., ability to run commands beyond what the UI user is intended to do).
- Unauthorized access to data, credentials, or internal services reachable from the worker.
- Lateral movement within the infrastructure if workers have network access to other internal systems.
- Disruption of scheduled workflows, data pipelines, or downstream systems through malicious commands.
General mitigation guidance
Effective mitigation focuses on treating dag_run.conf and other runtime configuration as untrusted input and avoiding direct shell interpolation.
Recommended defensive patterns include:
- Avoiding direct command concatenation: Use parameterized, structured APIs (e.g., Python operators or libraries) instead of constructing shell commands when possible.
- Strict quoting and escaping: When shell commands are unavoidable, apply robust quoting so that user-provided values are treated as opaque strings rather than executable syntax.
- Input validation and allow-lists: Constrain
dag_run.conffields to a narrow set of expected values (e.g., enumerations, numeric ranges, or strongly-typed fields) and reject unexpected input early. - Separation of control and data: Design DAGs so that control flow and command templates are static, with user input only affecting non-sensitive parameters.
- Least privilege for workers: Run workers and UI components with minimal OS and network privileges, ensuring that even if a command is injected, its blast radius is limited.
- Secure-by-default guidance: Update internal examples and engineering guidelines to promote safe parameter handling in BashOperator and other shell-based tasks.
How teams detect issues like this
Organizations can identify and monitor this class of vulnerability through a combination of static analysis, review practices, and runtime controls:
- Static analysis and linters: Search for patterns where
dag_run.confor similarly user-controlled values are directly concatenated into shell command strings inBashOperator,SSHOperator, or custom shell wrappers. - Code review checklists: Include explicit review items for command construction in DAGs, requiring reviewers to verify proper quoting, validation, and separation of data from control.
- Policy-driven scanning: Implement repository scanning rules (e.g., grep-based or custom static rules) to flag usage of
{{ dag_run.conf[...] }}inside shell snippets without sanitization. - Runtime monitoring: Use logging and anomaly detection on worker nodes to flag unexpected shell commands, unusual arguments, or patterns indicative of command injection attempts.
- Automated security tooling: Integrate SAST and IaC security tools into CI pipelines to systematically identify command injection risks in Airflow DAG code and associated scripts.

