Skip to content

Commit b648f20

Browse files
ddollargaryburd
authored andcommitted
Use ASCII case folding in same origin test
1 parent 23059f2 commit b648f20

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func checkSameOrigin(r *http.Request) bool {
7676
if err != nil {
7777
return false
7878
}
79-
return u.Host == r.Host
79+
return equalASCIIFold(u.Host, r.Host)
8080
}
8181

8282
func (u *Upgrader) selectSubprotocol(r *http.Request, responseHeader http.Header) string {

server_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,21 @@ func TestIsWebSocketUpgrade(t *testing.T) {
4949
}
5050
}
5151
}
52+
53+
var checkSameOriginTests = []struct {
54+
ok bool
55+
r *http.Request
56+
}{
57+
{false, &http.Request{Host: "example.org", Header: map[string][]string{"Origin": []string{"https://other.org"}}}},
58+
{true, &http.Request{Host: "example.org", Header: map[string][]string{"Origin": []string{"https://example.org"}}}},
59+
{true, &http.Request{Host: "Example.org", Header: map[string][]string{"Origin": []string{"https://example.org"}}}},
60+
}
61+
62+
func TestCheckSameOrigin(t *testing.T) {
63+
for _, tt := range checkSameOriginTests {
64+
ok := checkSameOrigin(tt.r)
65+
if tt.ok != ok {
66+
t.Errorf("checkSameOrigin(%+v) returned %v, want %v", tt.r, ok, tt.ok)
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)