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

Reconsider and document redirect policy

Đang mở
#518 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

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

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
go
Lĩnh vực
api, networking

Hướng nghiên cứu

Bắt đầu với dial.go ở các dòng 76-103 và tài liệu thư viện mô tả DialOptions, sau đó so sánh hành vi chuyển hướng với đặc tả WebSocket được trích dẫn và các giới hạn của WASM. Làm rõ và ghi lại chính sách hiện tại, đồng thời xác định liệu giá trị mặc định có nên thay đổi trong một phiên bản tương lai hay không; issue #333 liên quan cung cấp thêm ngữ cảnh.

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

Mô tả

The problem

It looks like that by default the library uses the default HTTPClient:

https://github.com/coder/websocket/blob/d1468a75eee5525d183123766fbf288dca1eed9b/dial.go#L76-L103

And the default HTTP client does follow redirects:

// If CheckRedirect is nil, the Client uses its default policy,
// which is to stop after 10 consecutive requests.

Edit: actually, doesn't the fact that we do specify a CheckRedirect function mean that we do not stop after 10 consecutive requests?

I am aware that it is possible to provide your own HTTPClient struct to the Dial() function, and it is nice to rely on built-in defaults, I think a WebSocket library should be more concrete in this regard. Especially given the fact that this particular one claims to be able to target WASM. And, according to the browser WebSocket spec, redirects are not followed:

redirect mode is "error"

The reason redirects are not followed and this handshake is generally restricted is because it could introduce serious security problems in a web browser context. For example, consider a host with a WebSocket server at one path and an open HTTP redirector at another. Suddenly, any script that can be given a particular WebSocket URL can be tricked into communicating to (and potentially sharing secrets with) any host on the internet, even if the script checks that the URL has the right hostname.

This IMO can be considered an inconsistency between different targets.
Note that changing redirect policy for the WASM version is not possible, according to this library's docs:

HTTPClient, HTTPHeader and CompressionMode in DialOptions are no-op


For reference, the WebSocket spec itself states:

the server might redirect the client using a 3xx status code (but clients are not required to follow them)

Also for reference, the Gorilla WebSocket library IMU does not follow redirects, see this issue: https://github.com/gorilla/websocket/pull/965 and the code.

Suggested solution

  1. Document that the library follows redirects, but not in the WASM version.
  2. For the next version: Do not follow redirects by default, and document this.
    This can either be considered a breaking change (so it goes to v2.x.x), or a bug fix.

Related issue: https://github.com/coder/websocket/issues/333

Ngôn ngữ chính
Go
Star
5.5k
Fork
377
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

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 coder/websocket

Tất cả issue của coder/websocket

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.