From 2ac848828a8607b53fc060d4b002f6c5c20f44a4 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 10 Jul 2019 08:33:53 +0200 Subject: [PATCH] storage.js: Prevent conflicts with other apps accessing the same storage --- public/js/icinga/storage.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/public/js/icinga/storage.js b/public/js/icinga/storage.js index 03e3f3a2a..6c33fb89a 100644 --- a/public/js/icinga/storage.js +++ b/public/js/icinga/storage.js @@ -53,11 +53,12 @@ * @returns {string} */ prefixKey: function(key) { + var prefix = 'icinga.'; if (typeof this.prefix !== 'undefined') { - return this.prefix + '.' + key; + prefix = prefix + this.prefix + '.'; } - return key; + return prefix + key; }, /** @@ -113,6 +114,13 @@ * @param {StorageEvent} event */ onStorage: function(event) { + var url = icinga.utils.parseUrl(event.url); + if (! url.path.startsWith(icinga.config.baseUrl)) { + // A localStorage is shared between all paths on the same origin. + // So we need to make sure it's us who made a change. + return; + } + if (typeof this.subscribers[event.key] !== 'undefined') { var subscriber = this.subscribers[event.key]; subscriber[0].call(subscriber[1], JSON.parse(event.newValue), JSON.parse(event.oldValue), event);