-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Prevent cross origin iframe content reading #8005
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
Prevent cross origin iframe content reading #8005
Conversation
Looks like it's same as #7914, but I'm not using jQuery, b/c it's not necessary. |
There is already a PR for this here: #7914 The integration test failure was probably a bug in that rather than my js version of the code |
it's already implemented in jQuery so why not use it? |
Because it's not necessary as you see. We should write as much of vanilla JS as we can, not a 100% jQuery based code, even just for sake of future upgrades and deprecations. You soultion will not work if 3rd party iframe will have your main domain as a GET parameter i.e. Livechat make it this way. I already mentioned your PR in secod comment 😉 |
I would prefer #7914 over this one (if they work equally good).
jQuery is NEVER necessary. There is NO valid reason to not use it in a file where it is already defined. You simply create a mess with all these wordy
There is jQuery call here, isn't it? There is jQuery call one line after you code:
So, is it really necessary to force any developer reading this code scratch their heads? Does it work as intended, by the way? I didn't try your implementation in action but tried a small snippet in browser console:
|
@orlangur jQuery replacment: var el = $('<a></a>');
el.prop('href', 'http://magento.com/test&page=test.com');
console.log(el[0].hostname); About As I mention before #7914 dosen't cover option while URL contains base page URL as GET param (as in exapmple above) and thread this as "own" iframe, which cause same errors as currently, that's why we need to check BTW. Yes it works, we have it on production stores already. |
@Igloczek, I was trying to say that you (probably) changed behavior of code trying to use Vanilla JS.
I'm perfectly fine with VanillaJS-only (for instance, in small templates with KnockoutJS bindings). |
Ah, ok then. All the rest is just a matter of taste :) |
@Igloczek can you please merge with the latest mainline? |
@vrann Conflicts solved. |
@Igloczek After running the tests for JS had one failure:
which is related to this test As far as we already have merged #7914, should we just close this one? Seems like the exactly same solution. Haven't dig deep into why the test fails, though. |
@vrann I didn't check by myself, but from #8005 (comment) it looks like this fix is wider. |
@vrann Weird... Returning an empty array is the thing in this PR. I run tests locally and everything is fine. Do you use this test somewhere in CI pipeline to check non-local results? I pushed updated tests, b/c the solution from #7914 not cover a case when origin hostname is passed as a GET param and assume that can read iframe content, breaking everything. |
@Igloczek ok, let me try to run it again. The covered use case makes sense |
@Igloczek I run this test again in CI pipeline and it fails with the same result on latest commit. Can that be related to any environment setting? |
@Igloczek are you sure running those Jasmine-based JavaScript tests locally? They are not a part of Travis CI build currently. So, if you say "Returning an empty array is the thing in this PR" and you observe it locally, corresponding JavaScript unit test needs to be adopted to a changed logic. OR this test is passing on your local env? |
I found why it was failing and now I'm wondering how it works in my stores, b/c it shouldn't... The problem was related to reading jQuery object in vanilla JS, so I just switched to jQuery solution instead of addding Also for some reason I probably was checking some cached / wrong version of my files, that's why my tests were green all the time. BTW. Do you have any plans to run Jasmine on Travis too? It should be easy to do. |
That's exactly what I was referring in #8005 (comment) 😄 Good that we found it before merging to mainline. |
@Igloczek thanks for all the updates! Continue merging. |
@Igloczek accepted! Pleasure working with you. |
@vrann I'm on magento 2.1.7. How can I apply this fix? |
@viebel Same question, did you already find out? |
@TommyKolkman: this fix was very recently backported to the 2.1-develop branch, I suspect it might get released in version 2.1.8 or 2.1.9, but you'll have to ask the Magento devs for the exact timeframe. |
@peterjaap: It was too late to get included in 2.1.8 as far as I understood it, so it will probably be released in 2.1.10. |
@hostep yes, seems to be present on |
There is still an error in the fix mentioned above (in 2.1.10). It should be 'el' not 'element'.
|
@DaimPiek doesn't seem to be incorrect in this PR at least.. |
@OZZlE |
released in 2.1.10 |
@behnamshayani great! Good thai today 🥇 :D |
I still have this issue in 2.1.11. |
Browsers like Firefox or IE11 throws errors while trying to read cross origin iframe content. Element type and hostname has to be checked before any content processing/reading.
Loading external iframes is common practise in every store, b/c services like Hotjar use this technique.
This errors are breaking checkout process, so it's not an low severity issue.