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

If matrix_domain contains @HOST@, this isn't replaced when using the option #4167

Closed badlop closed 4 months ago

badlop commented 4 months ago

Reported in the ejabberd chatroom by Arcanicanis:

There seems to be a bug where server_name in /_matrix/key/v2/server will be listed literally as "@HOST@" if matrix_domain isn't set for mod_matrix_gw.

And to clarify, I mean as the string literal @HOST@, and not the intended substitution (the server's default hostname).

It's easy to reproduce, simply use ejabberd 24.02 and configure

listen:
  - 
    port: 8448
    module: ejabberd_http
    tls: true
    request_handlers:
      "/_matrix": mod_matrix_gw

modules:
  mod_matrix_gw:
    key_name: "key1"
    key: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    matrix_id_as_jid: true

And visiting https://localhost:8448/_matrix/key/v2/server returns as result:

{
 "verify_keys":{"ed25519:key1":{"key":"ftd/itbHcx5iqJ/IUhcDXA+QVQJjqUIe04EoUQO/ODU"}},
 "valid_until_ts":1709719180881,
 "signatures":{"@HOST@": {"ed25519:key1":"bpgphjYuYYB5BU..."}},
 "server_name":"@HOST@",
 "old_verify_keys":{}
}

In fact, setting the option matrix_domain: "@HOST@.aaa" will make the page show "server_name":"@HOST@.aaa".

It seems mod_matrix lacks a call to misc:expand_keyword(<<"@HOST@">>, Domain, Host) in the proper place...