VYPR
Moderate severityNVD Advisory· Published Aug 23, 2022· Updated Aug 3, 2024

CVE-2021-3701

CVE-2021-3701

Description

A flaw was found in ansible-runner where the default temporary files configuration in ansible-2.0.0 are written to world R/W locations. This flaw allows an attacker to pre-create the directory, resulting in reading private information or forcing ansible-runner to write files as the legitimate user in a place they did not expect. The highest threat from this vulnerability is to confidentiality and integrity.

AI Insight

LLM-synthesized narrative grounded in this CVE's description and references.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
ansible-runnerPyPI
>= 2.0.0, < 2.1.02.1.0

Affected products

2

Patches

Vulnerability mechanics

Root cause

"Predictable temporary directory path and a TOCTOU race condition allow an attacker to pre-create the directory before ansible-runner uses it."

Attack vector

An attacker with local access to the system can exploit the predictable temporary directory path (`.ansible-runner` in the system temp directory) or the race between deletion and reuse of a `TemporaryDirectory` name. By pre-creating the directory with world-writable permissions before ansible-runner uses it, the attacker can cause ansible-runner to write files into an attacker-controlled location, potentially reading private information or forcing writes as the legitimate user. This is a TOCTOU race condition combined with incorrect default permissions [CWE-276].

Affected code

The vulnerability is in `ansible_runner/config/_base.py` and `ansible_runner/streaming.py`. In `_base.py`, when no `private_data_dir` is provided, the code used `os.path.join(gettempdir(), ".ansible-runner")` — a fixed, predictable path — and then called `os.makedirs(..., exist_ok=True, mode=0o700)` on it. In `streaming.py`, the code used `tempfile.TemporaryDirectory().name` which creates a tempdir, immediately exposes its name, and then deletes it, allowing an attacker to pre-create a directory with that same name.

What the fix does

The patch replaces the fixed path `os.path.join(gettempdir(), ".ansible-runner")` with `tempfile.mkdtemp(prefix=".ansible-runner-")`, which creates a uniquely-named temporary directory atomically, eliminating the predictability that enabled the race. In `streaming.py`, `tempfile.TemporaryDirectory().name` is replaced with `tempfile.mkdtemp()`, avoiding the delete-then-recreate window. Additionally, `os.makedirs(self.private_data_dir, exist_ok=True, mode=0o700)` is moved inside the `if private_data_dir:` branch so it only runs when the user explicitly provides a path, not on the auto-generated one.

Preconditions

  • authAttacker must have local access to the system where ansible-runner runs
  • inputAttacker must be able to create directories in the system temporary directory

Generated on Jun 20, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

8

News mentions

0

No linked articles in our index yet.