Skip to content

Commit

Permalink
Close a race condition with temporary files
Browse files Browse the repository at this point in the history
The previous code allowed a race where an attacker could watch for
creation of a rapid creation and deletion of a temporary directory,
substitute their own directory at that name, and then have access to
ansible-runner's private_data_dir the next time ansible-runner made
ues of the private_data_dir.

This code fixes the issue by creating the directory securely using
mkdtemp() and not deleting it afterwards.
  • Loading branch information
abadger committed Jun 28, 2021
1 parent cd6b999 commit 766fb5f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ansible_runner/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self, _input=None, _output=None, **kwargs):

private_data_dir = kwargs.get('private_data_dir')
if private_data_dir is None:
private_data_dir = tempfile.TemporaryDirectory().name
private_data_dir = tempfile.mkdtemp()
self.private_data_dir = private_data_dir

self.status = "unstarted"
Expand Down Expand Up @@ -164,7 +164,7 @@ def __init__(self, _input=None, status_handler=None, event_handler=None,

private_data_dir = kwargs.get('private_data_dir')
if private_data_dir is None:
private_data_dir = tempfile.TemporaryDirectory().name
private_data_dir = tempfile.mkdtemp()
self.private_data_dir = private_data_dir
self._loader = ArtifactLoader(self.private_data_dir)

Expand Down

0 comments on commit 766fb5f

Please # to comment.