{"record":{"id":"666fdd5f342742ed","repo":"ratchetphp/Ratchet","slug":"invalid-wamp-message-format","errorCode":null,"errorMessage":"Invalid WAMP message format","messagePattern":"Invalid WAMP message format","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Ratchet/Wamp/ServerProtocol.php","lineNumber":93,"sourceCode":"        $this->connections->offsetSet($conn, $decor);\n\n        $this->_decorating->onOpen($decor);\n    }\n\n    /**\n     * {@inheritdoc}\n     * @throws \\Ratchet\\Wamp\\Exception\n     * @throws \\Ratchet\\Wamp\\JsonException\n     */\n    public function onMessage(ConnectionInterface $from, $msg) {\n        $from = $this->connections[$from];\n\n        if (null === ($json = @json_decode($msg, true))) {\n            throw new JsonException;\n        }\n\n        if (!is_array($json) || $json !== array_values($json)) {\n            throw new Exception(\"Invalid WAMP message format\");\n        }\n\n        if (isset($json[1]) && !(is_string($json[1]) || is_numeric($json[1]))) {\n            throw new Exception('Invalid Topic, must be a string');\n        }\n\n        switch ($json[0]) {\n            case static::MSG_PREFIX:\n                $from->WAMP->prefixes[$json[1]] = $json[2];\n            break;\n\n            case static::MSG_CALL:\n                array_shift($json);\n                $callID  = array_shift($json);\n                $procURI = array_shift($json);\n\n                if (count($json) == 1 && is_array($json[0])) {\n                    $json = $json[0];","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/ratchetphp/Ratchet/blob/e621c6c40bf684bbbb877102416ad5303d05a9cc/src/Ratchet/Wamp/ServerProtocol.php#L75-L111","documentation":"Ratchet\\Wamp\\ServerProtocol::onMessage throws \"Invalid WAMP message format\" when a decoded WebSocket frame is not a JSON array of consecutively-indexed elements. WAMP messages must be JSON arrays (e.g. [5, \"topic\"]); an object keyed with strings or a sparse array fails the `$json === array_values($json)` check. The library throws because it cannot route a non-array payload through its `switch ($json[0])` message-type dispatch.","triggerScenarios":"A client sends valid JSON that decodes to an associative object (e.g. `{\"type\":5}`) instead of a numbered array, or sends a JSON array with non-sequential keys impossible in strict JSON but possible when decoding objects cast to arrays, or sends a JSON scalar/null/number/string like `\"hello\"` or `42`, all of which fail `is_array` or the array_values comparison.","commonSituations":"Custom or hand-rolled client code that emits WAMP messages as JSON objects instead of arrays; a JS client doing JSON.stringify({topic: x}) instead of JSON.stringify([5, topic]); a WAMP v2/RAWS client speaking a newer protocol flavor than Ratchet's legacy WAMP v1 expects; a bot or fuzzer probing the socket.","solutions":["Send WAMP messages as JSON arrays with the message type as element 0, e.g. [5, \"http://example.com/topic\"], not JSON objects.","Check the client library version: Ratchet implements legacy WAMP v1; ensure the client (autobahn-js v0.x era, not newer Crossbar-oriented stacks) speaks the same protocol.","Log the raw incoming $msg before decoding to see exactly what the client sent, and fix the encoder on the client side.","Catch \\Ratchet\\Wamp\\Exception in the onError handler of your decorating component and close or ignore misbehaving connections."],"exampleFix":"// before (client, JavaScript)\nws.send(JSON.stringify({ type: 5, topic: 'kittens' }));\n// after\nws.send(JSON.stringify([5, 'kittens']));","handlingStrategy":"validation","validationCode":"$decoded = json_decode($msg, true);\nif (!is_array($decoded) || $decoded !== array_values($decoded)) {\n    // reject before sending: WAMP v1 requires a numerically-indexed JSON array\n}","typeGuard":"function isWampArrayMessage($msg): bool {\n    $d = json_decode($msg, true);\n    return is_array($d) && $d !== [] && $d === array_values($d);\n}","tryCatchPattern":"try {\n    $server->onMessage($conn, $msg);\n} catch (\\Ratchet\\Wamp\\Exception $e) {\n    $conn->close(); // malformed frame: drop the connection\n}","preventionTips":["Always send WAMP frames as JSON arrays: [type, topic, ...], never JSON objects.","Pin the client library to a WAMP v1-compatible version matching Ratchet.","Add a pre-send serializer test asserting decoded frames are sequential arrays.","Close connections on any WAMP protocol exception so a bad client cannot keep sending."],"tags":["websocket","wamp","protocol","json"],"backgroundTag":"invalid-argument-format","analyzedSha":"e621c6c40bf684bbbb877102416ad5303d05a9cc","analyzedAt":"2026-09-16T00:13:27.878Z","contentChangedAt":"2026-09-16T00:13:27.878Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}