Skip to content

Commit 45fc679

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1327 from magento-engcom/2.1-develop-prs
Public Pull Requests #10218
2 parents 225e81f + 787cf86 commit 45fc679

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

app/code/Magento/PageCache/view/frontend/web/js/page-cache.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ define([
2424
* @param {jQuery} element - Comment holder
2525
*/
2626
(function lookup(element) {
27+
var iframeHostName;
28+
29+
// prevent cross origin iframe content reading
30+
if ($(element).prop('tagName') === 'IFRAME') {
31+
iframeHostName = $('<a>').prop('href', $(element).prop('src'))
32+
.prop('hostname');
33+
34+
if (window.location.hostname !== iframeHostName) {
35+
return [];
36+
}
37+
}
38+
2739
$(element).contents().each(function (index, el) {
2840
switch (el.nodeType) {
2941
case 1: // ELEMENT_NODE
@@ -35,14 +47,7 @@ define([
3547
break;
3648

3749
case 9: // DOCUMENT_NODE
38-
var hostName = window.location.hostname,
39-
iFrameHostName = $('<a>')
40-
.prop('href', element.prop('src'))
41-
.prop('hostname');
42-
43-
if (hostName === iFrameHostName) {
44-
lookup($(el).find('body'));
45-
}
50+
lookup($(el).find('body'));
4651
break;
4752
}
4853
});
@@ -159,17 +164,16 @@ define([
159164
* @protected
160165
*/
161166
_replacePlaceholder: function (placeholder, html) {
167+
var startReplacing = false,
168+
prevSibling = null,
169+
parent, contents, yy, len, element;
170+
162171
if (!placeholder || !html) {
163172
return;
164173
}
165174

166-
var parent = $(placeholder.openElement).parent(),
167-
contents = parent.contents(),
168-
startReplacing = false,
169-
prevSibling = null,
170-
yy,
171-
len,
172-
element;
175+
parent = $(placeholder.openElement).parent();
176+
contents = parent.contents();
173177

174178
for (yy = 0, len = contents.length; yy < len; yy++) {
175179
element = contents[yy];

dev/tests/js/jasmine/tests/app/code/Magento/PageCache/frontend/js/page-cache.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ define([
5858

5959
it('on iframe from other host returns empty Array', function () {
6060
iframe.contents().find('body').html(comment);
61-
iframe.attr('src', '//' + host + '.otherHost/');
61+
iframe.attr('src', '//' + host + '.otherHost/?origin_url=' + host);
6262

6363
expect(iframe.comments().length).toEqual(0);
6464
});

0 commit comments

Comments
 (0)