Repository navigation
feat(ssrf): 支持通过 HTTPS_PROXY 出网 - #992
Merged
Merged
Conversation
采集站在部分网络环境下直连不可达(Cloudflare 机器人防护拦截搜索接口、 目标站在国内网络超时),而应用此前没有任何出网代理入口:Node/undici 不继承 macOS/Windows 的系统代理,部署者即使开了系统代理,服务端请求 仍然直连。 新增 HTTPS_PROXY / HTTP_PROXY 环境变量支持: - getUpstreamProxyUrl() 读取并校验代理地址(仅 http/https) - isNoProxyHost() 支持 NO_PROXY 例外列表 - createUpstreamDispatcher() 按需返回 ProxyAgent 或连接级 SSRF Agent 走代理时连接层 DNS 校验不再生效(TCP 由代理建立、域名由代理解析), 但应用层校验(isValidProxyUrl + isBlockedByDNS)每次请求前仍然执行, 内网/保留地址目标依旧被拦下。 补充 4 条单元测试覆盖代理读取、NO_PROXY 匹配与 dispatcher 选择。
bestZwei
added a commit
that referenced
this pull request
Nov 30, 2026
PR #992 让 ProxyAgent 接管连接后,连接层 SSRF/DNS Rebinding 校验不再生效。safeRedirects:false 的快捷路径原本只靠连接层兜底,补一次应用层 URL/DNS 校验;README 与 .env.example 明确提示安全代价。新增代理场景回归测试:验证内网目标仍被拦截、快捷路径不再裸奔、请求确实经代理发出。连接层专项测试显式用 NO_PROXY=* 固定直连口径,避免宿主机代理设置改写测试意图。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
采集站在部分网络环境下直连不可达:
?ac=videolist)被 Cloudflare 机器人防护拦截,返回 JS 挑战页(403),而列表接口(?ac=list)却正常返回 JSON —— 这类源不加代理会表现为「源能添加、搜索没结果」而应用此前没有任何出网代理入口。Node/undici 不继承 macOS/Windows 的系统代理设置,部署者即使在系统里开了代理(
networksetup),服务端请求仍然直连 —— 表现为「curl 走代理能通、应用里 403/超时」。改动
src/lib/ssrf.ts新增出网代理支持:getUpstreamProxyUrl()HTTPS_PROXY/https_proxy/HTTP_PROXY/http_proxy,仅接受http:/https:isNoProxyHost()NO_PROXY/no_proxy例外列表(逗号或空白分隔,支持.example.com后缀与*)createUpstreamDispatcher()ProxyAgent(走代理)或原有的连接级 SSRFAgent(直连)installFetchSSRFProtection()改用createUpstreamDispatcher(),并从 fetch 入参(string/URL/Request三种形态)解析目标 URL 以判断是否命中NO_PROXY。安全考量
走代理时连接层 DNS 校验不再生效 —— TCP 连接由代理建立、目标域名也由代理解析,
safeLookup/ssrfConnect无法介入。但应用层校验(
isValidProxyUrl+isBlockedByDNS)在每次请求前仍然执行,内网/保留地址目标依旧被拦下。本机实测(代理开启状态):http://169.254.169.254/latest/meta-datahttp://127.0.0.1:8080/api/statushttp://192.168.0.102:8080/api/statushttp://localhost:8080/api/statusfile:///etc/passwdsource.url测试
NO_PROXY匹配、dispatcher 选择(代理 / 直连 / 命中NO_PROXY)npx tsc --noEmit通过44 文件 / 653 用例全绿(原 649 + 新增 4)部署影响
纯增量,默认行为不变 —— 未设置
HTTPS_PROXY/HTTP_PROXY时createUpstreamDispatcher()直接返回原有的 SSRF Agent,与改动前完全一致。建议把视频 CDN 域名加进
NO_PROXY,避免播放流量绕行代理导致卡顿(实测 CDN 走代理比直连慢约 2.5 倍)。