From c43d73c6b63693d9dd72cd91a4934a8fc78f0ca4 Mon Sep 17 00:00:00 2001 From: Diep Pham Date: Mon, 5 Feb 2024 19:47:28 +0700 Subject: [PATCH] Fix wrong target origin warning when certain browser extensions are installed --- app/views/account/rpiframe.html.erb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/views/account/rpiframe.html.erb b/app/views/account/rpiframe.html.erb index 5ecd9e0..9df36ea 100644 --- a/app/views/account/rpiframe.html.erb +++ b/app/views/account/rpiframe.html.erb @@ -21,6 +21,11 @@ window.addEventListener("message", receiveMessage, false); function receiveMessage(e) { + // other scripts might use postMessage method, filter out events + // not originated from opiframe. + var opiframe = window.parent.document.getElementById("opiframe").contentWindow; + if (e.source !== opiframe) { return }; + if (e.origin !== target_origin) { return alert('Wrong target origin: ' + target_origin); } stat = e.data;