File tree Expand file tree Collapse file tree 1 file changed +30
-2
lines changed
Expand file tree Collapse file tree 1 file changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ async function checkIsStylesheetValid(
3838 return true ;
3939 }
4040 CHECKED_STYLESHEET_HREFS . add ( styleSheet . href ) ;
41+ ensureCORSEnabledForStylesheet ( styleSheet ) ;
4142 } else if (
4243 // Inline css
4344 potentialOwnerNode instanceof Element &&
@@ -63,11 +64,38 @@ function isValidCSSRule(rule: CSSRule): boolean {
6364 return false ;
6465 }
6566
66- if ( ! ( rule instanceof CSSGroupingRule || rule instanceof CSSKeyframesRule ) ) {
67+ if (
68+ ! (
69+ rule instanceof CSSGroupingRule ||
70+ rule instanceof CSSKeyframesRule ||
71+ rule instanceof CSSImportRule
72+ )
73+ ) {
6774 return true ;
6875 }
6976
70- return [ ...rule . cssRules ] . every ( isValidCSSRule ) ;
77+ let rulesToCheck : Array < CSSRule > = [ ] ;
78+
79+ if ( rule instanceof CSSImportRule ) {
80+ const styleSheet = rule . styleSheet ;
81+ if ( styleSheet != null ) {
82+ ensureCORSEnabledForStylesheet ( styleSheet ) ;
83+ rulesToCheck = [ ...styleSheet . cssRules ] ;
84+ }
85+ } else {
86+ rulesToCheck = [ ...rule . cssRules ] ;
87+ }
88+
89+ return rulesToCheck . every ( isValidCSSRule ) ;
90+ }
91+
92+ function ensureCORSEnabledForStylesheet ( styleSheet : CSSStyleSheet ) : void {
93+ try {
94+ // Ensure all non same origin stylesheets can be accessed (CORS)
95+ styleSheet . cssRules ;
96+ } catch ( e ) {
97+ updateStateOnInvalidStylesheet ( false , styleSheet ) ;
98+ }
7199}
72100
73101async function hashString ( content : string ) : Promise < string > {
You can’t perform that action at this time.
0 commit comments