Skip to content

Commit

Permalink
mod_spam_filter: resolve http redirects so we're not fooled by url sh…
Browse files Browse the repository at this point in the history
…orteners
  • Loading branch information
sstrigler committed Jan 8, 2025
1 parent 9e747bf commit 9bae343
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion mod_spam_filter/src/mod_spam_filter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,28 @@ extract_urls(Body) ->
Options = [global, {capture, all, binary}],
case re:run(Body, RE, Options) of
{match, Captured} when is_list(Captured) ->
{urls, lists:flatten(Captured)};
Urls = resolve_redirects(lists:flatten(Captured), []),
{urls, Urls};
nomatch ->
none
end.

-spec resolve_redirects([url()], [url()]) -> [url()].
resolve_redirects([], Result) -> Result;
resolve_redirects([Url | Rest], Acc) ->
case httpc:request(get, {Url, [{"user-agent", "curl/8.7.1"}]}, [{autoredirect, false}], []) of
{ok, {{_, Moved, _}, Headers, _Body}} when Moved >= 300, Moved < 400 ->
Location = proplists:get_value("location", Headers),
case lists:member(Location, Acc) of
false ->
resolve_redirects([Location | Rest], [Url | Acc]);
true ->
resolve_redirects(Rest, [Url | Acc])
end;
_Res ->
resolve_redirects(Rest, [Url | Acc])
end.

-spec extract_jids(binary()) -> {jids, [ljid()]} | none.
extract_jids(Body) ->
RE = <<"\\S+@\\S+">>,
Expand Down

0 comments on commit 9bae343

Please sign in to comment.