Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FPC JS - Fix for CORS issue #7914

Merged
merged 3 commits into from
Mar 9, 2017
Merged

Conversation

OZZlE
Copy link
Contributor

@OZZlE OZZlE commented Dec 21, 2016

Page cache JS cannot modify dom of a external iframed page.

How to test (this is a fix for below):
Insert an iframe into your magento page with an external source for example (assuming you aren't google):

<iframe src="https://google.com/"></iframe>

Expected result:
No JS errors in console

Actual result (from chrome):
Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "https://google.com/" from accessing a cross-origin frame.

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Dec 21, 2016

CLA assistant check
All committers have signed the CLA.

I'm teh author
@vrann vrann self-assigned this Mar 6, 2017
@vrann vrann added this to the March 2017 milestone Mar 6, 2017
@magento-team magento-team merged commit 9e7f664 into magento:develop Mar 9, 2017
@vrann
Copy link
Contributor

vrann commented Mar 9, 2017

@OZZlE PR is merged, thank you for the contribution!

@OZZlE
Copy link
Contributor Author

OZZlE commented Mar 10, 2017

You are welcome! :)

@sshymko
Copy link

sshymko commented Mar 31, 2017

The fix is incomplete as 3rd party iframe URL may contain the site's domain in a query string.

For example, Google Customer Reviews badge.

Example Magento 2 website:
https://www.lillianvernon.com/

The 3rd party iframe:
https://www.google.com/shopping/customerreviews/badge?usegapi=1&merchant_id=101500539&position=BOTTOM_RIGHT&hl=en_US&origin=https%3A%2F%2Fwww.lillianvernon.com&gsrc=3p&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.GBDVBIKSh6E.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Frs%3DAGLTcCOvjPXLze_vbEyZVBIlOAVh5fcR-g

Notice the domain "www.lillianvernon.com" in the iframe URL, but it's not the Magento page.

@orlangur
Copy link
Contributor

orlangur commented Apr 1, 2017

@sshymko it would be more productive to report a new issue referring to this PR rather than to comment in a closed ticket.

@sshymko
Copy link

sshymko commented Apr 1, 2017

Submitted #9090

@Igloczek
Copy link
Contributor

Igloczek commented Apr 2, 2017

Already fixed #8005

@winds1983
Copy link

winds1983 commented Apr 21, 2017

Still happened on 2.1.6:
Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "https://***" from accessing a cross-origin frame.

@Igloczek
Copy link
Contributor

@winds1983 it's merged to develop and will be released probably as 2.2.0

@hostep
Copy link
Contributor

hostep commented Apr 21, 2017

Or someone can backport the PR, so it gets included in 2.1.x:
https://community.magento.com/t5/Magento-DevBlog/Pull-Requests-for-2-1-x-Patch-Releases/ba-p/65630 ;)

@Ylmzef
Copy link

Ylmzef commented Oct 3, 2017

I have still this issue

@Igloczek
Copy link
Contributor

Igloczek commented Oct 3, 2017

@Ylmzef On 2.2?

@Ylmzef
Copy link

Ylmzef commented Oct 11, 2017

@Igloczek yes

@Igloczek
Copy link
Contributor

@Ylmzef You should open a new issue with a detailed description and steps to reproduce it, b/c code of this and related PR is present in M2.2.

@gcampedelli
Copy link

I'm not sure exactly where to write this. But I'm trying to fix this DOM error and I applied more than one suggestion in this forum. I've applied this one: 9e7f664
It didn't fix 3rd party iframe DOM problem, just the error prop. is not a function.

Then I tried to apply this other solution described in another document in page-cache.js : // prevent cross origin iframe content reading
if ($(element).prop('tagName') === 'IFRAME') {
iframeHostName = $('').prop('href', $(element).prop('src'))
.prop('hostname');

            if (window.location.hostname !== iframeHostName) {
                return [];
            }
        }

It did fix iframe problem but it breaks checkout credit card form. I don't have how to fix credit card form. I know that the payment module uses Vanilla JS.
So, is there any other advice on how to prevent that?

@OZZlE
Copy link
Contributor Author

OZZlE commented Nov 21, 2017

@gcampedelli have you tried this one? https://github.com/magento/magento2/pull/8005/files

@OZZlE
Copy link
Contributor Author

OZZlE commented Nov 21, 2017

@gcampedelli maybe that was the one you were referring to? Might be better to create a new issue instead

@gcampedelli
Copy link

gcampedelli commented Nov 21, 2017

Hello Ozzie, yes, I tried this one as well. https://github.com/magento/magento2/pull/8005/files.
But It breaks payment module. Fix for iframe issue in console without breaking payment was

`/**
* @param {jQuery} element - Comment holder
*/
(function lookup(element) {
if (element.nodeName === "IFRAME") {
var iframeSrc = document.createElement('a');
iframeSrc.href = element.src;
if (window.location.hostname !== iframeSrc.hostname) {
}
}
$(element).contents().each(function (index, el) {
switch (el.nodeType) {
case 1: // ELEMENT_NODE
lookup(el);
break;

                case 8: // COMMENT_NODE
                    elements.push(el);
                    break;

                case 9: // DOCUMENT_NODE
                    lookup($(el).find('body'));
                    break;
    })(this);

    return elements;
};`

I just got an unexpected token that maybe easy to solve. These are lines that are in red here - 3026e81

magento-devops-reposync-svc pushed a commit that referenced this pull request Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.