From 4ade4adff2471478b7a849e7681b5855241050e5 Mon Sep 17 00:00:00 2001
From: Alexey Golubev <alexey.golubev@onlyoffice.com>
Date: Mon, 26 Dec 2016 12:27:01 +0300
Subject: [PATCH 1/2] Update version

---
 apps/api/documents/api.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js
index adbc4a6d9..179c2eeb9 100644
--- a/apps/api/documents/api.js
+++ b/apps/api/documents/api.js
@@ -557,7 +557,7 @@
     };
 
     DocsAPI.DocEditor.version = function() {
-        return '4.2.0';
+        return '4.2.4';
     };
 
     MessageDispatcher = function(fn, scope) {

From 494cc271dd3d279cf3c595861152d99665fe98b3 Mon Sep 17 00:00:00 2001
From: Julia Radzhabova <Julia.Radzhabova@onlyoffice.com>
Date: Wed, 14 Dec 2016 14:20:18 +0300
Subject: [PATCH 2/2] Check origin of messages received in api.

---
 apps/api/documents/api.js                        | 6 +++++-
 apps/common/Gateway.js                           | 1 +
 apps/documenteditor/embed/index.html             | 2 ++
 apps/documenteditor/embed/index.html.deploy      | 2 ++
 apps/documenteditor/main/index.html              | 2 ++
 apps/documenteditor/main/index.html.deploy       | 2 ++
 apps/documenteditor/mobile/index.html            | 2 ++
 apps/documenteditor/mobile/index.html.deploy     | 2 ++
 apps/presentationeditor/embed/index.html         | 2 ++
 apps/presentationeditor/embed/index.html.deploy  | 2 ++
 apps/presentationeditor/main/index.html          | 2 ++
 apps/presentationeditor/main/index.html.deploy   | 2 ++
 apps/presentationeditor/mobile/index.html        | 2 ++
 apps/presentationeditor/mobile/index.html.deploy | 2 ++
 apps/spreadsheeteditor/embed/index.html          | 2 ++
 apps/spreadsheeteditor/embed/index.html.deploy   | 2 ++
 apps/spreadsheeteditor/main/index.html           | 2 ++
 apps/spreadsheeteditor/main/index.html.deploy    | 2 ++
 apps/spreadsheeteditor/mobile/index.html         | 2 ++
 apps/spreadsheeteditor/mobile/index.html.deploy  | 2 ++
 20 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js
index 179c2eeb9..78223ee1e 100644
--- a/apps/api/documents/api.js
+++ b/apps/api/documents/api.js
@@ -180,6 +180,7 @@
         _config.editorConfig.canHistoryRestore = _config.events && !!_config.events.onRequestRestore;
         _config.editorConfig.canSendEmailAddresses = _config.events && !!_config.events.onRequestEmailAddresses;
         _config.editorConfig.canRequestEditRights = _config.events && !!_config.events.onRequestEditRights;
+        _config.frameEditorId = placeholderId;
 
         var onMouseUp = function (evt) {
             _processMouse(evt);
@@ -257,7 +258,7 @@
         };
 
         var _onMessage = function(msg) {
-            if (msg) {
+            if (msg && msg.frameEditorId == placeholderId) {
                 var events = _config.events || {},
                     handler = events[msg.event],
                     res;
@@ -662,6 +663,9 @@
                 if (config.editorConfig.customization.loaderLogo !== '') params += "&logo=" + config.editorConfig.customization.loaderLogo;
             }
         }
+
+        if (config.frameEditorId)
+            params += "&frameEditorId=" + config.frameEditorId;
         
         return params;
     }
diff --git a/apps/common/Gateway.js b/apps/common/Gateway.js
index 7cb8cab20..bae3f3f93 100644
--- a/apps/common/Gateway.js
+++ b/apps/common/Gateway.js
@@ -99,6 +99,7 @@ Common.Gateway = new(function() {
     var _postMessage = function(msg) {
         // TODO: specify explicit origin
         if (window.parent && window.JSON) {
+            msg.frameEditorId = window.frameEditorId;
             window.parent.postMessage(window.JSON.stringify(msg), "*");
         }
     };
diff --git a/apps/documenteditor/embed/index.html b/apps/documenteditor/embed/index.html
index e913f189a..9bf9f202b 100644
--- a/apps/documenteditor/embed/index.html
+++ b/apps/documenteditor/embed/index.html
@@ -239,6 +239,8 @@
                 loading = 'Loading...',
                 logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+            window.frameEditorId = params["frameEditorId"];
+
             if ( lang == 'de')      loading = 'Ladevorgang...';
             else if ( lang == 'es') loading = 'Cargando...';
             else if ( lang == 'fr') loading = 'Chargement en cours...';
diff --git a/apps/documenteditor/embed/index.html.deploy b/apps/documenteditor/embed/index.html.deploy
index bba1d7428..0737ebcea 100644
--- a/apps/documenteditor/embed/index.html.deploy
+++ b/apps/documenteditor/embed/index.html.deploy
@@ -231,6 +231,8 @@
                 loading = 'Loading...',
                 logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+            window.frameEditorId = params["frameEditorId"];
+
             if ( lang == 'de')      loading = 'Ladevorgang...';
             else if ( lang == 'es') loading = 'Cargando...';
             else if ( lang == 'fr') loading = 'Chargement en cours...';
diff --git a/apps/documenteditor/main/index.html b/apps/documenteditor/main/index.html
index d9e29af74..ff57f1872 100644
--- a/apps/documenteditor/main/index.html
+++ b/apps/documenteditor/main/index.html
@@ -227,6 +227,8 @@
             loading = 'Loading...',
             logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+        window.frameEditorId = params["frameEditorId"];
+
         if ( lang == 'de')      loading = 'Ladevorgang...';
         else if ( lang == 'es') loading = 'Cargando...';
         else if ( lang == 'fr') loading = 'Chargement en cours...';
diff --git a/apps/documenteditor/main/index.html.deploy b/apps/documenteditor/main/index.html.deploy
index 618e4c658..6a2e70bef 100644
--- a/apps/documenteditor/main/index.html.deploy
+++ b/apps/documenteditor/main/index.html.deploy
@@ -227,6 +227,8 @@
             loading = 'Loading...',
             logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+        window.frameEditorId = params["frameEditorId"];
+
         if ( lang == 'de')      loading = 'Ladevorgang...';
         else if ( lang == 'es') loading = 'Cargando...';
         else if ( lang == 'fr') loading = 'Chargement en cours...';
diff --git a/apps/documenteditor/mobile/index.html b/apps/documenteditor/mobile/index.html
index 0511a8cf3..a337cf9bc 100644
--- a/apps/documenteditor/mobile/index.html
+++ b/apps/documenteditor/mobile/index.html
@@ -264,6 +264,8 @@
                     loading = 'Loading...',
                     logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+                window.frameEditorId = params["frameEditorId"];
+
                 if ( lang == 'de')      loading = 'Ladevorgang...';
                 else if ( lang == 'es') loading = 'Cargando...';
                 else if ( lang == 'fr') loading = 'Chargement en cours...';
diff --git a/apps/documenteditor/mobile/index.html.deploy b/apps/documenteditor/mobile/index.html.deploy
index b0068f291..da68f5a76 100644
--- a/apps/documenteditor/mobile/index.html.deploy
+++ b/apps/documenteditor/mobile/index.html.deploy
@@ -255,6 +255,8 @@
                     loading = 'Loading...',
                     logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+                window.frameEditorId = params["frameEditorId"];
+
                 if ( lang == 'de')      loading = 'Ladevorgang...';
                 else if ( lang == 'es') loading = 'Cargando...';
                 else if ( lang == 'fr') loading = 'Chargement en cours...';
diff --git a/apps/presentationeditor/embed/index.html b/apps/presentationeditor/embed/index.html
index 58055d2ae..aa4c5f04b 100644
--- a/apps/presentationeditor/embed/index.html
+++ b/apps/presentationeditor/embed/index.html
@@ -238,6 +238,8 @@
               loading = 'Loading...',
               logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+          window.frameEditorId = params["frameEditorId"];
+
           if ( lang == 'de')      loading = 'Ladevorgang...';
           else if ( lang == 'es') loading = 'Cargando...';
           else if ( lang == 'fr') loading = 'Chargement en cours...';
diff --git a/apps/presentationeditor/embed/index.html.deploy b/apps/presentationeditor/embed/index.html.deploy
index 88aee4b7c..405f0a9b9 100644
--- a/apps/presentationeditor/embed/index.html.deploy
+++ b/apps/presentationeditor/embed/index.html.deploy
@@ -231,6 +231,8 @@
             loading = 'Loading...',
             logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+        window.frameEditorId = params["frameEditorId"];
+
         if ( lang == 'de')      loading = 'Ladevorgang...';
         else if ( lang == 'es') loading = 'Cargando...';
         else if ( lang == 'fr') loading = 'Chargement en cours...';
diff --git a/apps/presentationeditor/main/index.html b/apps/presentationeditor/main/index.html
index f17afdb60..b7fbec434 100644
--- a/apps/presentationeditor/main/index.html
+++ b/apps/presentationeditor/main/index.html
@@ -228,6 +228,8 @@
             loading = 'Loading...',
             logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+        window.frameEditorId = params["frameEditorId"];
+
         if ( lang == 'de')      loading = 'Ladevorgang...';
         else if ( lang == 'es') loading = 'Cargando...';
         else if ( lang == 'fr') loading = 'Chargement en cours...';
diff --git a/apps/presentationeditor/main/index.html.deploy b/apps/presentationeditor/main/index.html.deploy
index 187e8c64b..02842f74f 100644
--- a/apps/presentationeditor/main/index.html.deploy
+++ b/apps/presentationeditor/main/index.html.deploy
@@ -227,6 +227,8 @@
             loading = 'Loading...',
             logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+        window.frameEditorId = params["frameEditorId"];
+
         if ( lang == 'de')      loading = 'Ladevorgang...';
         else if ( lang == 'es') loading = 'Cargando...';
         else if ( lang == 'fr') loading = 'Chargement en cours...';
diff --git a/apps/presentationeditor/mobile/index.html b/apps/presentationeditor/mobile/index.html
index 42c71ee65..645d13fa6 100644
--- a/apps/presentationeditor/mobile/index.html
+++ b/apps/presentationeditor/mobile/index.html
@@ -263,6 +263,8 @@
                     loading = 'Loading...',
                     logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+                window.frameEditorId = params["frameEditorId"];
+
                 if ( lang == 'de')      loading = 'Ladevorgang...';
                 else if ( lang == 'es') loading = 'Cargando...';
                 else if ( lang == 'fr') loading = 'Chargement en cours...';
diff --git a/apps/presentationeditor/mobile/index.html.deploy b/apps/presentationeditor/mobile/index.html.deploy
index 57e3d4621..2de37649b 100644
--- a/apps/presentationeditor/mobile/index.html.deploy
+++ b/apps/presentationeditor/mobile/index.html.deploy
@@ -254,6 +254,8 @@
                     loading = 'Loading...',
                     logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+                window.frameEditorId = params["frameEditorId"];
+
                 if ( lang == 'de')      loading = 'Ladevorgang...';
                 else if ( lang == 'es') loading = 'Cargando...';
                 else if ( lang == 'fr') loading = 'Chargement en cours...';
diff --git a/apps/spreadsheeteditor/embed/index.html b/apps/spreadsheeteditor/embed/index.html
index 3ecdfd954..0695c7f3d 100644
--- a/apps/spreadsheeteditor/embed/index.html
+++ b/apps/spreadsheeteditor/embed/index.html
@@ -239,6 +239,8 @@
               loading = 'Loading...',
               logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+          window.frameEditorId = params["frameEditorId"];
+
           if ( lang == 'de')      loading = 'Ladevorgang...';
           else if ( lang == 'es') loading = 'Cargando...';
           else if ( lang == 'fr') loading = 'Chargement en cours...';
diff --git a/apps/spreadsheeteditor/embed/index.html.deploy b/apps/spreadsheeteditor/embed/index.html.deploy
index 63446a8db..2e34330ce 100644
--- a/apps/spreadsheeteditor/embed/index.html.deploy
+++ b/apps/spreadsheeteditor/embed/index.html.deploy
@@ -231,6 +231,8 @@
             loading = 'Loading...',
             logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+        window.frameEditorId = params["frameEditorId"];
+
         if ( lang == 'de')      loading = 'Ladevorgang...';
         else if ( lang == 'es') loading = 'Cargando...';
         else if ( lang == 'fr') loading = 'Chargement en cours...';
diff --git a/apps/spreadsheeteditor/main/index.html b/apps/spreadsheeteditor/main/index.html
index 0167ba7e2..44bd96271 100644
--- a/apps/spreadsheeteditor/main/index.html
+++ b/apps/spreadsheeteditor/main/index.html
@@ -230,6 +230,8 @@
             loading = 'Loading...',
             logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+        window.frameEditorId = params["frameEditorId"];
+
         if ( lang == 'de')      loading = 'Ladevorgang...';
         else if ( lang == 'es') loading = 'Cargando...';
         else if ( lang == 'fr') loading = 'Chargement en cours...';
diff --git a/apps/spreadsheeteditor/main/index.html.deploy b/apps/spreadsheeteditor/main/index.html.deploy
index 75c72c5c7..a6e3b81b3 100644
--- a/apps/spreadsheeteditor/main/index.html.deploy
+++ b/apps/spreadsheeteditor/main/index.html.deploy
@@ -228,6 +228,8 @@
             loading = 'Loading...',
             logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+        window.frameEditorId = params["frameEditorId"];
+
         if ( lang == 'de')      loading = 'Ladevorgang...';
         else if ( lang == 'es') loading = 'Cargando...';
         else if ( lang == 'fr') loading = 'Chargement en cours...';
diff --git a/apps/spreadsheeteditor/mobile/index.html b/apps/spreadsheeteditor/mobile/index.html
index d9a5f176a..500afab89 100644
--- a/apps/spreadsheeteditor/mobile/index.html
+++ b/apps/spreadsheeteditor/mobile/index.html
@@ -270,6 +270,8 @@
                     loading = 'Loading...',
                     logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+                window.frameEditorId = params["frameEditorId"];
+
                 if ( lang == 'de')      loading = 'Ladevorgang...';
                 else if ( lang == 'es') loading = 'Cargando...';
                 else if ( lang == 'fr') loading = 'Chargement en cours...';
diff --git a/apps/spreadsheeteditor/mobile/index.html.deploy b/apps/spreadsheeteditor/mobile/index.html.deploy
index 901427567..47e1fd2fe 100644
--- a/apps/spreadsheeteditor/mobile/index.html.deploy
+++ b/apps/spreadsheeteditor/mobile/index.html.deploy
@@ -255,6 +255,8 @@
                     loading = 'Loading...',
                     logo = params["logo"] ? ((params["logo"] !== 'none') ? ('<img src="' + encodeUrlParam(params["logo"]) + '" class="loader-logo" />') : '') : null;
 
+                window.frameEditorId = params["frameEditorId"];
+
                 if ( lang == 'de')      loading = 'Ladevorgang...';
                 else if ( lang == 'es') loading = 'Cargando...';
                 else if ( lang == 'fr') loading = 'Chargement en cours...';