refactor: forbidden access by hostname or docker ip.
parent
f0ecad6de1
commit
c1fbb41aa5
|
|
@ -5,7 +5,7 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
import socket
|
||||||
import uuid_utils.compat as uuid
|
import uuid_utils.compat as uuid
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
|
@ -28,7 +28,15 @@ class ToolExecutor:
|
||||||
if self.sandbox:
|
if self.sandbox:
|
||||||
os.system(f"chown -R {self.user}:root {self.sandbox_path}")
|
os.system(f"chown -R {self.user}:root {self.sandbox_path}")
|
||||||
self.banned_keywords = CONFIG.get("SANDBOX_PYTHON_BANNED_KEYWORDS", 'nothing_is_banned').split(',');
|
self.banned_keywords = CONFIG.get("SANDBOX_PYTHON_BANNED_KEYWORDS", 'nothing_is_banned').split(',');
|
||||||
self.banned_hosts = CONFIG.get("SANDBOX_PYTHON_BANNED_HOSTS", '');
|
banned_hosts = CONFIG.get("SANDBOX_PYTHON_BANNED_HOSTS", '').strip()
|
||||||
|
try:
|
||||||
|
if banned_hosts:
|
||||||
|
hostname = socket.gethostname()
|
||||||
|
local_ip = socket.gethostbyname(hostname)
|
||||||
|
banned_hosts = f"{banned_hosts},{hostname},{local_ip}"
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
self.banned_hosts = banned_hosts
|
||||||
|
|
||||||
def _createdir(self):
|
def _createdir(self):
|
||||||
old_mask = os.umask(0o077)
|
old_mask = os.umask(0o077)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue