From e67e006f330296ceab4fb5eb5ffb0d8700ef89c9 Mon Sep 17 00:00:00 2001 From: Victor Mu Date: Thu, 22 Apr 2021 14:46:43 -0700 Subject: [PATCH] Check for unsupported unicode payload strings in add event (#555) --- lib/console_web/controllers/router/device_controller.ex | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/console_web/controllers/router/device_controller.ex b/lib/console_web/controllers/router/device_controller.ex index 9e014b37e..11bef5ff6 100644 --- a/lib/console_web/controllers/router/device_controller.ex +++ b/lib/console_web/controllers/router/device_controller.ex @@ -148,6 +148,15 @@ defmodule ConsoleWeb.Router.DeviceController do end end + event = case event["data"]["payload"] do + nil -> event + _ -> + case :unicode.characters_to_binary(event["data"]["payload"]) |> String.at(0) do + <<0>> -> Kernel.put_in(event["data"]["payload"], "Unsupported unicode escape sequence in payload") + _ -> event + end + end + Events.create_event(Map.put(event, "organization_id", organization.id)) end) |> Ecto.Multi.run(:device, fn _repo, %{ event: event } ->