From 7046bb9f152e63ad3e381d45b004726b616306b8 Mon Sep 17 00:00:00 2001 From: Eyal <109809+eyal0@users.noreply.github.com> Date: Thu, 10 Dec 2020 21:30:10 -0700 Subject: [PATCH] Validate websocket JSON before sending The default json library in python will send infinity values as `Infinity` as described [here](https://docs.python.org/3/library/json.html#json.dump). Check that the JSON is strictly valid before sending it, otherwise throw an exception. This fixes #3875 --- src/octoprint/server/util/sockjs.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/octoprint/server/util/sockjs.py b/src/octoprint/server/util/sockjs.py index fdc883ad9..7e43f5ff8 100644 --- a/src/octoprint/server/util/sockjs.py +++ b/src/octoprint/server/util/sockjs.py @@ -589,6 +589,9 @@ class PrinterStateConnection( def _do_emit(self, type, payload): try: + import json + + _ = json.dumps(octoprint.util.thaw_frozendict({type: payload}), allow_nan=False) self.send({type: payload}) except Exception as e: if self._logger.isEnabledFor(logging.DEBUG):