Skip to content

fix(utils/request-rewriter): pass CONNECT proxy tunnel requests through untouched - #23136

Open
ryanchou1994 wants to merge 1 commit into
DIYgod:masterfrom
ryanchou1994:fix/request-rewriter-connect-passthrough
Open

ryanchou1994 wants to merge 1 commit into
DIYgod:masterfrom
ryanchou1994:fix/request-rewriter-connect-passthrough

Conversation

@ryanchou1994

Copy link
Copy Markdown
Contributor

Involved Issue / 该 PR 相关 Issue

Close #16970

Example for the Proposed Route(s) / 路由地址示例

NOROUTE

New RSS Route Checklist / 新 RSS 路由检查表

  • New Route / 新的路由
  • Anti-bot or rate limit / 反爬/频率限制
    • If yes, do your code reflect this sign? / 如果有, 是否有对应的措施?
  • Date and time / 日期和时间
    • Parsed / 可以解析
    • Correct time zone / 时区正确
  • New package added / 添加了新的包
  • Puppeteer

Note / 说明

With IG_PROXY set, instagram-private-api uses request + tunnel-agent, which sends a CONNECT to the proxy with legacy options whose path is the tunnel target (i.instagram.com:443), not a URL path. The rewriter rebuilds a URL as protocol + host + path, giving http://127.0.0.1i.instagram.com:443/, and node fails with ENOTFOUND 127.0.0.1i.instagram.com.

Fix: in the legacy options branch, hand CONNECT requests to node untouched. A URL cannot be rebuilt for them, and UA / referer injection is meant for the target site, not the proxy handshake. CONNECT requests thus no longer get the global proxy agent; that path has never worked since 2024-03, so nothing depends on it. Regular requests are unaffected. Unlike the workaround in the issue, this does not throw on options without a port and keeps tunnel-agent's agent: false.

Tests: two cases added to the get wrapper tests (a normal legacy options request and the tunnel-agent CONNECT shape). With the fix reverted the CONNECT case fails with the malformed URL above; with it the suite passes 15/15 on node 24; oxlint, oxfmt and tsc are clean. No Instagram account plus HTTP proxy here, so the end-to-end login flow was not run.

…gh untouched

tunnel-agent (used by request / request-promise, e.g. instagram-private-api with IG_PROXY) sends a CONNECT request with legacy options whose path is the tunnel target authority (host:port), not a URL path. Rebuilding a URL from those options produced http://127.0.0.1i.instagram.com:443/ and node then resolved that bogus hostname (ENOTFOUND). Hand CONNECT requests to node as-is: they cannot be turned into a URL, and UA/referer/proxy-agent injection does not apply to a proxy handshake.

Fixes DIYgod#16970
Copilot AI lite review requested due to automatic review settings August 29, 2026 15:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ryanchou1994

Copy link
Copy Markdown
Contributor Author

Gentle ping — also open for two weeks. All checks are green here (the Vercel one is just the preview auth page, not a build failure). The change keeps CONNECT tunnel requests untouched so proxied requests stop getting mangled by the rewriter. Let me know if you want anything changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

instagram在使用IG_PROXY时访问失败,溯源发现是utils\request-rewriter\get.ts用options还原url的处理有bug

2 participants