Search Unity

How to fix or what is the cause of "Disconnecting connId=0 to prevent exploits" in Unity?

Discussion in 'Multiplayer' started by cycloaaa04, Oct 5, 2021.

  1. cycloaaa04

    cycloaaa04

    Joined:
    Sep 23, 2021
    Posts:
    1
    (Just tell me if you need more details for this problem and what details are those. Thanks!)

    I am encountering the errors below in the Mirror network package (Unity).

    I am new at networking in Unity and I can't figure out what causes this error.

    Code (CSharp):
    1. Disconnecting connId=0 to prevent exploits from an Exception in MessageHandler: NullReferenceException Object reference not set to an instance of an object
    2.   at Mirror.NetworkIdentity.OnStartServer () [0x00085] in C:\Users\...\My project\Assets\Mirror\Runtime\NetworkIdentity.cs:659
    3.   at Mirror.NetworkServer.SpawnObject (UnityEngine.GameObject obj, Mirror.NetworkConnection ownerConnection) [0x000af] in C:\Users\....\My project\Assets\Mirror\Runtime\NetworkServer.cs:1021
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. Mirror.NetworkIdentity.ClearAllComponentsDirtyBits () (at Assets/Mirror/Runtime/NetworkIdentity.cs:1234)
    3.  
    4. Mirror.NetworkServer.ClearSpawnedDirtyBits () (at Assets/Mirror/Runtime/NetworkServer.cs:1571)
    5. Mirror.NetworkServer.Broadcast () (at Assets/Mirror/Runtime/NetworkServer.cs:1689)
    Here is the situation:

    I am trying to create a game that has a host and a server. I created my own IP input field to allow changing host IP in the game. But when I click "HOST" which calling StartServer() function of Mirror Network Manager, it produces the error below. It is also the case when trying the HUD.

    Note that I haven't edited or coded yet anything with Mirror in this project.

    The code in the Player prefab is working when I run the game scene alone.

    upload_2021-10-6_0-34-56.png
    Above is the first scene where the user needs to input the host IP. The Play button is for the client connection, but don't mind it yet.

    Here is my setup of NetworkManager
    upload_2021-10-6_0-35-27.png

    Here are some of the Player Prefabs Scripts including the NetworkIdentity.
    upload_2021-10-6_0-36-3.png


    upload_2021-10-6_0-36-20.png
     
    CloudyVR likes this.
  2. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    666
    I'm not sure exactly what's going on but a little clarification. The player that is the host is the server as well as a client, with the other players joining the host as clients. You don't need to set the IP for the host and I would keep it simple and leave as localhost for now, and start the server with a call to NetworkManager.singleton.StartHost(). The joining players can enter the IP as localhost, and join the server with NetworkManager.singleton.StartClient().

    I don't know why the hud would also give problems, check out the examples that come with Mirror and see if they're working.
     
  3. Kjaka

    Kjaka

    Joined:
    Dec 8, 2015
    Posts:
    18
    Did you ever solve this problem, we are encountering the same issue
     
    CloudyVR likes this.
  4. FellowPlayer123

    FellowPlayer123

    Joined:
    Dec 23, 2016
    Posts:
    114
    Any update on this?
     
    CloudyVR likes this.
  5. qskakar

    qskakar

    Joined:
    Dec 21, 2017
    Posts:
    4
    I had the same problem and fixed it. The problem was that apparently Mirror can not take Gameobject as an input to a command. I just received the gameobject from the command function input parameters and the problem was resolved.
     
    AycanOzatak likes this.
  6. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    401
    This error can be caused by literally anything.

    Unfortunately the only correct answer is, the server encountered an error when parsing data received from the client.

    You will have to dig into the core and debug to see what was the last packet received from the client leading up to the error, and further isolate if it's a RPC, broadcast, ect.

    Once you know the origin see if it's the data being received or possibly the logic processing the data that's throwing.
     
  7. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Clients should never be able to throw exceptions on the server.
    Otherwise, you are risking potential exploits.

    For example, let's say you have two components:
    - PlayerCombat
    - PlayerBuffs

    and let's say PlayerBuffers.OnStartServer loads all buffs from the database.
    Buffs may be positive, or negative - for example, some kind of punishment that lasts for a day.

    Now if an attacker is able to throw an exception in PlayerCombat.OnStartServer, then PlayerBuffs.OnStartServer may never happen due to the exception being propagated up the call stack.

    In other words, in that hypothetical example an attacker may be able to remove (= never load) negative buffs by triggering the exception.

    ---

    This is why Mirror disconnects a client if that client was able to throw an exception.
    The goal is to contain the potential attack.

    ---

    Now in your example, it looks like NetworkIdentity:1234 throws a NullReferenceException.
    This should never happen, it sounds like some component in your game is null or was destroyed when it shouldn't be.
    For example, don't call GameObject.Destroy(playerCombat) manually.
    Always use NetworkServer.Destroy(player.gameObject).

    Mirror will always show you the reason why it disconnect a connection.
    Follow the reason and you will know the answer :)
     
  8. Boyozu

    Boyozu

    Joined:
    Jan 15, 2020
    Posts:
    1
    Amazing explanation thank you.
     
    mischa2k likes this.