database: PostgreSQL DSN breaks IPv6 hosts and Validate accepts out-of-range ports
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 67/100
調査の方向性
Locate PostgresConfig.DSN(), PostgresConfig.Validate(), MySQLConfig.Validate(), and the existing MySQLConfig.DSN() implementation in the database package. Read those methods and their tests first; the issue gives the IPv6 and port cases to cover. Done means PostgreSQL DSNs parse for the listed host forms, both validators reject ports below 0 or above 65535 while accepting 0, and the database tests pass.
索引モデルが issue の本文から書いたものです。
説明
Describe the Bug
PostgresConfig.DSN() builds an invalid URL when Host is an IPv6 address, and Validate() accepts any port.
- IPv6 hosts:
DSN()joins the host and port withfmt.Sprintf("%s:%d", c.Host, c.Port). ForHost: "::1", Port: 5432the URL host is::1:5432, which pgx rejects ("too many colons in address"), soNewfails. IPv4-mapped literals such as::ffff:10.0.0.1fail the same way.MySQLConfig.DSN()already usesnet.JoinHostPort, so only PostgreSQL is affected. - Out-of-range ports:
PostgresConfig.Validate()andMySQLConfig.Validate()don't checkPort, so a negative port or one above 65535 passes validation and fails later, at connect time, with a driver error. A port of 0 (omitted) is documented as "use the driver default" and is fine.
To Reproduce
cfg := database.PostgresConfig{
Host: "::1", Port: 5432, User: "postgres", Password: "secret",
Name: "app", SSLMode: "disable",
}
fmt.Println(cfg.Validate()) // <nil>
_, err := pgconn.ParseConfig(cfg.DSN())
fmt.Println(err)
// cannot parse `postgres://postgres:xxxxx@::1:5432/app?sslmode=disable`: failed to parse as URL
// (failed to split host:port in '::1:5432', err: address ::1:5432: too many colons in address)
cfg.Host, cfg.Port = "localhost", 70000
fmt.Println(cfg.Validate()) // <nil>
Expected Behavior
DSN()brackets IPv6 hosts, e.g.postgres://...@[::1]:5432/app, by usingnet.JoinHostPortasMySQLConfig.DSN()does. A host with no port that is an IPv6 literal is bracketed too ([::1]).Validate()for PostgreSQL and MySQL rejects ports below 0 or above 65535. 0 keeps meaning "driver default".- A test parses
DSN()withpgconn.ParseConfigfor a hostname, IPv4, IPv6, an IPv4-mapped IPv6 address, and an already-bracketed[::1], with and without a port.
Screenshots
N/A
Version
database/v0.3.0
Environment Details (with versions)
Go 1.26, pgx v5, PostgreSQL 16
Additional Context
Found while moving the OpenNDX Portal Backend onto this package (openndx/openndx-core#688). The PB's old hand-built keyword DSN accepted host=::1, so this is a small regression for OpenNDX deployments that use an IPv6 database address. OpenNDX will bump the dependency once a fix is released, rather than work around it in each service.
- 主要言語
- Go
- スター
- 6
- フォーク
- 8
- 平均マージ
- 21時間 36分
- マージ済み PR(30日)
- 42
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
OpenNSW/core のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
payment: test fixtures hardcode real gateway names (govpay/lankapay) instead of generic placeholdersオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
nsw-sl cleanup Type/Improvement
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
メンテナーはふだん 1 日以内に返信
-
remote: let the host inject a logger, and log with one consistent policy対応中かも @mushrafmim が 5 日前に担当しました。 オープンType/Improvement
難易度 4/5 3〜5日 初心者へのやさしさ 22/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
☢️ Bug v3
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
area/import-export area/projects concern/ux
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
go-vikunja/vikunja#4455 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
Dependabot PRs no longer merge automatically対応中かも @dwisiswant0 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
projectdiscovery/urlfinder#160 ·
メンテナーはふだん 1 日以内に返信
-
database
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
chnm/legal-modernism#450 ·
メンテナーはふだん 1 日以内に返信
-
tech-debt
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信