Skip to content

Commit 3444ac7

Browse files
committed
Stop redirect loops
Stop redirects if the server path equals redirect prefix path. This stops redirect loops.
1 parent 442f1ec commit 3444ac7

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/yaws_server.erl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,8 +2704,11 @@ deliver_redirect_map(CliSock, Req, Arg,
27042704
%% Here Code is 1xx, 2xx, 4xx or 5xx
27052705
?Debug("in redir ~p", [Code]),
27062706
deliver_xxx(CliSock, Req, Arg, Code);
2707-
deliver_redirect_map(_CliSock, _Req, Arg,
2708-
{_Prefix, Code, Path, Mode}, N) when is_list(Path) ->
2707+
deliver_redirect_map(_CliSock, #http_request{path = {abs_path, ReqPath}}, Arg,
2708+
{Prefix, Code, Path, Mode}, N)
2709+
when is_list(Path) andalso
2710+
%% Stop redirect loops
2711+
ReqPath /= Prefix ->
27092712
%% Here Code is 1xx, 2xx, 4xx or 5xx
27102713
?Debug("in redir ~p", [Code]),
27112714
Path1 = if
@@ -2725,8 +2728,13 @@ deliver_redirect_map(_CliSock, _Req, Arg,
27252728
put(yaws_arg, Arg),
27262729
put(client_data_pos, N),
27272730
{page, {[{status, Code}], Page}};
2728-
deliver_redirect_map(CliSock, Req, Arg,
2729-
{_Prefix, Code, URL, Mode}, N) when is_record(URL, url) ->
2731+
deliver_redirect_map(CliSock,
2732+
#http_request{path = {abs_path, ReqPath}} = Req, Arg,
2733+
{Prefix, Code, URL, Mode}, N)
2734+
when is_record(URL, url)
2735+
andalso
2736+
%% Stop redirect loops
2737+
ReqPath == Prefix ->
27302738
%% Here Code is 3xx
27312739
?Debug("in redir ~p", [Code]),
27322740
H = get(outh),

0 commit comments

Comments
 (0)