video.js icon indicating copy to clipboard operation
video.js copied to clipboard

Uncaught SecurityError when using iframe

Open naorye opened this issue 11 years ago • 25 comments

When using videoJS inside an iframe, the following code runs and cause an exception:

var hasAutomationEqualityBug = (function () {
    /* global window */
    if (typeof window === 'undefined') { return false; }
    for (var k in window) {
        if (!blacklistedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
            try {
                equalsConstructorPrototype(window[k]);
            } catch (e) {
                return true;
            }
        }
    }
    return false;
}());

The problem is that window.frameElement throwing the following example:

Uncaught SecurityError: Failed to read the 'frame' property from 'Window': Blocked a frame with origin "https://frontend.dev:8001" from accessing a frame with origin "http://frontend.dev:8000".  The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "http". Protocols must match.

naorye avatar Oct 15 '15 12:10 naorye

I have the same problem. Confirmed.

jtwalters avatar Oct 15 '15 18:10 jtwalters

So the code snippet you're referencing comes from the ES5-shim, but is this really a VJS issue? Trying to access an HTTPS-origin frame from an HTTP-origin frame isn't ever going to work for obvious security reasons. Mind putting up an example?

mmcc avatar Oct 15 '15 18:10 mmcc

Sounds like frame is another key that es5-shim might need to add to the blacklistedKeys array. See https://github.com/es-shims/es5-shim/issues/322 for reference.

gkatsev avatar Oct 15 '15 18:10 gkatsev

@mmcc in my case, the issue is occurring with an https iframe inside a cross-origin, https page. Of course we shouldn't expect it to work, but it's still a bug that is effectively breaking my iframe's JS behavior due to the generated SecurityError.

jtwalters avatar Oct 15 '15 18:10 jtwalters

What version of videojs are you using? 5.0? Are you using our ie8 shim?

gkatsev avatar Oct 15 '15 18:10 gkatsev

* Video.js 5.0.0 <http://videojs.com/>

I don't believe I'm using any IE8 shim. Not sure how to confirm that.

This SecurityError is with latest stable Google Chrome, BTW.

jtwalters avatar Oct 15 '15 18:10 jtwalters

@jtwalters do you have an example?

gkatsev avatar Oct 15 '15 18:10 gkatsev

I put together this jsfiddle which will give you a SecurityError viewable in the console.

jtwalters avatar Oct 15 '15 18:10 jtwalters

Of course this is an oversimplified example and doesn't actually represent the error that I have.

jtwalters avatar Oct 15 '15 18:10 jtwalters

Ah, I think i see where it's coming from. This is from our object.assign module which uses an older version of object-keys which has a newer version which has frameElement blacklisted. Do you want to put together a PR that updates object.assign to the latest version?

gkatsev avatar Oct 15 '15 19:10 gkatsev

I am using videoJS with npm and require it like this: var videojs = require(video.js); I didn't ask to include es5 shim.

naorye avatar Oct 15 '15 20:10 naorye

Whenever videojs is inside an iframe, I get this error.

Any solution?

naorye avatar Oct 18 '15 16:10 naorye

Yes, me too, same problem. Videojs 5.0.0 produces the security error in Google Chrome, but the security error stops videojs from loading inside an iFrame. A quick fix would be HUGELY appreciated!

richardbushell avatar Oct 18 '15 16:10 richardbushell

Same issue, only in the latest chrome (v 46)

andriidrebot avatar Oct 19 '15 06:10 andriidrebot

If anyone needs a quick fix in the meantime, modifying this in your own hosted copy of Video.js works for me in Chrome 46:

var hasAutomationEqualityBug = (function () {
  ...
    for (var k in window) {
      if (k === 'frameElement') {
        continue;
      }
      ...
    }
}());

rickyblaha avatar Oct 19 '15 18:10 rickyblaha

@rickyblaha I am using the CDN version of videojs and the quick fix doesn't fix that issue. Did you manually change the video.js file?

jemoreno avatar Oct 19 '15 20:10 jemoreno

@jemoreno, just edited my comment to clarify. Since that is immediately invoked it would need to be changed within the library, so I did make that change on my own CDN-hosted copy.

rickyblaha avatar Oct 19 '15 20:10 rickyblaha

Working on getting this fixed.

gkatsev avatar Oct 19 '15 20:10 gkatsev

Waiting on https://github.com/ljharb/object-keys/pull/17

gkatsev avatar Oct 19 '15 20:10 gkatsev

Also note that the latest versions of es5-shim and object-keys have the blacklisting wrapped with a try/catch, so this should already be "fixed" in the latest version.

That said, thanks for the "frame" PR, as I'd still like to blacklist all throwing keys that I can :-)

ljharb avatar Oct 19 '15 21:10 ljharb