rpc: remove default origin for client connections

The client used to put the local hostname into the Origin header because
the server wanted an origin to accept the connection, but that's silly:
Origin is for browsers/websites. The nobody would whitelist a particular
hostname.

Now that the server doesn't need Origin anymore, don't bother setting
one for clients. Users who need an origin can use DialWebsocket to
create a client with arbitrary origin if needed.
This commit is contained in:
Felix Lange 2019-07-19 15:57:57 +02:00
parent a27c950996
commit 376178b961
2 changed files with 2 additions and 14 deletions

View file

@ -140,18 +140,6 @@ func wsClientHeaders(endpoint, origin string) (string, http.Header, error) {
if err != nil { if err != nil {
return endpoint, nil, err return endpoint, nil, err
} }
if origin == "" {
var err error
if origin, err = os.Hostname(); err != nil {
return endpoint, nil, err
}
if endpointURL.Scheme == "wss" {
origin = "https://" + strings.ToLower(origin)
} else {
origin = "http://" + strings.ToLower(origin)
}
}
header := make(http.Header) header := make(http.Header)
header.Add("origin", origin) header.Add("origin", origin)
if endpointURL.User != nil { if endpointURL.User != nil {

View file

@ -31,7 +31,7 @@ import (
func TestWebsocketClientHeaders(t *testing.T) { func TestWebsocketClientHeaders(t *testing.T) {
t.Parallel() t.Parallel()
endpoint, header, err := wsClientHeaders("wss://testuser:test-PASS_01@example.com:1234", "") endpoint, header, err := wsClientHeaders("wss://testuser:test-PASS_01@example.com:1234", "https://example.com")
if err != nil { if err != nil {
t.Fatalf("wsGetConfig failed: %s", err) t.Fatalf("wsGetConfig failed: %s", err)
} }
@ -41,7 +41,7 @@ func TestWebsocketClientHeaders(t *testing.T) {
if header.Get("authorization") != "Basic dGVzdHVzZXI6dGVzdC1QQVNTXzAx" { if header.Get("authorization") != "Basic dGVzdHVzZXI6dGVzdC1QQVNTXzAx" {
t.Fatal("Basic auth header is incorrect") t.Fatal("Basic auth header is incorrect")
} }
if header.Get("origin") == "" { if header.Get("origin") != "https://example.com" {
t.Fatal("Origin not set") t.Fatal("Origin not set")
} }
} }