]> granicus.if.org Git - ejabberd/commitdiff
mod_http_upload: Case-insensitive host comparison
authorHolger Weiss <holger@zedat.fu-berlin.de>
Sun, 12 May 2019 09:57:17 +0000 (11:57 +0200)
committerHolger Weiss <holger@zedat.fu-berlin.de>
Sun, 12 May 2019 09:57:17 +0000 (11:57 +0200)
Perform a case-insensitive lookup of the host name specified by the HTTP
client.

Fixes #2827.

src/mod_http_upload.erl

index b3600e7094f5d9fdc4683b350fb2bea8ad2ab089..c1013fe77835b068a108d3d694458fefc2c2d4a4 100644 (file)
@@ -508,9 +508,12 @@ process(_LocalPath, #request{method = Method, host = Host, ip = IP}) ->
 -spec get_proc_name(binary(), atom()) -> atom().
 get_proc_name(ServerHost, ModuleName) ->
     PutURL = gen_mod:get_module_opt(ServerHost, ?MODULE, put_url),
-    {ok, {_Scheme, _UserInfo, Host, _Port, Path, _Query}} =
+    %% Once we depend on OTP >= 20.0, we can use binaries with http_uri.
+    {ok, {_Scheme, _UserInfo, Host0, _Port, Path0, _Query}} =
        http_uri:parse(binary_to_list(expand_host(PutURL, ServerHost))),
-    ProcPrefix = list_to_binary(string:strip(Host ++ Path, right, $/)),
+    Host = jid:nameprep(iolist_to_binary(Host0)),
+    Path = str:strip(iolist_to_binary(Path0), right, $/),
+    ProcPrefix = <<Host/binary, Path/binary>>,
     gen_mod:get_module_proc(ProcPrefix, ModuleName).
 
 -spec expand_home(binary()) -> binary().
@@ -762,7 +765,8 @@ iq_disco_info(Host, Lang, Name, AddInfo) ->
 %% HTTP request handling.
 
 -spec parse_http_request(#request{}) -> {atom(), slot()}.
-parse_http_request(#request{host = Host, path = Path}) ->
+parse_http_request(#request{host = Host0, path = Path}) ->
+    Host = jid:nameprep(Host0),
     PrefixLength = length(Path) - 3,
     {ProcURL, Slot} = if PrefixLength > 0 ->
                              Prefix = lists:sublist(Path, PrefixLength),