Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

enhancement: MCP server 缺少 query 长度限制 / method 级授权 / rate limit #294

Copy link
Copy link

Description

@allmonday
Issue body actions

问题

pydantic-resolve 通过 MCP 把 GraphQL schema 与 use_case method 暴露给 AI agent。当前缺少基本的安全控制,对一个面向 agent 的服务来说属于设计层缺陷。

子问题 1:query 长度无上限

pydantic_resolve/graphql/mcp/tools/multi_app_tools.py:364 只检查空串:

if not query or not isinstance(query, str):
    return create_error_response('Query must be a non-empty string', ...)

agent 可发送任意大 query,触发 schema 解析与执行的内存/CPU 放大(DoS 风险)。

子问题 2:无 method 级授权

pydantic_resolve/use_case/mcp_server.py 的 use_case MCP server 把所有装饰了 @business 的方法暴露。context_extractor 是唯一身份钩子,且可选。MCP 客户端一旦可达,任何 agent 可调用任何 method(包括管理类 method)。

子问题 3:缺少调用频次限制

没有 rate limit,单个 agent 可发起大量 GraphQL query 触发 DB 查询。

建议方案

  1. 增加 query 长度上限配置(如默认 100_000 字符),超出返回 INVALID_INPUT 错误;
  2. UseCaseAppConfig / MultiAppManager 加可选 authorizer: Callable[[context, method_name], bool] 钩子,默认拒绝;
  3. 提供简单的 in-memory rate limiter(按 context 身份)作为可选项;
  4. 在 README/文档明确「MCP server 默认无授权,不要直接对公网暴露」的安全语义。

收益

  • 防止无意的 DoS(巨大 query、高频调用);
  • 提供最小授权层,符合面向 AI agent 服务的安全实践;
  • 文档化安全边界,避免用户误部署。
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationImprovements or additions to documentationenhancementNew feature or requestNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.