summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhackademix2018-09-09 08:21:03 +0200
committerhackademix2018-09-09 08:21:03 +0200
commiteb85395a01b735294d70551abbecb78838000a05 (patch)
treeae7f710df5b030d481510ad16c9daa997cfaf777
parentffc688d57a02f36d5e3c2c47f6d5836391487c16 (diff)
downloadnoscript-eb85395a01b735294d70551abbecb78838000a05.tar.gz
noscript-eb85395a01b735294d70551abbecb78838000a05.tar.xz
noscript-eb85395a01b735294d70551abbecb78838000a05.zip
Fixed message handling regression causing incompatibilities with embedders and potential internal loops.
-rw-r--r--src/lib/Messages.js14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/lib/Messages.js b/src/lib/Messages.js
index 8152555..11b9010 100644
--- a/src/lib/Messages.js
+++ b/src/lib/Messages.js
@@ -3,7 +3,14 @@
let handlers = new Set();
let dispatch = async (msg, sender) => {
- let {__meta} = msg;
+ let {__meta, _messageName} = msg;
+ if (!__meta) {
+ // legacy message from embedder?
+ if (!_messageName) {
+ throw new Error(`NoScript cannot handle message %s`, JSON.stringify(msg));
+ }
+ __meta = {name: _messageName};
+ }
let {name} = __meta;
let answers = [];
for (let h of handlers) {
@@ -17,8 +24,11 @@
answers.length === 1 ? answers.pop(): Promise.all(answers)
);
}
- let context = typeof window === "object" && window.location || null;
+ let context = typeof window === "object" && window.location.href || null;
let originalSender = __meta.originalSender || sender;
+ if (context === originalSender.url || context === sender.url) {
+ throw new Error("Message %s (%o) looping to its sender (%s)", name, msg, context);
+ }
console.debug("Warning: no handler for message %o in context %s", msg, context);
if (originalSender.tab && originalSender.tab.id) {
// if we're receiving a message from content, there might be another