Skip to content

Commit b47a7e8

Browse files
committed
fix: enhance safe redirect handling in util module to preserve query parameters
1 parent 6e8c776 commit b47a7e8

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/algora_web/util.ex

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,23 @@ defmodule AlgoraWeb.Util do
99
def build_safe_redirect(url) do
1010
app_host = AlgoraWeb.Endpoint.host()
1111

12-
case URI.parse(url) do
12+
uri = URI.parse(url)
13+
query = if uri.query, do: "?#{uri.query}", else: ""
14+
15+
case uri do
1316
%URI{host: nil, path: nil} ->
14-
[to: ~p"/"]
17+
[to: ~p"/#{query}"]
1518

1619
%URI{host: host, path: path} when is_nil(host) or host == app_host ->
17-
[to: path]
20+
[to: "#{path}#{query}"]
1821

1922
%URI{host: host} ->
2023
case host |> String.split(".") |> Enum.take(-2) |> Enum.join(".") do
2124
"algora.io" -> [external: url]
2225
"algora.tv" -> [external: url]
2326
"stripe.com" -> [external: url]
2427
"github.com" -> [external: url]
25-
_ -> [to: ~p"/"]
28+
_ -> [to: ~p"/#{query}"]
2629
end
2730
end
2831
rescue

0 commit comments

Comments
 (0)