mirror of
https://github.com/processone/ejabberd
synced 2025-10-03 17:59:31 +02:00
mod_http_upload: Encode URLs into IDNA when showing to XMPP client (#3519)
This commit is contained in:
parent
e5da1efea4
commit
bba1a1e3ca
1 changed files with 18 additions and 4 deletions
|
@ -533,7 +533,8 @@ process(LocalPath, #request{method = Method, host = Host, ip = IP})
|
||||||
[Method, encode_addr(IP), Host]),
|
[Method, encode_addr(IP), Host]),
|
||||||
http_response(404);
|
http_response(404);
|
||||||
process(_LocalPath, #request{method = 'PUT', host = Host, ip = IP,
|
process(_LocalPath, #request{method = 'PUT', host = Host, ip = IP,
|
||||||
length = Length} = Request) ->
|
length = Length} = Request0) ->
|
||||||
|
Request = Request0#request{host = redecode_url(Host)},
|
||||||
{Proc, Slot} = parse_http_request(Request),
|
{Proc, Slot} = parse_http_request(Request),
|
||||||
try gen_server:call(Proc, {use_slot, Slot, Length}, ?CALL_TIMEOUT) of
|
try gen_server:call(Proc, {use_slot, Slot, Length}, ?CALL_TIMEOUT) of
|
||||||
{ok, Path, FileMode, DirMode, GetPrefix, Thumbnail, CustomHeaders} ->
|
{ok, Path, FileMode, DirMode, GetPrefix, Thumbnail, CustomHeaders} ->
|
||||||
|
@ -573,9 +574,10 @@ process(_LocalPath, #request{method = 'PUT', host = Host, ip = IP,
|
||||||
[encode_addr(IP), Host, Error]),
|
[encode_addr(IP), Host, Error]),
|
||||||
http_response(500)
|
http_response(500)
|
||||||
end;
|
end;
|
||||||
process(_LocalPath, #request{method = Method, host = Host, ip = IP} = Request)
|
process(_LocalPath, #request{method = Method, host = Host, ip = IP} = Request0)
|
||||||
when Method == 'GET';
|
when Method == 'GET';
|
||||||
Method == 'HEAD' ->
|
Method == 'HEAD' ->
|
||||||
|
Request = Request0#request{host = redecode_url(Host)},
|
||||||
{Proc, [_UserDir, _RandDir, FileName] = Slot} = parse_http_request(Request),
|
{Proc, [_UserDir, _RandDir, FileName] = Slot} = parse_http_request(Request),
|
||||||
try gen_server:call(Proc, get_conf, ?CALL_TIMEOUT) of
|
try gen_server:call(Proc, get_conf, ?CALL_TIMEOUT) of
|
||||||
{ok, DocRoot, CustomHeaders} ->
|
{ok, DocRoot, CustomHeaders} ->
|
||||||
|
@ -909,8 +911,8 @@ mk_slot(Slot, #state{put_url = PutPrefix, get_url = GetPrefix}, XMLNS, Query) ->
|
||||||
GetURL = str:join([GetPrefix | Slot], <<$/>>),
|
GetURL = str:join([GetPrefix | Slot], <<$/>>),
|
||||||
mk_slot(PutURL, GetURL, XMLNS, Query);
|
mk_slot(PutURL, GetURL, XMLNS, Query);
|
||||||
mk_slot(PutURL, GetURL, XMLNS, Query) ->
|
mk_slot(PutURL, GetURL, XMLNS, Query) ->
|
||||||
PutURL1 = <<(misc:url_encode(PutURL))/binary, Query/binary>>,
|
PutURL1 = <<(reencode_url(PutURL))/binary, Query/binary>>,
|
||||||
GetURL1 = misc:url_encode(GetURL),
|
GetURL1 = reencode_url(GetURL),
|
||||||
case XMLNS of
|
case XMLNS of
|
||||||
?NS_HTTP_UPLOAD_0 ->
|
?NS_HTTP_UPLOAD_0 ->
|
||||||
#upload_slot_0{get = GetURL1, put = PutURL1, xmlns = XMLNS};
|
#upload_slot_0{get = GetURL1, put = PutURL1, xmlns = XMLNS};
|
||||||
|
@ -918,6 +920,18 @@ mk_slot(PutURL, GetURL, XMLNS, Query) ->
|
||||||
#upload_slot{get = GetURL1, put = PutURL1, xmlns = XMLNS}
|
#upload_slot{get = GetURL1, put = PutURL1, xmlns = XMLNS}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
reencode_url(UrlString) ->
|
||||||
|
{ok, _, _, Host, _, _, _} = yconf:parse_uri(UrlString),
|
||||||
|
HostDecoded = misc:uri_decode(Host),
|
||||||
|
HostIdna = idna:encode(HostDecoded),
|
||||||
|
re:replace(UrlString, Host, HostIdna, [{return, binary}]).
|
||||||
|
|
||||||
|
redecode_url(UrlString) ->
|
||||||
|
{ok, _, _, HostIdna, _, _, _} = yconf:parse_uri(<<"http://", UrlString/binary>>),
|
||||||
|
HostDecoded = idna:decode(HostIdna),
|
||||||
|
Host = misc:uri_quote(HostDecoded),
|
||||||
|
re:replace(UrlString, HostIdna, Host, [{return, binary}]).
|
||||||
|
|
||||||
-spec make_user_string(jid(), sha1 | node) -> binary().
|
-spec make_user_string(jid(), sha1 | node) -> binary().
|
||||||
make_user_string(#jid{luser = U, lserver = S}, sha1) ->
|
make_user_string(#jid{luser = U, lserver = S}, sha1) ->
|
||||||
str:sha(<<U/binary, $@, S/binary>>);
|
str:sha(<<U/binary, $@, S/binary>>);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue