fix: sanitize runtime directory names to avoid unsafe characters (#17002)

Co-authored-by: wangruidong <940853815@qq.com>
This commit is contained in:
fit2bot
2026-07-08 18:03:06 +08:00
committed by GitHub
parent f6c865c0b6
commit 6bfe770b02

View File

@@ -2,6 +2,7 @@ import hashlib
import json
import logging
import os
import re
import shutil
import time
from collections import defaultdict
@@ -27,6 +28,12 @@ from users.utils import activate_user_language
logger = get_logger(__name__)
BULK_SIZE = 80
RUNTIME_DIR_UNSAFE_CHARS = re.compile(r'[\s/\\:<>|"?*\x00-\x1f]+')
def safe_runtime_dir_name(name):
dir_name = RUNTIME_DIR_UNSAFE_CHARS.sub('_', str(name or '')).strip('_')
return dir_name or 'automation'
class SSHTunnelManager:
@@ -239,7 +246,7 @@ class PlaybookPrepareMixin:
def prepare_runtime_dir(self):
ansible_dir = settings.ANSIBLE_DIR
task_name = self.execution.snapshot["name"]
dir_name = "{}_{}".format(task_name.replace(" ", "_"), self.execution.id)
dir_name = "{}_{}".format(safe_runtime_dir_name(task_name), self.execution.id)
path = os.path.join(
ansible_dir,
"automations",