Skip to content

fix: connect through an IPv6 HTTP proxy - #18155

Open
haranishi wants to merge 1 commit into
misskey-dev:developfrom
haranishi:fix/ipv6-proxy-hostname
Open

haranishi wants to merge 1 commit into
misskey-dev:developfrom
haranishi:fix/ipv6-proxy-hostname

Conversation

@haranishi

Copy link
Copy Markdown

What

When config.proxy is an IPv6 URL such as http://[2001:db8::2]:3128, the existing hpagent setup receives a host without the surrounding []. Domain and IPv4 proxy strings are unchanged.

Why

Fixes #17565.

hpagent v1.2.0 copies URL.hostname into http.request({ host }). For IPv6 that value is [2001:db8::2]. Node's urlToHttpOptions strips those brackets, but a raw host string does not, so getaddrinfo returns ENOTFOUND. hpagent has not had a release since 2023.

The proxy is still built only in HttpRequestService, for both HttpProxyAgent and HttpsProxyAgent. This does not add another proxy client. A URL object cannot store an IPv6 hostname without brackets (hostname keeps them after assignment), and hpagent already accepts a non-string proxy and reads hostname, port, protocol, username, and password. The configured URL string stays in bracket form.

Additional info (optional)

  • Base: 8fe4596d7d56d0a7a4038042ec3eda26cfc9f5ad (develop).
  • packages/backend/test/unit/misc/hpagent-proxy.ts checks the host stored by both agents, leaves domain and IPv4 strings untouched, and keeps auth and protocol. Leaving the brackets in place fails that test.
  • node scripts/check-shipping.mjs --base origin/develop: lint, SPDX, and locale safety passed.
  • A live CONNECT proxy on [::1] was not run. On this machine, dns.lookup('[2001:db8::2]') is ENOTFOUND and dns.lookup('2001:db8::2') returns the IPv6 address. Windows can resolve the bracketed form, so the test does not assert getaddrinfo.
  • The cause and this construction site were already described on HTTP/HTTPS用のproxy設定にipv6を指定するとRequestErrorが発生する #17565. No open pull request covered it.
  • Prepared with an AI coding assistant.

Checklist

  • Read the contribution guide
  • Test working in a local environment
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md
  • (If possible) Add tests

hpagent が URL.hostname を http.request の host に渡すと、IPv6 の角括弧付きのまま名前解決に失敗する。
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

角括弧付きIPv6ホスト名を含むプロキシ設定を変換する関数を追加しました。HttpRequestServiceは変換結果をHTTP・HTTPSのhpagentエージェントに渡します。ユニットテストは変換結果とエージェント内のホスト名を検証します。

Changes: IPv6プロキシ対応

Layer / File(s) Summary
プロキシ変換とエージェントへの連携
packages/backend/src/misc/hpagent-proxy.ts, packages/backend/src/core/HttpRequestService.ts, packages/backend/test/unit/misc/hpagent-proxy.ts
proxyForHpagentを追加しました。URLを解析できない場合、またはホスト名が角括弧で囲まれていない場合は入力文字列を返します。角括弧付きホスト名の場合は、角括弧を除いたホスト名とURLの各フィールドを持つオブジェクトを返します。HttpRequestServiceは変換結果をHTTP・HTTPSエージェントに渡します。テストはURLの各フィールドとエージェント内のホスト名を確認します。

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: syuilo, samunohito

Merge Risk: Minimal · up to dc5fd

This change lets the server connect through an IPv6 HTTP or HTTPS proxy, and other proxy formats behave as before. No concrete merge-blocking risk was found. The only gap is that a live IPv6 proxy connection was not tested.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed タイトル「fix: connect through an IPv6 HTTP proxy」は、変更の主目的であるIPv6 HTTPプロキシへの接続修正を具体的に示しています。raw_summaryの変更内容(hpagentへ渡すホスト名から角括弧を除去し、HTTP・HTTPSのエージェントで共通に扱う)と一致するため、主要な変更を正しく表しています。
Description check Passed 説明文は、テンプレートの主要セクションである What、Why、Additional info、Checklist をすべて含んでいます。What では IPv6 プロキシURLでの問題と影響範囲を説明し、Why では原因(hpagent v1.2.0 が URL.hostname をそのまま渡すこと)、関連 Issue #17565、採用した方針を説明しています。テスト内容と未実施の検証(ライブ…
Linked Issues check Passed [#17565] 直接リンクされたIssueの要求は、IPv6のHTTP/HTTPSプロキシ設定で getaddrinfo ENOTFOUND [2001:db8::2] が発生しないようにすることです。

原因は、hpagent v1.2.0が URL.hostname の角括弧付きの値を http.request({ host }) に渡すことです。

変更内容:
- `packa…
Out of Scope Changes check Passed 変更は次の4つのファイルに限られます。いずれも #17565 のIPv6プロキシ対応に直接関係します。

- packages/backend/src/misc/hpagent-proxy.ts: IPv6プロキシ用の変換処理を追加します。
- packages/backend/src/core/HttpRequestService.ts: 既存のhpagent設定で変換処理を使います。プ…
Full details: Description check

Explanation

説明文は、テンプレートの主要セクションである What、Why、Additional info、Checklist をすべて含んでいます。What では IPv6 プロキシURLでの問題と影響範囲を説明し、Why では原因(hpagent v1.2.0 が URL.hostname をそのまま渡すこと)、関連 Issue #17565、採用した方針を説明しています。テスト内容と未実施の検証(ライブ CONNECT プロキシ)も記載されています。一方で、チェックリストの「Test working in a local environment」は未チェックのままで、「Update CHANGELOG.md」はチェック済みですが、CHANGELOG.md は除外ファイルに含まれているため、この点は確認が必要です。説明は概ね完全であるため合格と判断します。

Full details: Linked Issues check

Explanation

[#17565] 直接リンクされたIssueの要求は、IPv6のHTTP/HTTPSプロキシ設定で getaddrinfo ENOTFOUND [2001:db8::2] が発生しないようにすることです。

原因は、hpagent v1.2.0が URL.hostname の角括弧付きの値を http.request({ host }) に渡すことです。

変更内容:

  • packages/backend/src/misc/hpagent-proxy.ts の proxyForHpagent は、角括弧付きIPv6ホストを持つURL文字列を、角括弧を除いたホスト名、ポート、プロトコル、ユーザー名、パスワードを持つオブジェクトに変換します。
  • ドメイン名、IPv4、URLとして解析できない文字列は、変更されずにそのまま返します。
  • packages/backend/src/core/HttpRequestService.ts は、HttpProxyAgent と HttpsProxyAgent の両方で proxyForHpagent の結果を使います。
  • packages/backend/test/unit/misc/hpagent-proxy.ts は、両エージェントが保持するホスト名を検証します。IPv4とドメイン名の変更がないことや、認証情報、プロトコル、HTTPSのデフォルトポートも検証します。

これらの変更は、Issueの原因に対応しています。ただし、実際のCONNECTプロキシを使う接続テストは実施されていません。また、確認はhpagentの挙動に関する説明と単体テストに基づきます。実環境での接続成功は未確認です。

Full details: Out of Scope Changes check

Explanation

変更は次の4つのファイルに限られます。いずれも #17565 のIPv6プロキシ対応に直接関係します。

  • packages/backend/src/misc/hpagent-proxy.ts: IPv6プロキシ用の変換処理を追加します。
  • packages/backend/src/core/HttpRequestService.ts: 既存のhpagent設定で変換処理を使います。プロキシ未設定時のエージェント選択は変わりません。
  • packages/backend/test/unit/misc/hpagent-proxy.ts: 変換処理の単体テストを追加します。
  • CHANGELOG.md: 除外対象のため、評価対象外です。

今回確認した範囲では、Issueに関係しない変更は見つかりませんでした。

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

IPv6の角括弧をほどいて
ホスト名をそっと取り出します
HTTPにもHTTPSにも渡します
テストが値をたしかめます
プロキシの道がつながります

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8fe4596 and dc5fd2f.

Files ignored due to path filters: 1

  • CHANGELOG.md is excluded by !CHANGELOG.md
Files selected for processing: 3

  • packages/backend/src/core/HttpRequestService.ts
  • packages/backend/src/misc/hpagent-proxy.ts
  • packages/backend/test/unit/misc/hpagent-proxy.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@github-actions github-actions Bot added packages/backend Server side specific issue/PR packages/backend:test labels Nov 16, 2026
@haranishi
haranishi marked this pull request as ready for review November 16, 2026 13:29
@github-actions

Copy link
Copy Markdown
Contributor

このPRによるapi.jsonの差分
差分はありません。
Get diff files from Workflow Page

@github-project-automation github-project-automation Bot moved this from Todo to Approved in [実験中] 管理用 Nov 17, 2026
@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 26.94%. Comparing base (c696bf0) to head (dc5fd2f).
⚠️ Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
packages/backend/src/misc/hpagent-proxy.ts 85.71% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           develop   #18155       +/-   ##
============================================
+ Coverage    12.81%   26.94%   +14.12%     
============================================
  Files          228     1162      +934     
  Lines        11181    39948    +28767     
  Branches      3699    11000     +7301     
============================================
+ Hits          1433    10763     +9330     
- Misses        7661    23406    +15745     
- Partials      2087     5779     +3692     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown
Contributor

⚙️ Backend Diagnostics Report

Memory: After GC

(No significant changes)

V8 Heap Snapshot Statistics

Metric @ Base @ Head Δ MAD
$\color{gray}{\rule{8pt}{8pt}}$ Total 79 MB
± 1.1 KB
79 MB
± 256 B
$\text{-9.9 KB}$
$\text{-0\%}$
1.1 KB
$\color{orange}{\rule{8pt}{8pt}}$ Code 24 MB 24 MB $\text{-12 KB}$ 6.7 KB
$\color{red}{\rule{8pt}{8pt}}$ Strings 24 MB 24 MB $\text{+512 B}$ 2.1 KB
$\color{cyan}{\rule{8pt}{8pt}}$ JS arrays 5.6 MB 5.6 MB 0 B 0 B
$\color{green}{\rule{8pt}{8pt}}$ Typed arrays 544 KB 544 KB 0 B 0 B
$\color{yellow}{\rule{8pt}{8pt}}$ System objects 2 MB 2 MB $\text{+1.9 KB}$ 239 B
$\color{violet}{\rule{8pt}{8pt}}$ Other JS objs 23 MB 23 MB $\text{-56 B}$ 169 B
$\color{pink}{\rule{8pt}{8pt}}$ Other non-JS objs 41 KB 41 KB 0 B 0 B

Download representative heap snapshot: base / head

@github-actions

Copy link
Copy Markdown
Contributor

🖥 Frontend Diagnostics Report

(No significant changes)

View details

Requests by resource type
Type Requests Encoded bytes
Base Head Δ Base Head Δ
Document 2 2 0 33 KB 33 KB 0 B
Script 146 146 0 2 MB 2 MB 0 B
Stylesheet 57 57 0 280 KB 280 KB 0 B
Fetch 20 20 0 46 KB 46 KB 0 B
Image 10 10 0 254 KB 254 KB 0 B
Font 2 2 0 118 KB 118 KB 0 B
Other 9 9 0 421 KB 421 KB $\color{orange}{\text{+7 B}}$
V8 heap snapshot statistics
Metric @ Base @ Head Δ MAD
$\color{gray}{\rule{8pt}{8pt}}$ Total 11 MB
± 1.6 KB
11 MB
± 11 KB
$\text{-641 B}$
$\text{-0\%}$
11 KB
$\color{orange}{\rule{8pt}{8pt}}$ Code 2.8 MB 2.8 MB $\text{+156 B}$ 6.1 KB
$\color{red}{\rule{8pt}{8pt}}$ Strings 1.3 MB 1.3 MB $\text{+156 B}$ 252 B
$\color{cyan}{\rule{8pt}{8pt}}$ JS arrays 112 KB 112 KB 0 B 92 B
$\color{green}{\rule{8pt}{8pt}}$ Typed arrays 0 B 0 B 0 B 0 B
$\color{yellow}{\rule{8pt}{8pt}}$ System objects 0 B 0 B 0 B 0 B
$\color{violet}{\rule{8pt}{8pt}}$ Other JS objs 2 MB 2 MB $\text{+364 B}$ 1.5 KB
$\color{pink}{\rule{8pt}{8pt}}$ Other non-JS objs 4.9 MB 4.9 MB $\text{+2.4 KB}$ 16 KB

Download representative heap snapshot: base / head

📦 Bundle Stats

Chunk size diff (0 updated, 0 added, 0 removed)
Chunk Base Head Δ Δ (%)
(total) 6 MB 6 MB 0 B 0%
(other generated chunks) 2.1 MB 2.1 MB 0 B 0%
Startup chunk size (0 updated, 0 added, 0 removed)
Chunk Base Head Δ Δ (%)
(total) 1 MB 1 MB 0 B 0%
(other generated chunks) 718 KB 718 KB 0 B 0%
(other) 284 KB 284 KB 0 B 0%

Startup chunks are the Vite entry for src/_boot_.ts and its static imports.

Bundles Modules Entries Imports Size
Static Dynamic Rendered Gzip Brotli
Base 474 2,881 22 10,565 339 10 MB 2.8 MB 2.4 MB
Head 474 2,881 22 10,565 339 10 MB 2.8 MB 2.4 MB
Δ 0 0 0 0 0 0 B $\text{-10 B}$ $\text{-15 B}$
Δ (%) 0% 0% 0% 0% 0% 0% $\text{-0\%}$ $\text{-0\%}$

Open treemap HTML

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

Labels

packages/backend:test packages/backend Server side specific issue/PR

Projects

Status: Approved

Development

Successfully merging this pull request may close these issues.

HTTP/HTTPS用のproxy設定にipv6を指定するとRequestErrorが発生する

2 participants