Skip to content

Commit dc79f04

Browse files
ENGCOM-3440: #16887: [Forwardport] Fix blocked a frame with origin. #19171
2 parents 0ea6794 + 87a8a98 commit dc79f04

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
define([
77
'jquery',
88
'domReady',
9+
'consoleLogger',
910
'jquery/ui',
1011
'mage/cookies'
11-
], function ($, domReady) {
12+
], function ($, domReady, consoleLogger) {
1213
'use strict';
1314

1415
/**
@@ -46,14 +47,30 @@ define([
4647
// prevent cross origin iframe content reading
4748
if ($(element).prop('tagName') === 'IFRAME') {
4849
iframeHostName = $('<a>').prop('href', $(element).prop('src'))
49-
.prop('hostname');
50+
.prop('hostname');
5051

5152
if (window.location.hostname !== iframeHostName) {
5253
return [];
5354
}
5455
}
5556

56-
$(element).contents().each(function (index, el) {
57+
// rewrite jQuery contents()
58+
var contents = function (element) {
59+
return $.map(element, function (elem) {
60+
try {
61+
return $.nodeName(elem, "iframe") ?
62+
elem.contentDocument || (elem.contentWindow ? elem.contentWindow.document : []) :
63+
$.merge([], elem.childNodes);
64+
} catch (e) {
65+
consoleLogger.error(e);
66+
return [];
67+
}
68+
});
69+
};
70+
71+
var elementContents = contents($(element));
72+
73+
$.each(elementContents, function (index, el) {
5774
switch (el.nodeType) {
5875
case 1: // ELEMENT_NODE
5976
lookup(el);

0 commit comments

Comments
 (0)