返回提交历史
Modified
g4f/gui/server/website.py
+11
-0
Modified
g4f/mcp/server.py
+3
-2
Modified
g4f/mcp/tools.py
+2
-2
XFEstudio/gpt4free
Update mcp
ee891210
代码差异
3 个文件
+16
-4
@@ -132,6 +132,14 @@ class Website:
132
132
'function': self._playground,
133
133
'methods': ['GET']
134
134
},
135
'/apps/': {
136
'function': self._apps,
137
'methods': ['GET']
138
},
139
'/apps/<path:filename>': {
140
'function': self._apps,
141
'methods': ['GET']
142
},
135
143
}
136
144
137
145
def _index(self, filename = "home"):
@@ -156,6 +164,9 @@ class Website:
156
164
157
165
def _dist(self, name: str):
158
166
return render(f"dist/{name}")
167
168
def _apps(self, filename: str = "index.html"):
169
return render(f"apps/{filename}")
159
170
160
171
def _playground(self, filename: str = "index.html"):
161
172
PLAYGROUND_URL = "https://raw.githubusercontent.com/gpt4free/playground/refs/heads/main/"
@@ -435,12 +435,13 @@ class MCPServer:
435
435
header so they run in an isolated null origin.
436
436
"""
437
437
from .pa_provider import get_workspace_dir
438
workspace = get_workspace_dir()
438
workspace = get_workspace_dir().resolve()
439
439
440
440
file_path = request.match_info.get("file_path", "")
441
441
try:
442
442
resolved = (workspace / file_path).resolve()
443
resolved.relative_to(workspace.resolve())
443
# Security: ensure the resolved path is still inside the workspace directory
444
resolved.relative_to(workspace)
444
445
except (ValueError, Exception):
445
446
return web.Response(status=403, text="Path traversal is not allowed")
446
447
@@ -609,10 +609,10 @@ class FileReadTool(MCPTool):
609
609
if not rel_path:
610
610
return {"error": "path parameter is required"}
611
611
612
workspace = get_workspace_dir()
612
workspace = get_workspace_dir().resolve()
613
613
try:
614
614
target = (workspace / rel_path).resolve()
615
if not str(target).startswith(str(workspace.resolve())):
615
if not str(target).startswith(str(workspace)):
616
616
return {"error": "Access outside the workspace is not allowed"}
617
617
if not target.exists():
618
618
return {"error": f"File not found: {rel_path}"}