Skip to content
This repository has been archived by the owner on Feb 25, 2018. It is now read-only.

Document CSSOM CORS: "SecurityError: The operation is insecure." with ext. CSS #7

Closed
anselmh opened this issue Apr 3, 2014 · 11 comments
Assignees

Comments

@anselmh
Copy link
Owner

anselmh commented Apr 3, 2014

When using external CSS (like a CDNed CSS, ext. Webfonts) Firefox throws an error in part of our script:
resp. https://gist.github.com/ydaniv/3033012/#file-mozgetmatchedcssrules-js-L23

There are some hints for this here: http://stackoverflow.com/a/5323868 and http://stackoverflow.com/questions/3211536/accessing-cross-domain-stylesheet-with-cssrules.

The issue, solution and circumvention hack should be well documented so authors don't run into it not knowing what is going on.

@anselmh anselmh added the bug label Apr 3, 2014
@anselmh
Copy link
Owner Author

anselmh commented Apr 3, 2014

Can be manually fixed by site authors:

p.s. I fixed the security problem by avoiding @import and setting a header in PHP:
header('Access-Control-Allow-Origin:*');
then adding the crossorigin attribute to the <link crossorigin="use-credentials"

respectively setting it in the .htaccess file.
We should still try to fix this in our script or it needs to be documented but this is the short fix.

ccing @mattbbp

@anselmh
Copy link
Owner Author

anselmh commented May 6, 2014

I researched a bit more and found out we could only fix this by circumventing the CSSOM CORS. This is a massive hack which I don’t think should land in our codebase as it has too many side effects.

Therefore I’ll rename the issue as it only needs to be documented.

@anselmh anselmh changed the title Solve "SecurityError: The operation is insecure." with ext. CSS Document CSSOM CORS: "SecurityError: The operation is insecure." with ext. CSS May 6, 2014
@anselmh anselmh self-assigned this May 6, 2014
@anselmh anselmh added Documentation and removed bug labels May 6, 2014
@lolmaus
Copy link

lolmaus commented Oct 24, 2014

Hi! I receive "SecurityError: The operation is insecure." even though i'm bundling polyfill.object-fit.js with a relative URL.

Is there something i can do to solve it?

@anselmh
Copy link
Owner Author

anselmh commented Oct 24, 2014

Is there any SSL involved or a different port / host?

@lolmaus
Copy link

lolmaus commented Oct 24, 2014

No SSL.

The web server is running in a virtualbox, serving all assets locally (i. e. with relative paths). I'm opening it in browser as http://foo:3000.

@lolmaus
Copy link

lolmaus commented Oct 24, 2014

PS Firefox.

@anselmh
Copy link
Owner Author

anselmh commented Oct 24, 2014

So, are you using Webfonts that are from a 3rd party, by chance? Somewhere there must be another host / protocol involded to trigger this issue as far as I know. It’s very annoying but this these are the circumstances we’re dealing with when using JS (and we can’t use anything else here) nowadays for such stuff.

@lolmaus
Copy link

lolmaus commented Oct 24, 2014

I do use web fonts served from an external URL. I thought only the fitted images are concerned...

@anselmh
Copy link
Owner Author

anselmh commented Oct 24, 2014

Okay, then this is the issue. Unfortunately, as the polyfill needs to read out your computed CSS it does exactly that. And this means all inherited properties and values, such as fonts as well. I’m not sure if that is somehow avoidable, I have a look at this specific GetMatchedCSSRules.js anyways as it causes major problems and performance issues as well.

@anselmh
Copy link
Owner Author

anselmh commented Oct 24, 2014

By the way this should not affect your live setup when protocols and ports match (=non mixed content, so HTTP or HTTPS only).

@luruke
Copy link

luruke commented Feb 6, 2015

I had a similar problem like @lolmaus (I was using typekit)

I solved adding this code inside getSheetRules():

if (stylesheet.href && stylesheet.href.match(/typekit/)) {
            return [];
}

anselmh added a commit that referenced this issue Feb 23, 2015
This adds an option called `disableCrossDomain: 'true'`
to ignore external stylesheets.

This is needed when you can’t allow CORS due to your CSP
or can’t set a CSP at all. This closes #7, closes #15
and fixes some bug reports related to that behavior.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants