返回提交历史
Modified
etc/unittest/mcp.py
+3
-0
Modified
g4f/mcp/tools.py
+14
-10
XFEstudio/gpt4free
Address review: add input validation for timeout/max_depth, clarify test comment
Agent-Logs-Url: https://github.com/xtekky/gpt4free/sessions/41556926-6205-4207-b36b-e10e22a8b87e Co-authored-by: hlohaus <983577+hlohaus@users.noreply.github.com>
d2f2af88
代码差异
2 个文件
+17
-10
@@ -516,6 +516,9 @@ class TestSecurityHardening(unittest.IsolatedAsyncioTestCase):
516
516
timeout=5.0,
517
517
)
518
518
self.assertTrue(r.success)
519
# The buffer may contain up to MAX_OUTPUT_BYTES of user output plus a
520
# small number of bytes from multi-byte UTF-8 boundary rounding; 50
521
# bytes is generous slack for that edge case.
519
522
self.assertLessEqual(len(r.stdout), MAX_OUTPUT_BYTES + 50)
520
523
self.assertIn("truncated", r.stderr.lower())
521
524
@@ -549,17 +549,21 @@ class PythonExecuteTool(MCPTool):
549
549
allowed = SAFE_MODULES | frozenset(extra_names)
550
550
# Allow callers to reduce (but not exceed) the defaults
551
551
requested_timeout = arguments.get("timeout")
552
timeout = (
553
min(float(requested_timeout), MAX_EXEC_TIMEOUT)
554
if requested_timeout is not None
555
else MAX_EXEC_TIMEOUT
556
)
552
if requested_timeout is not None:
553
try:
554
timeout = min(float(requested_timeout), MAX_EXEC_TIMEOUT)
555
except (TypeError, ValueError):
556
return {"error": "timeout must be a number"}
557
else:
558
timeout = MAX_EXEC_TIMEOUT
557
559
requested_depth = arguments.get("max_depth")
558
max_depth = (
559
min(int(requested_depth), MAX_RECURSION_DEPTH)
560
if requested_depth is not None
561
else MAX_RECURSION_DEPTH
562
)
560
if requested_depth is not None:
561
try:
562
max_depth = min(int(requested_depth), MAX_RECURSION_DEPTH)
563
except (TypeError, ValueError):
564
return {"error": "max_depth must be an integer"}
565
else:
566
max_depth = MAX_RECURSION_DEPTH
563
567
564
568
try:
565
569
exec_result = execute_safe_code(