CVE-2022-40127: RCE in Apache Airflow <2.4.0 bash example
An example DAG shipped with Apache Airflow passed the user-supplied run_id value straight into a shell command without escaping it. Anyone with UI access who could trigger DAGs could therefore run arbitrary operating system commands on the Airflow host.
- Triaged in 16 days
- Fixed in 49 days
- Paid in 49 days
- Disclosed after 49 days
Summary by the program
###Description:
A vulnerability in Example Dags of Apache Airflow allows an attacker with UI access who can trigger DAGs, to execute arbitrary commands via manually provided run_id parameter. This issue affects Apache Airflow Apache Airflow versions prior to 2.4.0.
###Mitigation:
Do not enable example dags on systems that should not allow UI user to execute an arbitrary command.
###References:
https://github.com/apache/airflow/pull/25960
The report
airflow-2.3.3/airflow/example_dags/example_bash_operator.py has a command injection vulnerability. I can control the run_id in the following code(example_bash_operator.py),So I can inject custom commands.
also_run_this = BashOperator(
task_id='also_run_this',
bash_command='echo "run_id={{ run_id }} | dag_run={{ dag_run }}"',
)
Enter the DAGs menu and start example_bash_operator task, select “Trigger DAG w/ config”.Set the run_id to " touch /tmp/success " and trigger.

Impact
Execute any OS command
Context
Apache Airflow is a workflow scheduler in which DAGs (directed acyclic graphs) define tasks and their dependencies. Airflow ships with a set of example DAGs that demonstrate operators, and these examples are enabled by default in the versions concerned. One of them, example_bash_operator.py, uses the BashOperator to run shell commands.
The vulnerability described here is CVE-2022-40127. It affects Apache Airflow versions prior to 2.4.0 and allows a user with UI access who can trigger DAGs to execute arbitrary commands through a manually supplied run_id parameter. The report was filed against the apache/airflow repository on the Internet Bug Bounty programme, rated high severity with a CVSS score of 8.8 (Code Injection), and paid a bounty of 4,000 USD. It was disclosed on 5 January 2023.
Setup
The researcher worked against Airflow 2.3.3. The precondition is an account with UI access that is permitted to trigger DAGs, plus example DAGs being enabled, which is the default state. No special tooling is described beyond the Airflow web interface.
Finding it
The researcher looked at airflow-2.3.3/airflow/example_dags/example_bash_operator.py and identified a command injection vulnerability in it. The relevant task is:
also_run_this = BashOperator(
task_id='also_run_this',
bash_command='echo "run_id={{ run_id }} | dag_run={{ dag_run }}"',
)
The bash_command string is a Jinja template. The {{ run_id }} expression is rendered into the command before the shell runs it, and the run_id value is supplied by whoever triggers the DAG. Because the rendered value is placed inside a shell command, the researcher could control the run_id and therefore inject custom commands.
Exploitation
Step 1: open the DAG and choose the trigger option
Enter the DAGs menu and start the example_bash_operator task. Select "Trigger DAG w/ config", which lets the user supply configuration for the run, including the run_id.
Step 2: set the run_id payload
Set the run_id to the following value and trigger the DAG:
`touch /tmp/success`
The value is wrapped in backticks, which the shell evaluates as command substitution. When the template is rendered into the bash_command and executed, the backticked touch /tmp/success runs as a separate command, creating the file /tmp/success as proof of execution.

The screenshot shows the trigger dialog with the crafted run_id entered before the DAG is triggered.
Root cause
The example DAG interpolates the user-controlled run_id directly into a shell command string. Jinja rendering happens before the shell sees the command, so any shell metacharacters in run_id (here backticks) are interpreted by the shell rather than treated as data. The value is never quoted or escaped for the shell context, and the example DAGs are enabled by default, so the vulnerable task is reachable out of the box. The report does not describe any additional defence that was in place.
Impact
The researcher states the impact as the ability to execute any OS command. The condition is an attacker with UI access who can trigger DAGs, on an instance where example DAGs are enabled. The program's summary frames it the same way: an attacker with UI access who can trigger DAGs can execute arbitrary commands via a manually provided run_id parameter.
Fix
The issue affects Apache Airflow versions prior to 2.4.0. The program's mitigation guidance is not to enable example DAGs on systems that should not allow a UI user to execute an arbitrary command. The referenced change is the pull request at https://github.com/apache/airflow/pull/25960.
Variants to test
- Other example DAGs that interpolate run parameters into
BashOperatorcommands. A positive result is a rendered command in which a crafted parameter value is evaluated by the shell, for example by creating a file or producing observable output. - Other template fields passed into shell commands, such as
dag_runin the same task. A positive result is command substitution or chaining taking effect when the field is set through the trigger configuration. - Instances where example DAGs are enabled but the user is not an admin. A positive result is a non-admin user with trigger permission obtaining command execution.
Hunting notes
This class of bug hides in example and demo content that ships enabled by default, and in any operator that builds a shell command from templated, user-supplied values. During recon, look for default-enabled sample DAGs, tasks using BashOperator with Jinja expressions, and trigger interfaces that accept a run_id or config. The researcher demonstrated impact by setting run_id to a backticked touch /tmp/success and triggering the DAG.
What happened, in plain words
Apache Airflow is a piece of software that runs scheduled jobs. You describe the jobs as a set of steps, and Airflow runs them in the right order, on a schedule or when you ask it to. The description of the steps is called a DAG, short for directed acyclic graph: a chain of tasks where each task can depend on the ones before it, and nothing loops back on itself.
Airflow comes with a collection of ready-made example DAGs so that new users can see how it works. In the versions involved here, those examples are switched on by default. One of them, example_bash_operator.py, runs shell commands. A shell command is a line of text you would type into a terminal to make the computer do something.
The bug is that this example takes a value supplied by the person starting the job, called run_id, and pastes it straight into a shell command without cleaning it. If that value contains characters the shell treats as instructions, the shell obeys them. The result is that anyone who can log into the Airflow web interface and start a DAG can run any command they like on the server.
The bug is tracked as CVE-2022-40127. A CVE is a public catalogue number given to a known security flaw so people can refer to it unambiguously. It affects Airflow versions before 2.4.0. The report was filed against the apache/airflow repository on the Internet Bug Bounty programme, rated high severity with a CVSS score of 8.8 in the Code Injection category, and paid a bounty of 4,000 USD. CVSS is a standard scoring system for how serious a vulnerability is. It was disclosed on 5 January 2023.
Context
Airflow is a workflow scheduler. Think of it as a kitchen manager: you hand it a list of dishes to prepare and the order they depend on each other, and it makes sure each one is cooked at the right time. In Airflow the list is a DAG, and each dish is a task. Tasks are run by small pieces of code called operators, each specialised for a kind of work. The BashOperator is the operator that runs shell commands.
The vulnerability class here is command injection. Injection means that data you supply is treated as instructions instead of being kept as plain data. An everyday comparison: a form asks for your name and you write "Robert'); drop the table" and the system runs the second half as a database command. The same idea applies to shells: if your input ends up inside a command line, characters like backticks or semicolons can turn your input into extra commands.
Setup
The researcher worked against Airflow 2.3.3. Two things had to be true for the attack to work: an account with access to the web interface that is allowed to trigger DAGs, and example DAGs being enabled, which is the default state. No special tooling is described beyond the Airflow web interface itself. The web interface is the pages you open in a browser to see and manage DAGs.
Finding it
The researcher opened the file airflow-2.3.3/airflow/example_dags/example_bash_operator.py and found a command injection vulnerability in it. The relevant task is:
also_run_this = BashOperator(
task_id='also_run_this',
bash_command='echo "run_id={{ run_id }} | dag_run={{ dag_run }}"',
)
Line by line:
also_run_this = BashOperator(creates a task namedalso_run_thisusing theBashOperator, the operator that runs a shell command.task_id='also_run_this',gives the task its internal name, which is how Airflow refers to it.bash_command='echo "run_id={{ run_id }} | dag_run={{ dag_run }}"',is the command that will be run.echosimply prints text. The parts in double curly braces,{{ run_id }}and{{ dag_run }}, are placeholders. Airflow fills them in before the command runs, using a templating language called Jinja. Jinja is a way of writing text with blanks that get filled from data.)closes the task definition.
The important point is that run_id is a value supplied by whoever triggers the DAG. It is filled into the command text, and then the shell runs the whole thing. Because the filled-in value sits inside a shell command, the researcher could control run_id and therefore inject extra commands.
Exploitation
Step 1: open the DAG and choose the trigger option
Go to the DAGs menu and start the example_bash_operator task. Choose "Trigger DAG w/ config". This option lets the person starting the run supply configuration for it, including the run_id. The reason to pick this option is that it is the door through which the attacker's value reaches the vulnerable template.
Step 2: set the run_id payload
Set the run_id to the following value and trigger the DAG:
`touch /tmp/success`
What this does:
- The backtick character,
`, tells the shell: run whatever is between the backticks first, and put its output in place of the backticks. This is called command substitution. An everyday comparison: writing "today isdate" on a form and having the system replacedatewith the actual date before reading the sentence. touch /tmp/successis the command inside the backticks.touchcreates an empty file if it does not exist./tmp/successis the path of that file./tmpis a temporary folder on Linux systems.- So when the template is filled into
bash_commandand the shell runs it, the backtickedtouch /tmp/successruns as a separate command, creating the file/tmp/successas proof that the attacker's command executed.

The screenshot shows the trigger dialog with the crafted run_id entered, just before the DAG is triggered.
Root cause
The example DAG puts the user-controlled run_id directly into a shell command string. Jinja fills in the value before the shell ever sees the command, so any shell special characters in run_id, here backticks, are interpreted by the shell rather than treated as harmless text. The value is never quoted or escaped for the shell context. Quoting or escaping means wrapping a value so the shell treats it purely as text. On top of that, the example DAGs are enabled by default, so the vulnerable task is reachable out of the box. The report does not describe any additional defence that was in place.
Impact
The researcher states the impact as the ability to execute any OS command. OS means operating system, the underlying software that runs the machine. The condition is an attacker with web interface access who can trigger DAGs, on an instance where example DAGs are enabled. The programme's summary frames it the same way: an attacker with UI access who can trigger DAGs can execute arbitrary commands via a manually provided run_id parameter.
Fix
The issue affects Apache Airflow versions before 2.4.0. The programme's mitigation guidance is not to enable example DAGs on systems that should not allow a web interface user to execute an arbitrary command. The referenced change is the pull request at https://github.com/apache/airflow/pull/25960. A pull request is a proposed change to a code repository that maintainers review and merge.
Variants to test
- Other example DAGs that put run parameters into
BashOperatorcommands. A positive result is a rendered command in which a crafted parameter value is evaluated by the shell, for example by creating a file or producing observable output. - Other template fields passed into shell commands, such as
dag_runin the same task. A positive result is command substitution or chaining taking effect when the field is set through the trigger configuration. - Instances where example DAGs are enabled but the user is not an admin. A positive result is a non-admin user with trigger permission obtaining command execution.
Hunting notes
This class of bug hides in example and demo content that ships enabled by default, and in any operator that builds a shell command from templated, user-supplied values. During recon, meaning the early phase of looking around a target, look for default-enabled sample DAGs, tasks using BashOperator with Jinja expressions, and trigger interfaces that accept a run_id or config. The researcher demonstrated impact by setting run_id to a backticked touch /tmp/success and triggering the DAG. A reverse shell is a technique where the target machine connects back to the attacker and gives them an interactive command line.
Glossary
- Apache Airflow: software that schedules and runs chains of tasks, called workflows.
- DAG: directed acyclic graph, Airflow's description of a set of tasks and the order they depend on each other, with no loops.
- Task: one step inside a DAG.
- Operator: the piece of code that performs a task, such as
BashOperatorfor shell commands. - BashOperator: the Airflow operator that runs a shell command.
- Shell: the program that reads and executes typed commands on a computer.
- Command injection: a flaw where user-supplied data is treated as instructions by a shell or similar interpreter.
- Jinja: a templating language that fills placeholders in text with values.
- Template: text containing placeholders that get replaced with data before use.
- run_id: the identifier of a particular run of a DAG, supplied when the run is triggered.
- Backtick: the
`character, which tells the shell to run the enclosed command and substitute its output. - Command substitution: the shell feature where a command inside backticks is run and its output replaces the backticks.
- touch: a shell command that creates an empty file or updates a file's timestamp.
- CVE: a public catalogue number for a known security vulnerability.
- CVSS: a standard scoring system for the severity of a vulnerability.
- Code Injection: a vulnerability category where attacker input is executed as code.
- UI: user interface, the pages and controls you use in a browser.
- Web interface: the browser-based pages for managing Airflow.
- Instance: one running installation of the software.
- OS: operating system, the software that runs the machine.
- Escaping: transforming a value so special characters are treated as plain text.
- Quoting: wrapping a value so the shell treats it as a single piece of text.
- Pull request: a proposed change to a code repository that maintainers review and merge.
- Recon: the early phase of exploring a target to find things worth testing.
- Reverse shell: a technique where the target machine connects back to the attacker and gives them an interactive command line.
- Payload: the crafted input used to trigger a vulnerability.