processone / ejabberd

Robust, Ubiquitous and Massively Scalable Messaging Platform (XMPP, MQTT, SIP Server)
https://www.process-one.net/en/ejabberd/
Other
6k stars 1.5k forks source link

[BUG] mod_http_api /api/srg_get_info - bad request 400 #4242

Open sando38 opened 2 days ago

sando38 commented 2 days ago

Environment

Bug description

curl -k -X POST -H "Content-type: application/json" \
  -d '{"group": "account_32775", "host": "quodarca.net"}' \
  "http://127.0.0.1:5280/api/v0/srg_get_info"
2024-07-02 10:03:15.986425+00:00 [debug] <0.2857.0>@ejabberd_http:process_header/2:291 (#Port<0.1833>) http query: 'POST' <<"/api/v0/srg_get_info">> |  
-- | --
  |   |   |  
  |   | 2024-07-02 10:03:15.986546+00:00 [debug] <0.2857.0>@ejabberd_http:process/1:363 [<<"api">>,<<"v0">>,<<"srg_get_info">>] matches [<<"api">>,<<"v0">>] |  
  |   | 2024-07-02 10:03:15.986706+00:00 [info] <0.2857.0>@mod_http_api:log/3:516 API call srg_get_info [{<<"group">>,<<"account_32775">>}, |  
  |   | {<<"host">>,<<"quodarca.net">>}] from ::ffff:127.0.0.1:37612 |  
  |   | 2024-07-02 10:03:15.987034+00:00 [debug] <0.2857.0>@ejabberd_access_permissions:can_access/2:84 Command 'srg_get_info' execution allowed by rule 'console commands' |  
  |   | (CallerInfo=#{tag => <<>>, |  
  |   | ip => {0,0,0,0,0,65535,32512,1}, |  
  |   | caller_module => mod_http_api}) |  
  |   | 2024-07-02 10:03:15.987217+00:00 [debug] <0.2857.0>@ejabberd_commands:do_execute_command/2:286 Executing command mod_admin_extra:srg_get_info with Args=[<<"account_32775">>, |  
  |   | <<"quodarca.net">>] |  
  |   | 2024-07-02 10:03:15.987586+00:00 [debug] <0.874.0>@ejabberd_sql:sql_query_internal/1:728 SQL: "select opts from sr_group where name=E'account_32775' and 0=0" |  
  |   | 2024-07-02 10:03:15.989467+00:00 [debug] <0.2857.0>@mod_http_api:process/2:153 Bad Request: {unsupported_type,{[{<<"key">>,<<"label">>}, |  
  |   | {<<"value">>,<<"account_32775">>}]}} [{json, |  
  |   | do_encode, |  
  |   | 2, |  
  |   | [{file, |  
  |   | "json.erl"}, |  
  |   | {line, |  
  |   | 193}]}, |  
  |   | {json, |  
  |   | do_encode_list, |  
  |   | 2, |  
  |   | [{file, |  
  |   | "json.erl"}, |  
  |   | {line, |  
  |   | 235}]}, |  
  |   | {misc, |  
  |   | json_encode, |  
  |   | 1, |  
  |   | [{file, |  
  |   | "src/misc.erl"}, |  
  |   | {line, |  
  |   | 141}]}, |  
  |   | {mod_http_api, |  
  |   | json_format, |  
  |   | 1, |  
  |   | [{file, |  
  |   | "src/mod_http_api.erl"}, |  
  |   | {line, |  
  |   | 498}]}, |  
  |   | {mod_http_api, |  
  |   | process, |  
  |   | 2, |  
  |   | [{file, |  
  |   | "src/mod_http_api.erl"}, |  
  |   | {line, |  
  |   | 143}]}, |  
  |   | {ejabberd_http, |  
  |   | process, |  
  |   | 2, |  
  |   | [{file, |  
  |   | "src/ejabberd_http.erl"}, |  
  |   | {line, |  
  |   | 375}]}, |  
  |   | {ejabberd_http, |  
  |   | process_request, |  
  |   | 1, |  
  |   | [{file, |  
  |   | "src/ejabberd_http.erl"}, |  
  |   | {line, |  
  |   | 505}]}, |  
  |   | {ejabberd_http, |  
  |   | process_header, |  
  |   | 2, |  
  |   | [{file, |  
  |   | "src/ejabberd_http.erl"}, |  
  |   | {line, |  
  |   | 294}]}]

Hello, using the srg_get_info command with mod_http_api leads to bad request 400 messages. Sorry for the ugly log output of the debug log (see above).

The error only occurs with Erlang 27, when running with Erlang 26.2 it works fine.

Thanks, Saarko

badlop commented 2 days ago

The problem when using OTP 27 happens when encoding result into JSON using the OTP json library; when using OTP 26 or older it uses jiffy and works correctly. Let me see...

badlop commented 8 hours ago

I've just pushed a fix in mod_http_api, and also tests for example API commands. It works for me now using OTP 26 and 27.

When you can try it, please confirm it's solved.