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

Security Error: Not allowed to access cross-origin stylesheet #2853

Open
BrandonML opened this issue Jan 26, 2023 · 7 comments · May be fixed by #2979
Open

Security Error: Not allowed to access cross-origin stylesheet #2853

BrandonML opened this issue Jan 26, 2023 · 7 comments · May be fixed by #2979

Comments

@BrandonML
Copy link

Your Environment

  • flatpickr version used: 4.6.3 and 4.6.13
  • Browser name and version: Chrome 109
  • OS and version: Windows 11

Recently we've been logging security errors from Flatpickr in Sentry. The issue doesn't appear to be widespread, so far only logged about 20 times, but I have been unable to recreate it and, frankly, I'm baffled.

All of the events logged are from mobile devices, including OS Android 10-12, and iOS 15-16. The events logged so far include both Chrome Mobile 108-109 and Mobile Safari 15-16.

The exception message varies by OS, but I'm guessing it's the same issue. For Android users, the exception is "Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules". For iOS the exception is, "Not allowed to access cross-origin stylesheet".

We use Flatpickr in two different applications. One implementation calls Flatpickr CSS and JS files from our server, and both resources have the same domain. The other implementation calls Flatpickr resources via CDN. The exception is being logged from both applications, which confuses me even more, since the one implementation has the files hosted on our server (how can there be a cross-origin issue if the files are on the same server and domain?).

The line of code that Sentry has highlighted in the stack track is
{snip} styleSheets.length;n++){var t=document.styleSheets[n];if(t.cssRules){try{t.cssRules}catch(e){continue}e=t;break}}return null!=e?e:(a=documen {snip}

Has anyone else run into this problem?

@KapustinVadim1991
Copy link

The same problem! Haven't found a solution yet.

@MeesterDev
Copy link

MeesterDev commented Feb 1, 2023

Just appeared in our Sentry log as well.

Our first stylesheet is a Google Fonts link, which is cross origin.

Firefox console:
>> document.styleSheets[0].cssRules
❌ Uncaught DOMException: CSSStyleSheet.cssRules getter: Not allowed to access cross-origin stylesheet

@BrandonML
Copy link
Author

Yeah, this one is proving to be complicated. And I can't make sense of it.

If it were only occurring in our application that calls Flatpickr from a CDN it would at least be plausible, although I am clueless about how or why. But it's also being logged from a different application that hosts Flatpickr CSS and JS on our server.

How can a cross-origin error be encountered when everything is being called from the same domain? I can't come up with a plausible explanation.

@krishaantechnology
Copy link

Importing flatpicker.css file fixed this issue for me.

In my case.

import '../../../node_modules/flatpickr/dist/flatpickr.css'

@wdog
Copy link

wdog commented Jun 13, 2023

Adding this to my resources/js/app.js works (only 2 ..)

import "../../node_modules/flatpickr/dist/flatpickr.css";

@christopheraseidl
Copy link

Adding this to my resources/js/app.js works (only 2 ..)

import "../../node_modules/flatpickr/dist/flatpickr.css";

This solution also worked for me.

@R70YNS
Copy link

R70YNS commented Mar 13, 2024

Importing flatpicker.css file fixed this issue for me.

In my case.

import '../../../node_modules/flatpickr/dist/flatpickr.css'

Worked for me - could do with above PR merging.

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 a pull request may close this issue.

7 participants