WebSocket status not being correctly validated before sending a message



  • Hi, this is a message directed to the development team, specifically the software engineers:

    I noticed you have the debug logs active for the browser, so I went to read some of your code and noticed something that I believe might be a bug.
    I think it could be related to some of the recurring errors during the startup phase, so it might be worth to look at.

    In order to validate the status of a WebSocket before a message is sent, the following function is called:

    this.checkWebSocketValid = (function(stateValidator) {
        if (!this.webSocket) {
            this.log("WebSocket not initialized. ");
            return false
        } else if (!stateValidator(this.webSocket.readyState)) {
            this.log("WebSocket in wrong state: " + webSocketStateToString(this.webSocket.readyState)) 
        }
        return true
    }
    
    

    You can see however that the second part of the conditional is missing a return statement, so the method actually regards any existing web socket as valid, regardless of its state being ready or not. This could cause attempts to send data before it should be, which might cascade to different problems depending of how that's handled.

    A correct version would look like this:

    this.checkWebSocketValid = (function(stateValidator) {
        if (!this.webSocket) {
            this.log("WebSocket not initialized. ");
            return false
        } else if (!stateValidator(this.webSocket.readyState)) {
            this.log("WebSocket in wrong state: " + webSocketStateToString(this.webSocket.readyState))
            return false
        }
        return true
    }
    
    

    The observed URI of the production build of the file where I read the code above was https://www.catanuniverse.com/b5ed2ff9-f389-4eb4-8fc6-3c650915a247 and the location within that file was the line 3272, after I ran the script through the code pretty-printer included in the chrome developer tools.

    Good luck, I hope it might be helpful.
    Keep it up, it's a very enjoyable game.


  • administrators

    @FcoManueel thank you very much for letting us know. I´ll forward it to the devs and they´ll take a look at it.


Log in to reply