fix(service): reject encoded MCP paths

Reject percent signs in mcp_path so ASGI path decoding cannot turn an accepted configuration into an unreachable route. Cover encoded slash, space, and double-encoded slash inputs.
This commit is contained in:
jinli.yl 2026-08-27 17:07:55 +08:00
parent 4b5d34c8bc
commit 470e782f71
2 changed files with 4 additions and 1 deletions

View file

@ -205,7 +205,7 @@ class HttpService(BaseService):
)
if "//" in path or any(segment in {".", ".."} for segment in path.split("/")):
raise ValueError("mcp_path must use non-empty literal path segments")
if any(char in path for char in "{}?#\\") or any(
if any(char in path for char in "{}?#%\\") or any(
char.isspace() or ord(char) < 32 or ord(char) == 127 for char in path
):
raise ValueError("mcp_path must be a literal URL path without route, query, or fragment syntax")

View file

@ -194,6 +194,9 @@ def test_http_service_rejects_invalid_or_conflicting_mcp_paths() -> None:
"/{rest:path}",
"/mcp?mode=test",
"/mcp#fragment",
"/mcp%2Fv2",
"/mcp%20v2",
"/mcp%252Fv2",
"/mcp path",
"/mcp//nested",
"/mcp/../nested",