Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webadmin - crash when navigating to /admin/server/domain.tld/shared-roster/ #4245

Closed
rom1dep opened this issue Jul 3, 2024 · 5 comments
Closed
Assignees
Labels

Comments

@rom1dep
Copy link
Contributor

rom1dep commented Jul 3, 2024

Environment

  • ejabberd version: 24.06.11
  • Erlang version: Erlang (SMP,ASYNC_THREADS) (BEAM) emulator version 14.2.5
  • OS: Linux (Fedora)
  • Installed from: source

Errors from error.log/crash.log

[error] <0.883.0>@ejabberd_hooks:safe_apply/4:460 Hook webadmin_page_host crashed when running mod_shared_roster:webadmin_page/3:                                               
** exception error: bad generator undefined                                                                                                                                                                      
   in function  ejabberd_web_admin:'-make_command_result_element/5-lc$^5/1-0-'/5 (/home/apps/ejabberd/src/ejabberd_web_admin.erl, line 2136)                                                                     
   in call from ejabberd_web_admin:make_command_result_element/5 (/home/apps/ejabberd/src/ejabberd_web_admin.erl, line 2136)                                                                                     
   in call from ejabberd_web_admin:make_command_result/7 (/home/apps/ejabberd/src/ejabberd_web_admin.erl, line 2079)                                                                                             
   in call from ejabberd_web_admin:make_command2/12 (/home/apps/ejabberd/src/ejabberd_web_admin.erl, line 1778)                                                                                                  
   in call from mod_shared_roster:'-make_webadmin_srg_table/4-lc$^0/1-0-'/4 (/home/apps/ejabberd/src/mod_shared_roster.erl, line 1162)                                                                           
   in call from mod_shared_roster:make_webadmin_srg_table/4 (/home/apps/ejabberd/src/mod_shared_roster.erl, line 1172)                                                                                           
   in call from mod_shared_roster:webadmin_page_backend/5 (/home/apps/ejabberd/src/mod_shared_roster.erl, line 1050)                                                                                             
   in call from mod_shared_roster:webadmin_page/3 (/home/apps/ejabberd/src/mod_shared_roster.erl, line 885)                                                                                                      
** Arg 1 = []                                                                                                                                                                                                    
** Arg 2 = <<"domain.tld">>                                                                                                                                                                                     
** Arg 3 = {request,'GET',                                                                                                                                                                                       
               [<<"shared-roster">>],
               <<"/admin/server/domain.tld/shared-roster/">>,
               [{nokey,<<>>}],
               {<<"adminuser">>,<<"domain.tld">>},
               {<<"[email protected]">>,<<"password">>},
               <<"en-US">>,<<>>,
               …
               <<"domain.tld">>,5443,
               [{custom_headers,
                    [{<<"Access-Control-Allow-Origin">>,<<"*">>},
                     {<<"Access-Control-Allow-Methods">>,
                      <<"OPTIONS, HEAD, GET, PUT">>},
                     {<<"Access-Control-Allow-Headers">>,<<"Authorization">>},
                     {<<"Access-Control-Allow-Credentials">>,<<"true">>}]},
                {tls,true},
                {request_handlers,
                    [{[<<"admin">>],ejabberd_web_admin},
                     {[<<"api">>],mod_http_api},
                     {[<<"bosh">>],mod_bosh},
                     {[<<"ws">>],ejabberd_http_ws},
                     {[<<"captcha">>],ejabberd_captcha},
                     {[<<"upload">>],mod_http_upload},
                     {[<<".well-known">>,<<"host-meta">>],mod_host_meta},
                     {[<<".well-known">>,<<"host-meta.json">>],
                      mod_host_meta}]}],
               https,
               [{<<"Priority">>,<<"u=0, i">>},
                {<<"Sec-Fetch-User">>,<<"?1">>},
                {<<"Sec-Fetch-Site">>,<<"same-origin">>},
                {<<"Sec-Fetch-Mode">>,<<"navigate">>},
                {<<"Sec-Fetch-Dest">>,<<"document">>},
                {<<"Upgrade-Insecure-Requests">>,<<"1">>},
                {'Cookie',
                    <<"…">>},
                {'Referer',
                    <<"https://domain.tld:5443/admin/server/domain.tld/">>},
                {'Connection',<<"keep-alive">>},
                {'Authorization',
                    <<"Basic …">>},
                {<<"Sec-Gpc">>,<<"1">>},
                …
                {'Host',<<"domain.tld5443">>}],
               0,fast_tls,
               {tlssock,#Port<0.264>,#Ref<0.3102977973.3434217475.228801>}

Bug description

Navigating there results in an empty page showing "Not Found"

@mremond mremond added this to the ejabberd 24.07 milestone Jul 4, 2024
@badlop badlop self-assigned this Jul 5, 2024
@badlop
Copy link
Member

badlop commented Jul 5, 2024

Apparently the problem appears when generating the table of all the shared roster groups in a vhost. That table gets the list of groups and their details. More precisely, it seems to fail to obtain or process the list of "displayed_groups".

Probably the new webadmin feature or a nwe command is not able to process correctly that stored data. Or some stored data is corrupted and the code should know how to handle it.

Do you use mnesia storage? If so, take a look at the sr_group table, for example in
http://localhost:5280/admin/node/ejabberd@localhost/db/table/sr_group/elements/1/

In my case, I have two groups:

[{sr_group,{<<"gr1">>,<<"localhost">>},
           [{online_users,true},
            {all_users,true},
            {displayed_groups,[<<"gr1">>]},
            {label,<<>>},
            {description,<<>>}]},
 {sr_group,{<<"gr2">>,<<"localhost">>},
           [{label,<<>>},{description,<<>>},{displayed_groups,[]}]}]

Do you see anything abnormal in your table? Can you share it? (replace personal details if necessary)

Similarly, if you use SQL, take a look at the table, anything suspicious about incorrectly formatted data?

If you suspect the problem is in a specific group, I guess it will also crash if you visit that specific group:
http://localhost:5280/admin/server/localhost/shared-roster/group/gr1/

Also, does it crash when you execute those commands using ejabberdctl?


$ ejabberdctl srg_get_displayed gr1 localhost
gr1

$ ejabberdctl srg_get_info gr1 localhost
online_users    true
all_users       true
displayed_groups        ["gr1"]
label   []
description     []

@rom1dep
Copy link
Contributor Author

rom1dep commented Jul 5, 2024

Hi! Thanks for looking into this :)

Here's the content of the sr_group table as shown through the url: http://localhost:5280/admin/node/ejabberd@localhost/db/table/sr_group/elements/1/:

[{sr_group,{<<"g1">>,<<"domain.tld">>},
           [{label,<<"g1">>},{description,<<"g1 desc">>}]},
 {sr_group,{<<"g2">>,<<"domain.tld">>},[]},
 {sr_group,{<<"g3">>,<<"domain.tld">>},[{label,<<"g3 desc">>}]},
 {sr_group,{<<"g4">>,<<"domain.tld">>},[{label,<<"g4 desc">>}]},
 {sr_group,{<<"g5">>,<<"domain.tld">>},[{label,<<"g5 desc">>}]}]

I do not have any problem visiting any of those shared roster groups, but all of them crash when accessing their "displayed groups", i.e. from urls such as: /shared-roster/group/gX/displayed/

Of note:

[ejabberd@server sbin]$ ./ejabberdctl srg_get_displayed g1 localhost
Unhandled exception occurred executing the command:
** exception error: no function clause matching 
                  ejabberd_ctl:format_result(undefined,
                                             {display,
                                              {top_result_list,
                                               {group,binary}}},
                                             1000000) (/home/apps/ejabberd/src/ejabberd_ctl.erl, line 394)
   in function  ejabberd_ctl:try_call_command/4 (/home/apps/ejabberd/src/ejabberd_ctl.erl, line 289)
   in call from ejabberd_ctl:process2/4 (/home/apps/ejabberd/src/ejabberd_ctl.erl, line 229)
   in call from ejabberd_ctl:process/2 (/home/apps/ejabberd/src/ejabberd_ctl.erl, line 207)
   in call from erpc:execute_call/4 (erpc.erl, line 589)

[ejabberd@server sbin]$ ./ejabberdctl srg_get_info g1 localhost
label   g1
description     g1 desc

@badlop
Copy link
Member

badlop commented Jul 11, 2024

Ok, the problem was fairly simple: the groups created using ejabberd 24.02 webadmin (or older) didn't have the
displayed_groups or other options.

All the methods to create groups in ejabberd 24.06 (I mean the srg_add and srg_create API commands, and also the WebAdmin pages which internally use those commands) set those options, at least with a default value, so I didn't care to handle the case that a group created some time ago may not have the option.

The bug is fixed with a very small commit :)

@badlop badlop closed this as completed Jul 11, 2024
@rom1dep
Copy link
Contributor Author

rom1dep commented Jul 12, 2024

I'm sorry to report that I still have a crash when navigating to: https://domain/admin/server/domain.tld/shared-roster/

[error] <0.693.0>@ejabberd_hooks:safe_apply/4:460 Hook webadmin_page_host crashed when running mod_shared_roster:webadmin_page/3:                                               
** exception error: {bad_jid,<<"gr1">>}                                                                                                                                                                
   in function  jid:decode/1 (/home/apps/ejabberd/_build/default/lib/xmpp/src/jid.erl, line 138)                                                                                                                 
   in call from ejabberd_web_admin:make_result/4 (/home/apps/ejabberd/src/ejabberd_web_admin.erl, line 2229)                                                                                                     
   in call from ejabberd_web_admin:make_command_result_element/5 (/home/apps/ejabberd/src/ejabberd_web_admin.erl, line 2139)                                                                                     
   in call from ejabberd_web_admin:make_command_result/7 (/home/apps/ejabberd/src/ejabberd_web_admin.erl, line 2079)                                                                                             
   in call from ejabberd_web_admin:make_command2/12 (/home/apps/ejabberd/src/ejabberd_web_admin.erl, line 1778)                                                                                                  
   in call from mod_shared_roster:'-make_webadmin_srg_table/4-lc$^0/1-0-'/4 (/home/apps/ejabberd/src/mod_shared_roster.erl, line 1082)                                                                           
   in call from mod_shared_roster:'-make_webadmin_srg_table/4-lc$^0/1-0-'/4 (/home/apps/ejabberd/src/mod_shared_roster.erl, line 1172)                                                                           
   in call from mod_shared_roster:make_webadmin_srg_table/4 (/home/apps/ejabberd/src/mod_shared_roster.erl, line 1172)                                                                                           
** Arg 1 = []                                                                                                                                                                                                    
** Arg 2 = <<"domain.tld">>                                                                                                                                                                                     
** Arg 3 = {request,'GET',
[…]

@rom1dep
Copy link
Contributor Author

rom1dep commented Jul 12, 2024

Can confirm it's fixed now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants