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 path. This stops
redirect loops.
  • Loading branch information
avtobiff committed Jan 15, 2025
1 parent 442f1ec commit 724a0c9
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/yaws_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2704,14 +2704,17 @@ 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, _Req, #arg{server_path = ServerPath} = Arg,
{_Prefix, Code, Path, Mode}, N)
when is_list(Path) andalso
%% Stop redirect loops
ServerPath /= Path ->
%% Here Code is 1xx, 2xx, 4xx or 5xx
?Debug("in redir ~p", [Code]),
Path1 = if
Mode == append ->
filename:join([Path ++ Arg#arg.server_path]) ++
preserve_trailing_slash(Arg#arg.server_path);
filename:join([Path ++ ServerPath]) ++
preserve_trailing_slash(ServerPath);
true -> %% noappend
Path
end,
Expand All @@ -2725,8 +2728,10 @@ 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, Req, #arg{server_path = ServerPath} = Arg,
{_Prefix, Code, #url{path = Path} = URL, Mode}, N)
when %% Stop redirect loops
ServerPath /= Path ->
%% Here Code is 3xx
?Debug("in redir ~p", [Code]),
H = get(outh),
Expand All @@ -2736,8 +2741,8 @@ deliver_redirect_map(CliSock, Req, Arg,
end,
LocPath = if
Mode == append ->
Path1 = filename:join([URL#url.path ++ Arg#arg.server_path]) ++
preserve_trailing_slash(Arg#arg.server_path),
Path1 = filename:join([Path ++ ServerPath]) ++
preserve_trailing_slash(ServerPath),
yaws_api:format_partial_url(
URL#url{path=Path1,querypart=QueryData}, get(sc)
);
Expand Down

0 comments on commit 724a0c9

Please sign in to comment.