Skip to content

Commit 62dda96

Browse files
Jkhall81ssbarneaalisonlhart
authored
fix: replace hardcoded /tmp path with secure temp directory (CWE… (#4878)
Co-authored-by: Sorin Sbarnea <[email protected]> Co-authored-by: Alison Hart <[email protected]>
1 parent 4a764a4 commit 62dda96

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/ansiblelint/rules/args.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
from __future__ import annotations
44

5+
import atexit
56
import contextlib
67
import importlib.util
78
import io
89
import json
910
import logging
1011
import re
12+
import shutil
1113
import sys
14+
import tempfile
1215
from typing import TYPE_CHECKING, Any
1316

1417
# pylint: disable=preferred-module
@@ -60,9 +63,19 @@
6063
# https://github.com/ansible/ansible-lint/issues/3152
6164
"ansible.posix.synchronize": ["use_ssh_args"],
6265
}
66+
_SAFE_ASYNC_DIR = tempfile.mkdtemp(prefix="ansible-lint-async-")
67+
68+
69+
def _cleanup_async_dir() -> None:
70+
"""Safely remove the temp directory and all its contents."""
71+
shutil.rmtree(_SAFE_ASYNC_DIR, ignore_errors=True)
72+
73+
74+
atexit.register(_cleanup_async_dir)
75+
6376
workarounds_inject_map = {
6477
# https://github.com/ansible/ansible-lint/issues/2824
65-
"ansible.builtin.async_status": {"_async_dir": "/tmp/ansible-async"},
78+
"ansible.builtin.async_status": {"_async_dir": _SAFE_ASYNC_DIR},
6679
}
6780
workarounds_mutex_args_map = {
6881
# https://github.com/ansible/ansible-lint/issues/4623

0 commit comments

Comments
 (0)