Search code examples
ejabberd

Enter in MUC room with another username


When im trying to enter in a room with another username then i entered in room with a different username. Like my username is admin and when i send this xml to enter in room <presence to="roomname@conference.server.com/fakeuser" type="available"/> then 'admin' will enter in room with 'fakename' how to disallow this to all users so, they will enter in room with real names only.


Solution

  • This patch blocks presence stanzas with nickname different than username, and returns an error to the user:

    diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl
    index 492f9a4b3..3918401d1 100644
    --- a/src/mod_muc_room.erl
    +++ b/src/mod_muc_room.erl
    @@ -342,6 +342,15 @@ normal_state({route, <<"">>, #iq{} = IQ}, StateData) ->
        true -> {stop, normal, StateData};
        false -> {next_state, normal_state, StateData}
         end;
    +normal_state({route, Nick, #presence{from = From, lang = Lang} = Packet}, StateData)
    +   when From#jid.luser /= Nick ->
    +    ErrText = <<"It is not allowed to join the room with nickname different than username">>,
    +    Err = xmpp:err_forbidden(ErrText, Lang),
    +    ejabberd_router:route_error(Packet, Err),
    +    case StateData#state.just_created of
    +   true -> {stop, normal, StateData};
    +   false -> {next_state, normal_state, StateData}
    +    end;
     normal_state({route, Nick, #presence{from = From} = Packet}, StateData) ->
         Activity = get_user_activity(From, StateData),
         Now = p1_time_compat:system_time(micro_seconds),