mirror of
https://github.com/processone/ejabberd.git
synced 2024-09-29 14:37:44 +02:00
Return detailed error if HTTP upload is too large
If the file size specified in an HTTP upload slot request exceeds the the configured maximum size, include the limit with the stanza error.
This commit is contained in:
parent
43c3134f55
commit
ba30ac8ce8
@ -25,7 +25,7 @@
|
|||||||
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.22"}}},
|
{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.22"}}},
|
||||||
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.11"}}},
|
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.11"}}},
|
||||||
{fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.30"}}},
|
{fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.30"}}},
|
||||||
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "6e3feb7"}},
|
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "e26a39a"}},
|
||||||
{fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.14"}}},
|
{fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.14"}}},
|
||||||
{jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
|
{jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
|
||||||
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.3"}}},
|
{p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.3"}}},
|
||||||
|
@ -531,7 +531,8 @@ process_slot_request(#iq{lang = Lang, from = From} = IQ,
|
|||||||
case acl:match_rule(ServerHost, Access, From) of
|
case acl:match_rule(ServerHost, Access, From) of
|
||||||
allow ->
|
allow ->
|
||||||
ContentType = yield_content_type(CType),
|
ContentType = yield_content_type(CType),
|
||||||
case create_slot(State, From, File, Size, ContentType, Lang) of
|
case create_slot(State, From, File, Size, ContentType, XMLNS,
|
||||||
|
Lang) of
|
||||||
{ok, Slot} ->
|
{ok, Slot} ->
|
||||||
{ok, Timer} = timer:send_after(?SLOT_TIMEOUT,
|
{ok, Timer} = timer:send_after(?SLOT_TIMEOUT,
|
||||||
{slot_timed_out,
|
{slot_timed_out,
|
||||||
@ -552,21 +553,28 @@ process_slot_request(#iq{lang = Lang, from = From} = IQ,
|
|||||||
xmpp:make_error(IQ, xmpp:err_forbidden(Txt, Lang))
|
xmpp:make_error(IQ, xmpp:err_forbidden(Txt, Lang))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec create_slot(state(), jid(), binary(), pos_integer(), binary(), binary())
|
-spec create_slot(state(), jid(), binary(), pos_integer(), binary(), binary(),
|
||||||
|
binary())
|
||||||
-> {ok, slot()} | {ok, binary(), binary()} | {error, xmlel()}.
|
-> {ok, slot()} | {ok, binary(), binary()} | {error, xmlel()}.
|
||||||
create_slot(#state{service_url = undefined, max_size = MaxSize},
|
create_slot(#state{service_url = undefined, max_size = MaxSize},
|
||||||
JID, File, Size, _ContentType, Lang) when MaxSize /= infinity,
|
JID, File, Size, _ContentType, XMLNS, Lang)
|
||||||
Size > MaxSize ->
|
when MaxSize /= infinity,
|
||||||
|
Size > MaxSize ->
|
||||||
Text = {<<"File larger than ~w bytes">>, [MaxSize]},
|
Text = {<<"File larger than ~w bytes">>, [MaxSize]},
|
||||||
?INFO_MSG("Rejecting file ~s from ~s (too large: ~B bytes)",
|
?INFO_MSG("Rejecting file ~s from ~s (too large: ~B bytes)",
|
||||||
[File, jid:encode(JID), Size]),
|
[File, jid:encode(JID), Size]),
|
||||||
{error, xmpp:err_not_acceptable(Text, Lang)};
|
Error = xmpp:err_not_acceptable(Text, Lang),
|
||||||
|
Els = xmpp:get_els(Error),
|
||||||
|
Els1 = [#upload_file_too_large{'max-file-size' = MaxSize,
|
||||||
|
xmlns = XMLNS} | Els],
|
||||||
|
Error1 = xmpp:set_els(Error, Els1),
|
||||||
|
{error, Error1};
|
||||||
create_slot(#state{service_url = undefined,
|
create_slot(#state{service_url = undefined,
|
||||||
jid_in_url = JIDinURL,
|
jid_in_url = JIDinURL,
|
||||||
secret_length = SecretLength,
|
secret_length = SecretLength,
|
||||||
server_host = ServerHost,
|
server_host = ServerHost,
|
||||||
docroot = DocRoot},
|
docroot = DocRoot},
|
||||||
JID, File, Size, _ContentType, Lang) ->
|
JID, File, Size, _ContentType, _XMLNS, Lang) ->
|
||||||
UserStr = make_user_string(JID, JIDinURL),
|
UserStr = make_user_string(JID, JIDinURL),
|
||||||
UserDir = <<DocRoot/binary, $/, UserStr/binary>>,
|
UserDir = <<DocRoot/binary, $/, UserStr/binary>>,
|
||||||
case ejabberd_hooks:run_fold(http_upload_slot_request, ServerHost, allow,
|
case ejabberd_hooks:run_fold(http_upload_slot_request, ServerHost, allow,
|
||||||
@ -583,8 +591,8 @@ create_slot(#state{service_url = undefined,
|
|||||||
{error, Error}
|
{error, Error}
|
||||||
end;
|
end;
|
||||||
create_slot(#state{service_url = ServiceURL},
|
create_slot(#state{service_url = ServiceURL},
|
||||||
#jid{luser = U, lserver = S} = JID, File, Size, ContentType,
|
#jid{luser = U, lserver = S} = JID,
|
||||||
Lang) ->
|
File, Size, ContentType, _XMLNS, Lang) ->
|
||||||
Options = [{body_format, binary}, {full_result, false}],
|
Options = [{body_format, binary}, {full_result, false}],
|
||||||
HttpOptions = [{timeout, ?SERVICE_REQUEST_TIMEOUT}],
|
HttpOptions = [{timeout, ?SERVICE_REQUEST_TIMEOUT}],
|
||||||
SizeStr = integer_to_binary(Size),
|
SizeStr = integer_to_binary(Size),
|
||||||
|
@ -188,11 +188,14 @@ max_size_exceed(Config, NS) ->
|
|||||||
'content-type' = <<?CONTENT_TYPE>>,
|
'content-type' = <<?CONTENT_TYPE>>,
|
||||||
xmlns = NS}]})
|
xmlns = NS}]})
|
||||||
end,
|
end,
|
||||||
check_size_error(IQErr).
|
check_size_error(IQErr, Size, NS).
|
||||||
|
|
||||||
check_size_error(IQErr) ->
|
check_size_error(IQErr, Size, NS) ->
|
||||||
Err = xmpp:get_error(IQErr),
|
Err = xmpp:get_error(IQErr),
|
||||||
#stanza_error{reason = 'not-acceptable'} = Err.
|
FileTooLarge = xmpp:get_subtag(Err, #upload_file_too_large{xmlns = NS}),
|
||||||
|
#stanza_error{reason = 'not-acceptable'} = Err,
|
||||||
|
#upload_file_too_large{'max-file-size' = MaxSize} = FileTooLarge,
|
||||||
|
Size > MaxSize.
|
||||||
|
|
||||||
namespaces() ->
|
namespaces() ->
|
||||||
[?NS_HTTP_UPLOAD_0, ?NS_HTTP_UPLOAD, ?NS_HTTP_UPLOAD_OLD].
|
[?NS_HTTP_UPLOAD_0, ?NS_HTTP_UPLOAD, ?NS_HTTP_UPLOAD_OLD].
|
||||||
|
Loading…
Reference in New Issue
Block a user