Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

loopdb: postgres password with URL-reserved characters breaks the connection

Đang mở Phù hợp với người mới
#1,246 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go, postgres
Lĩnh vực
databases

Hướng nghiên cứu

Bắt đầu từ PostgresConfig.DSN và kiểm tra cách DSN hiện tại được ghép và ghi log. Bổ sung phần kiểm thử dạng bảng được yêu cầu cho các mật khẩu chứa các ký tự dành riêng cho URL, bao gồm việc phân tích kết quả bằng net/url, và chạy các bài kiểm thử Go liên quan. Được xem là hoàn tất khi user, password, host và database sau khi phân tích vẫn không thay đổi, bao gồm cả việc xử lý host IPv6.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Title: loopdb: postgres password with URL-reserved characters breaks the connection

Background

PostgresConfig.DSN builds the connection string with fmt.Sprintf, putting the user and password into the URL without escaping them:

dsnTemplate = "postgres://%v:%v@%v:%d/%v?sslmode=%v"

pgx parses this string with net/url, so any URL-reserved character in the password changes how the URL is parsed. For example, / ends the authority section early, so with --postgres.password=ab/cd the string becomes:

postgres://loop:ab/cd@localhost:5432/loop?sslmode=disable

This parses as host loop:ab and path /cd@localhost:5432/loop, so loopd fails to connect. #, ? and % cause similar failures.

Passwords made with common tools such as openssl rand -base64 often contain /. #1088 adds a way to read the password from a file, which encourages exactly this kind of generated password, so this is likely to come up more often.

Proposed fix

Build the DSN with net/url so each part is escaped correctly:

dsn := url.URL{
	Scheme:   "postgres",
	User:     url.UserPassword(s.User, password),
	Host:     net.JoinHostPort(s.Host, strconv.Itoa(s.Port)),
	Path:     s.DBName,
	RawQuery: url.Values{"sslmode": {sslMode}}.Encode(),
}

net.JoinHostPort also brackets IPv6 host literals correctly, which the current template doesn't do. The hidePassword placeholder used when logging stays as it is.

Add a table-driven test for DSN that runs passwords containing /, @, :, #, ?, % and spaces through url.Parse and checks that the user, password, host and database come back unchanged.

Ngôn ngữ chính
Go
Star
593
Fork
138
Merge trung bình
4 ngày 18 giờ
Pull request đã merge (30 ngày)
20

Chuẩn bị môi trường

  • Có Dockerfile hoặc tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của lightninglabs/loop

Tất cả issue của lightninglabs/loop

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.