The vulnerability exists in the attachGatewayWsMessageHandler function located in src/gateway/server/ws-connection/message-handler.ts. This function is responsible for handling WebSocket connections from nodes to the gateway. The analysis of the patch 3886b65ef21d02808c1a106fa1f9f69e22f71c32 reveals a flaw in the authorization logic for node commands. In the vulnerable version, when a node connects, the code checks if the node is paired. If it is not (pairedNode is null), the logic incorrectly defaults to allowing any command present in the device-type-based allowlist, completely skipping the node-specific command authorization. The expression (pairedCommands === null || pairedCommands.has(cmd)) evaluates to true for unpaired nodes, thus granting permissions. This allows a remote attacker who can complete the initial device-pairing step to execute arbitrary commands on the host if a dangerous command like system.run is declared by the connecting node. The patch rectifies this by ensuring that if a node is not paired, its list of executable commands is empty. It also introduces a mechanism to automatically request node pairing on the first connection. The new logic correctly filters commands against the set of commands explicitly granted during the node pairing process, effectively mitigating the vulnerability.