Skip to main content
G

dsh-web-fetch-open

gpboyer2/dsh-web-fetch-open

Replaces the web_fetch provider with one that skips private-range filtering, so web_fetch can reach localhost, private networks, link-local and fake-ip ranges and file:// paths.

Install

dsh plugin --profile web add github:gpboyer2/dsh-web-fetch-open

README

dsh-web-fetch-open

一句话:让 web_fetch 能读本机、局域网和 file://,不再只认公网。

简体中文 · English

DSH Node.js JavaScript Cordis tests license

一个 DeepSeek Harness(DSH)插件。出厂 web_fetch 只认公网单播地址,localhost、私网、fake-ip 段和 file:// 全被拒:

Error: URL hostname "localhost" resolves to a non-public IP address   (WEB_BLOCKED_URL)

本插件注册一个不做私网过滤的抓取后端,替换 ctx.web 的 fetchProvider。web_fetch 工具本身不动,agent 那边看不出差别。

工作方式

  • 地址不做私网 / 保留段过滤,只校验协议(http / https / 按配置的 file)。
  • 网络仍走全局 fetch,启动环境里的 HTTP_PROXY、HTTPS_PROXY、NO_PROXY、NODE_USE_ENV_PROXY 照旧生效:Clash 开着时外网仍从代理出去,NO_PROXY 里的本地地址直连。
  • 重定向自己跟,最多 maxRedirects 跳,跨域也跟。
  • Content-Type 缺失或不认识时按内容嗅探。
  • 是否二进制按「声明的文本类型 → 声明的二进制类型 → file:// 扩展名 → UTF-16 BOM → NUL 探测」依次判定。text/html; charset=utf-16 这种正文里天然带 NUL 的文本仍按文本解码,application/pdf 这种没有 NUL 的容器也不会被当文本吐出来。
  • file:// 直接从磁盘读,按扩展名决定 html / text。

放开的范围

项出厂 provider本插件
localhost / 127.0.0.1 / [::1]拒绝允许
私网 10.x 172.16-31.x 192.168.x拒绝允许
链路本地 169.254.x、CGNAT 100.64/10拒绝允许
Clash / sing-box / Surge 的 fake-ip 段 198.18.0.0/15拒绝允许
.local、内网域名只看解析结果允许
跨域重定向拒绝跟随,最多 10 跳
URL 里带 user:pass@拒绝转成 Basic 认证头发送
没有 Content-Type拒绝按内容嗅探 html / text
图片、PDF、压缩包等二进制报错返回一行说明(含字节数),字节不进上下文
file:// 本地文件不支持支持
大小 / 字符 / 超时5MB / 10 万字符 / 30s20MB / 50 万字符 / 25s

快速开始

# 直接从 GitHub 安装(命令行管理的 profile,如 web / main)
dsh plugin --profile <你的profile> add github:gpboyer2/dsh-web-fetch-open

# 本地开发:克隆到 ~/.dsh/plugins/dsh-web-fetch-open,改用本地软链安装
git clone https://github.com/gpboyer2/dsh-web-fetch-open.git ~/.dsh/plugins/dsh-web-fetch-open
dsh plugin --profile <你的profile> add link:$HOME/.dsh/plugins/dsh-web-fetch-open

# 重启 DSH

desktop profile 由 DeepSeek Harness.app 独占,命令行会被拒。桌面版在应用内「插件」页安装,或手动改 profile 的 dependencies 加软链后重启。

包内的 cordis.patch.yml 会把 ctx.web 的 fetchProvider 指到本插件注册的 http-open,不用手改 profile 配置。

验证:让 agent 抓一次 http://127.0.0.1:<你本机服务的端口>/,能返回内容就通了。

核心功能

能力说明
私网直通回环、私网、链路本地、CGNAT、fake-ip 段一律不拦。
file://直接读本地文件,按扩展名决定 html / text。
跨域重定向自己跟最多 maxRedirects 跳,不因跨域中断。
凭据转头URL 里的 user:pass@ 转成 Authorization: Basic,不写进请求行。
内容嗅探缺 Content-Type 时按内容判 html / text。
二进制不吞图片、PDF、压缩包只返回一句说明(含字节数)。
编码感知先看声明的字符集,UTF-16 BOM 也认。
容量可调响应上限、字符上限、超时、UA 都能配。

配置

默认值(index.js 里的 DEFAULTS):

配置默认说明
maxResponseBytes20000000响应体字节上限(20MB)。
maxBodyChars500000交给模型的字符上限(50 万)。
timeoutMs25000单次请求超时。
maxRedirects10重定向跳数上限。
userAgentdeepseek-harness/0.0.1请求 UA,默认与出厂 provider 一致。
allowFileUrlstrue是否允许 file://。
allowCredentialsInUrltrue是否把 user:pass@ 转成 Basic 认证头。

在 profile 的 cordis.patch.yml 里覆盖插件行:

- id: web-fetch-open
  name: dsh-web-fetch-open
  config:
    maxResponseBytes: 20000000
    maxBodyChars: 500000
    timeoutMs: 25000
    maxRedirects: 10
    allowFileUrls: true
    allowCredentialsInUrl: true

架构

index.js              抓取后端(http-open):地址校验、重定向、解码、二进制判定
cordis.patch.yml      bundle patch:把 ctx.web 的 fetchProvider 指到 http-open
test/                 11 条测试,全部跑在本地回环,不出网

只替换 fetchProvider,不动 web_fetch 工具;网络走全局 fetch,代理与 NO_PROXY 行为保持不变。

测试

npm test

11 条,全部跑在本地回环上,不出网:回环地址抓取、跨域重定向、缺 Content-Type、二进制说明、UTF-16 正文、image/svg+xml 按文本、file:// 的 PDF 按扩展名、URL 内凭据、私网 / CGNAT / fake-ip 字面量、allowFileUrls: false 时的拒绝。

边界

  • 装上就是真的能访问内网。没有白名单、没有网段排除,用在不可信环境里之前先想清楚。
  • file:// 读的是运行 DSH 那个用户能读的一切文件,同样没有路径白名单。
  • 二进制(图片、PDF、压缩包)只返回一句说明,字节不进上下文;需要原文件时让 agent 用 bash 下载。
  • 依赖 ctx.web 接缝与 fetchProvider 配置项,适配 DSH 0.2.x;上游改这个接缝就得跟着改。
  • 必须重启才生效:provider 是启动时注册的。

许可证

MIT

Related plugins