Skip to content

Commit be6679e

Browse files
liqiang-fit2cloudliuruibin
authored andcommitted
refactor: forbidden access by hostname or docker ip.
1 parent d3ad608 commit be6679e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

apps/common/utils/tool_code.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import subprocess
66
import sys
77
from textwrap import dedent
8-
8+
import socket
99
import uuid_utils.compat as uuid
1010
from django.utils.translation import gettext_lazy as _
1111

@@ -28,7 +28,15 @@ def __init__(self, sandbox=False):
2828
if self.sandbox:
2929
os.system(f"chown -R {self.user}:root {self.sandbox_path}")
3030
self.banned_keywords = CONFIG.get("SANDBOX_PYTHON_BANNED_KEYWORDS", 'nothing_is_banned').split(',');
31-
self.banned_hosts = CONFIG.get("SANDBOX_PYTHON_BANNED_HOSTS", '');
31+
banned_hosts = CONFIG.get("SANDBOX_PYTHON_BANNED_HOSTS", '').strip()
32+
try:
33+
if banned_hosts:
34+
hostname = socket.gethostname()
35+
local_ip = socket.gethostbyname(hostname)
36+
banned_hosts = f"{banned_hosts},{hostname},{local_ip}"
37+
except Exception:
38+
pass
39+
self.banned_hosts = banned_hosts
3240

3341
def _createdir(self):
3442
old_mask = os.umask(0o077)

0 commit comments

Comments
 (0)