diff --git a/lib/phoenix/socket/transport.ex b/lib/phoenix/socket/transport.ex index 26fa16f54d..0cc8ddd2b4 100644 --- a/lib/phoenix/socket/transport.ex +++ b/lib/phoenix/socket/transport.ex @@ -624,7 +624,7 @@ defmodule Phoenix.Socket.Transport do defp compare_host?(_request_host, nil), do: true defp compare_host?(request_host, "*." <> allowed_host), - do: String.ends_with?(request_host, allowed_host) + do: request_host == allowed_host or String.ends_with?(request_host, "." <> allowed_host) defp compare_host?(request_host, allowed_host), do: request_host == allowed_host diff --git a/test/phoenix/socket/transport_test.exs b/test/phoenix/socket/transport_test.exs index 74f642daca..59bb9b311a 100644 --- a/test/phoenix/socket/transport_test.exs +++ b/test/phoenix/socket/transport_test.exs @@ -85,6 +85,12 @@ defmodule Phoenix.Socket.TransportTest do refute conn.halted conn = check_origin("https://org1.ex.com", check_origin: origins) refute conn.halted + + conn = check_origin("https://ex.com", check_origin: origins) + refute conn.halted + + conn = check_origin("https://org1.prefix-ex.com", check_origin: origins) + assert conn.halted end test "nested wildcard subdomains" do @@ -93,6 +99,15 @@ defmodule Phoenix.Socket.TransportTest do conn = check_origin("http://org1.foo.example.com", check_origin: origins) refute conn.halted + conn = check_origin("http://foo.example.com", check_origin: origins) + refute conn.halted + + conn = check_origin("http://bad.example.com", check_origin: origins) + assert conn.halted + + conn = check_origin("http://org1.prefix-foo.example.com", check_origin: origins) + assert conn.halted + conn = check_origin("http://org1.bar.example.com", check_origin: origins) assert conn.halted assert conn.status == 403