Merge pull request #6936 from terry-xiaoyu/empty_rule_id

fix(rule): deny POST empty rule ids
This commit is contained in:
Shawn 2022-02-09 10:16:27 +08:00 committed by GitHub
commit ce05c14ef2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 15 deletions

View File

@ -199,7 +199,10 @@ param_path_id() ->
{200, format_rule_resp(Records)}; {200, format_rule_resp(Records)};
'/rules'(post, #{body := Params0}) -> '/rules'(post, #{body := Params0}) ->
Id = maps:get(<<"id">>, Params0, list_to_binary(emqx_misc:gen_id(8))), case maps:get(<<"id">>, Params0, list_to_binary(emqx_misc:gen_id(8))) of
<<>> ->
{400, #{code => 'BAD_ARGS', message => <<"empty rule id is not allowed">>}};
Id ->
Params = filter_out_request_body(Params0), Params = filter_out_request_body(Params0),
ConfPath = emqx_rule_engine:config_key_path() ++ [Id], ConfPath = emqx_rule_engine:config_key_path() ++ [Id],
case emqx_rule_engine:get_rule(Id) of case emqx_rule_engine:get_rule(Id) of
@ -215,6 +218,7 @@ param_path_id() ->
id => Id, reason => Reason}), id => Id, reason => Reason}),
{400, #{code => 'BAD_ARGS', message => ?ERR_BADARGS(Reason)}} {400, #{code => 'BAD_ARGS', message => ?ERR_BADARGS(Reason)}}
end end
end
end. end.
'/rule_test'(post, #{body := Params}) -> '/rule_test'(post, #{body := Params}) ->