Skip to content

feat: pin remote spider.jar behind SHA-256, default fallback-only + CSP diagnostics - #219

Open
libertydragonn wants to merge 2 commits into
Decohererk:mainfrom
libertydragonn:redo/spider-jar
Open

feat: pin remote spider.jar behind SHA-256, default fallback-only + CSP diagnostics#219
libertydragonn wants to merge 2 commits into
Decohererk:mainfrom
libertydragonn:redo/spider-jar

Conversation

@libertydragonn

@libertydragonn libertydragonn commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

背景

重做系列的 spider.jar 供应链加固。依赖 SSRF 防护 PR(#218(复用 fetchWithValidatedRedirects),在其合并前,本 PR 的 diff 会包含那一支的 commit。

改动

  • spiderJar.ts 默认使用内置最小 fallback JAR;远程 JAR 需显式 ALLOW_REMOTE_SPIDER_JAR=true + SPIDER_JAR_URL(S) + SPIDER_JAR_SHA256 校验,并通过校验过的重定向 fetch 拉取,无法访问私网。
  • 移除 TVBox config / 诊断 / admin 示例源里硬编码的第三方 spider.jar;?spider= 仅接受已配置的 pinned 候选地址。
  • 针对 [Bug]: 使用tvbox播放提示找不到数据,没升级1.5.0时是可以使用的,退回到1.4.0也是这样。 #210 的可诊断性改进:fallback-only 模式下若配置含 CSP(csp_)源,/api/tvbox/config 输出 spider_warning/api/tvbox/spider-status 明确说明「csp_ 源会没数据 / jar 加载失败」的表现与恢复所需的环境变量,避免用户只看到「没找到数据」而无从排查。
  • 修正 TVBox 超时回退的 ;md5;... 元数据使其来自真实 fallback JAR 字节。
  • 迁移指南写入 TVBox配置优化说明.md,新增 spider jar 策略测试。

兼容性 / 迁移

只使用普通 CMS 采集源的用户不受影响。依赖 CSP spider 的 TVBox / 影视仓用户升级后这些源会失效,需按迁移指南显式配置以下三个环境变量恢复:

ALLOW_REMOTE_SPIDER_JAR=true
SPIDER_JAR_URL=https://你信任的地址/spider.jar
SPIDER_JAR_SHA256=<该 JAR 的 64 位 SHA-256>

验证

  • jest --runInBand 通过(21 套件 / 110 测试)
  • pnpm typecheck 通过
  • docker build 本分支镜像成功(干净 checkout 下构建)

不改动登录 / 鉴权流程。

- New src/lib/proxy-security.ts: validateProxyTargetUrl blocks localhost,
  private/link-local/CGNAT ranges, cloud metadata hosts and credentialed
  URLs, resolves DNS and rejects targets answering with blocked addresses;
  fetchWithValidatedRedirects re-validates every redirect hop.
- Opt-in allowlisting for self-hosted LAN media (NAS/Jellyfin) via
  PROXY_ALLOW_PRIVATE_HOSTS=true + PROXY_PRIVATE_HOST_ALLOWLIST
  (exact IPs, hostnames, IPv4 CIDRs).
- Apply validation to /api/proxy/{cms,key,logo,m3u8,segment,stream},
  /api/download/{proxy,ffmpeg,ffmpeg/file}, /api/live/precheck and
  /api/douban/health.
- Documented threat model: this significantly reduces SSRF exposure but
  resolved IPs are not pinned to the socket, so DNS rebinding is
  mitigated best-effort, not eliminated.
- Add proxy target validation regression tests.

No auth/cookie/middleware changes in this PR.
…back-only

- spiderJar.ts now serves a bundled minimal fallback JAR by default;
  remote JARs require ALLOW_REMOTE_SPIDER_JAR=true plus SPIDER_JAR_URL(S)
  and a SPIDER_JAR_SHA256 pin, and are fetched through the validated
  redirect fetcher so they cannot reach private hosts.
- Remove hardcoded third-party spider.jar candidates from TVBox config,
  diagnostics and admin demo source; ?spider= only accepts configured
  pinned candidates.
- TVBox config emits spider_warning when fallback-only mode is active
  and the config contains CSP (csp_) sources; /api/tvbox/spider-status
  spells out the CSP impact and the exact env vars needed to restore a
  pinned remote JAR (addresses the jar-load reports in Decohererk#210).
- Fix TVBox timeout fallback metadata so ;md5;... reflects the actual
  fallback JAR bytes.
- Add migration guide to TVBox配置优化说明.md and spider jar policy tests.

Depends on the proxy-security PR (uses fetchWithValidatedRedirects).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant