mirror of
https://github.com/jumpserver/jumpserver.git
synced 2026-07-11 09:25:03 +00:00
fix: sanitize runtime directory names to avoid unsafe characters (#17002)
Co-authored-by: wangruidong <940853815@qq.com>
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user