File tree Expand file tree Collapse file tree 2 files changed +11
-13
lines changed
app/code/Magento/PageCache/view/frontend/web/js
dev/tests/js/jasmine/tests/app/code/Magento/PageCache/frontend/js Expand file tree Collapse file tree 2 files changed +11
-13
lines changed Original file line number Diff line number Diff line change @@ -41,12 +41,17 @@ define([
41
41
* @param {jQuery } element - Comment holder
42
42
*/
43
43
( function lookup ( element ) {
44
- if ( $ . nodeName ( element , 'iframe' ) && $ ( element ) . prop ( 'src' ) . indexOf ( window . location . hostname ) === - 1 ) {
45
- return [ ] ;
44
+ // prevent cross origin iframe content reading
45
+ if ( $ ( element ) . prop ( 'tagName' ) === 'IFRAME' ) {
46
+ var iframeHostName = $ ( '<a>' ) . prop ( 'href' , $ ( element ) . prop ( 'src' ) )
47
+ . prop ( 'hostname' ) ;
48
+
49
+ if ( window . location . hostname !== iframeHostName ) {
50
+ return [ ] ;
51
+ }
46
52
}
47
- $ ( element ) . contents ( ) . each ( function ( index , el ) {
48
- var hostName , iFrameHostName ;
49
53
54
+ $ ( element ) . contents ( ) . each ( function ( index , el ) {
50
55
switch ( el . nodeType ) {
51
56
case 1 : // ELEMENT_NODE
52
57
lookup ( el ) ;
@@ -57,14 +62,7 @@ define([
57
62
break ;
58
63
59
64
case 9 : // DOCUMENT_NODE
60
- hostName = window . location . hostname ;
61
- iFrameHostName = $ ( '<a>' )
62
- . prop ( 'href' , $ ( element ) . prop ( 'src' ) )
63
- . prop ( 'hostname' ) ;
64
-
65
- if ( hostName === iFrameHostName ) {
66
- lookup ( $ ( el ) . find ( 'body' ) ) ;
67
- }
65
+ lookup ( $ ( el ) . find ( 'body' ) ) ;
68
66
break ;
69
67
}
70
68
} ) ;
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ define([
60
60
61
61
it ( 'on iframe from other host returns empty Array' , function ( ) {
62
62
iframe . contents ( ) . find ( 'body' ) . html ( comment ) ;
63
- iframe . attr ( 'src' , '//' + host + '.otherHost/' ) ;
63
+ iframe . attr ( 'src' , '//' + host + '.otherHost/?origin_url=' + host ) ;
64
64
65
65
expect ( iframe . comments ( ) . length ) . toEqual ( 0 ) ;
66
66
} ) ;
You can’t perform that action at this time.
0 commit comments