Skip to content

Commit

Permalink
Stop redirect loops
Browse files Browse the repository at this point in the history
Stop redirects if the server path equals redirect prefix path. This
stops redirect loops.
  • Loading branch information
avtobiff committed Jan 15, 2025
1 parent 442f1ec commit 3444ac7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/yaws_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2704,8 +2704,11 @@ deliver_redirect_map(CliSock, Req, Arg,
%% Here Code is 1xx, 2xx, 4xx or 5xx
?Debug("in redir ~p", [Code]),
deliver_xxx(CliSock, Req, Arg, Code);
deliver_redirect_map(_CliSock, _Req, Arg,
{_Prefix, Code, Path, Mode}, N) when is_list(Path) ->
deliver_redirect_map(_CliSock, #http_request{path = {abs_path, ReqPath}}, Arg,
{Prefix, Code, Path, Mode}, N)
when is_list(Path) andalso
%% Stop redirect loops
ReqPath /= Prefix ->
%% Here Code is 1xx, 2xx, 4xx or 5xx
?Debug("in redir ~p", [Code]),
Path1 = if
Expand All @@ -2725,8 +2728,13 @@ deliver_redirect_map(_CliSock, _Req, Arg,
put(yaws_arg, Arg),
put(client_data_pos, N),
{page, {[{status, Code}], Page}};
deliver_redirect_map(CliSock, Req, Arg,
{_Prefix, Code, URL, Mode}, N) when is_record(URL, url) ->
deliver_redirect_map(CliSock,
#http_request{path = {abs_path, ReqPath}} = Req, Arg,
{Prefix, Code, URL, Mode}, N)
when is_record(URL, url)
andalso
%% Stop redirect loops
ReqPath == Prefix ->
%% Here Code is 3xx
?Debug("in redir ~p", [Code]),
H = get(outh),
Expand Down

0 comments on commit 3444ac7

Please sign in to comment.