Skip to content

Commit eb30b88

Browse files
refactor: remove MAXKB_SANDBOX_PYTHON_BANNED_KEYWORDS.
1 parent 057e042 commit eb30b88

File tree

3 files changed

+1
-13
lines changed

3 files changed

+1
-13
lines changed

apps/common/utils/tool_code.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def __init__(self, sandbox=False):
2727
else:
2828
self.sandbox_path = os.path.join(PROJECT_DIR, 'data', 'sandbox')
2929
self.user = None
30-
self.banned_keywords = CONFIG.get("SANDBOX_PYTHON_BANNED_KEYWORDS", 'nothing_is_banned').split(',');
3130
self.sandbox_so_path = f'{self.sandbox_path}/sandbox.so'
3231
try:
3332
self._init_dir()
@@ -74,10 +73,10 @@ def _init_dir(self):
7473
f.write(f"SANDBOX_PYTHON_BANNED_HOSTS={banned_hosts}")
7574
f.write("\n")
7675
f.write(f"SANDBOX_PYTHON_ALLOW_SUBPROCESS={allow_subprocess}")
76+
f.write("\n")
7777
os.chmod(sandbox_conf_file_path, 0o440)
7878

7979
def exec_code(self, code_str, keywords):
80-
self.validate_banned_keywords(code_str)
8180
_id = str(uuid.uuid7())
8281
success = '{"code":200,"msg":"成功","data":exec_result}'
8382
err = '{"code":500,"msg":str(e),"data":None}'
@@ -116,8 +115,6 @@ def exec_code(self, code_str, keywords):
116115
raise Exception(result.get('msg'))
117116

118117
def _generate_mcp_server_code(self, _code, params):
119-
self.validate_banned_keywords(_code)
120-
121118
# 解析代码,提取导入语句和函数定义
122119
try:
123120
tree = ast.parse(_code)
@@ -239,11 +236,6 @@ def _exec_sandbox(self, _code):
239236
capture_output=True, **kwargs)
240237
return subprocess_result
241238

242-
def validate_banned_keywords(self, code_str):
243-
matched = next((bad for bad in self.banned_keywords if bad in code_str), None)
244-
if matched:
245-
raise Exception(f"keyword '{matched}' is banned in the tool.")
246-
247239
def validate_mcp_transport(self, code_str):
248240
servers = json.loads(code_str)
249241
for server, config in servers.items():

apps/tools/serializers/tool.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,6 @@ def insert(self, instance, with_valid=True):
354354
self.is_valid(raise_exception=True)
355355
ToolCreateRequest(data=instance).is_valid(raise_exception=True)
356356
# 校验代码是否包括禁止的关键字
357-
ToolExecutor().validate_banned_keywords(instance.get('code', ''))
358357
if instance.get('tool_type') == ToolType.MCP:
359358
ToolExecutor().validate_mcp_transport(instance.get('code', ''))
360359

@@ -391,7 +390,6 @@ class TestConnection(serializers.Serializer):
391390
def test_connection(self):
392391
self.is_valid(raise_exception=True)
393392
# 校验代码是否包括禁止的关键字
394-
ToolExecutor().validate_banned_keywords(self.data.get('code', ''))
395393
ToolExecutor().validate_mcp_transport(self.data.get('code', ''))
396394

397395
# 校验mcp json
@@ -486,7 +484,6 @@ def edit(self, instance, with_valid=True):
486484
self.is_valid(raise_exception=True)
487485
ToolEditRequest(data=instance).is_valid(raise_exception=True)
488486
# 校验代码是否包括禁止的关键字
489-
ToolExecutor().validate_banned_keywords(instance.get('code', ''))
490487
if instance.get('tool_type') == ToolType.MCP:
491488
ToolExecutor().validate_mcp_transport(instance.get('code', ''))
492489

installer/Dockerfile-base

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ ENV PATH=/opt/py3/bin:$PATH \
4848
MAXKB_SANDBOX=1 \
4949
MAXKB_SANDBOX_HOME=/opt/maxkb-app/sandbox \
5050
MAXKB_SANDBOX_PYTHON_PACKAGE_PATHS="/opt/py3/lib/python3.11/site-packages,/opt/maxkb-app/sandbox/python-packages,/opt/maxkb/python-packages" \
51-
MAXKB_SANDBOX_PYTHON_BANNED_KEYWORDS="subprocess.,system(,exec(,execve(,pty.,eval(,compile(,shutil.,input(,__import__" \
5251
MAXKB_SANDBOX_PYTHON_BANNED_HOSTS="127.0.0.1,localhost,host.docker.internal,maxkb,pgsql,redis" \
5352
MAXKB_ADMIN_PATH=/admin
5453

0 commit comments

Comments
 (0)