You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Do browsers allow empty/missing Content-Type headers on <link rel="stylesheet">? #3457
We should write some tests, and see what browsers do. In the best case, Chrome is the only browser doing this, and we can fix it to pass some newly-written web platform tests. In the worst case, everyone has this hole, and we need to patch the spec to allow it.
<link rel="stylesheet" href="data:,body{color:blue}" type="text/css"> adds an entry to document.styleSheets at both Chromium and Firefox. At Chromium the CSSStyleSheet does not have a cssRules property, at Firefox the CSSStyleSheet does have a cssRules property with the length of the CSSRuleList set to 0.
@guest271314 is your HTML document in standards mode? Because otherwise you're hitting a quirk. Another thing to test here is a cross-origin stylesheet. And maybe also the unknown/unknown, application/unknown, and */* MIME types (from MIME Sniffing). (And the various combinations of these.)
Refused to apply style from 'https://gist.githubusercontent.com/guest271314/451634131a32d6f302744f2cbee92512/raw/296db2d197f81f073eb1285f630ebcc87a53692c/crossOriginCSSRequestedWithLinkElement.css' because its MIME type ('text/plain') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
The load event is dispatched for the remaining requests.
Only the local request where .css extension is set has style applied to the element (the first <p> element).
Firefox 60
The load event is dispatched for the local request where .css extension is set has style applied to the element (the first <p> element); and for data URL with MIME type set to "*/*" (the sixth <p> element).
The error message for the cross-origin (gist) request
DOMException: The operation is insecure.
https://gist.githubusercontent.com/guest271314/451634131a32d6f302744f2cbee92512/raw/296db2d197f81f073eb1285f630ebcc87a53692c/crossOriginCSSRequestedWithLinkElement.css
The error event is dispatched for the remainder of <p> elements.
Including crossOrigin="anonymous" to gist request results in DOMException: The operation is insecure. not being logged at Firefox 60, though the error event is still dispatched and the associated style is not applied to the selector.
Cross-origin was meant as a stylesheet on a different origin from the HTML document. No crossorigin attribute needed (though maybe we should test that as well, but I hope that it doesn't change the results).
The only change that can detect when crossOrigin attribute set to "anonymous" is that the error DOMException: The operation is insecure. is not logged at console.
The differences between Chromium and Firefox that have noticed so far are described at #3457 (comment):
The error event is not dispatched at Chromium for any of the tests save for gist request (cross-origin)
Firefox dispatches error event for all but two requests
Firefox applies styles for response having MIME type set to "*/*"
I have tests for this at web-platform-tests/wpt#13144. The HTML Standard does allude to missing and broken Content-Type resulting in text/css treatment, but this should be spelled out better. While testing I also found some issues with Chrome/Edge/Safari that I don't think are allowed (they're loose for some cases where there's a valid Content-Type). I'll file bugs on those.
It's a little bit unclear to me how to clarify the standard here, since there isn't a clear loading pipeline as things stand.
See whatwg/mimesniff#30 (comment) for why I abstained from testing */* for now. It'd be easy to add, but it's unclear to me what the correct result is and where it should be special cased. I suspect we don't want to special case it for style sheet loadding.
Activity
guest271314 commentedon Feb 16, 2018
Both Chromium 64 and Firefox 57 load the CSS with no value for
Content-TypesetWith
''set as value ofContent-TypeChromium create an entry at
document.styleSheetsthough the style rules are not applied. At Firefox the style rules are applied.guest271314 commentedon Feb 16, 2018
<link rel="stylesheet" href="data:,body{color:blue}" type="text/css">adds an entry todocument.styleSheetsat both Chromium and Firefox. At Chromium theCSSStyleSheetdoes not have acssRulesproperty, at Firefox theCSSStyleSheetdoes have acssRulesproperty with thelengthof theCSSRuleListset to0.guest271314 commentedon Feb 16, 2018
Firefox 60 has the same behaviour as Firefox 57
does apply style rules to the
document.Response headers
annevk commentedon Feb 17, 2018
@guest271314 is your HTML document in standards mode? Because otherwise you're hitting a quirk. Another thing to test here is a cross-origin stylesheet. And maybe also the
unknown/unknown,application/unknown, and*/*MIME types (from MIME Sniffing). (And the various combinations of these.)guest271314 commentedon Feb 17, 2018
@annevk What is "standards mode"? What exactly are we trying to determine? If the resource is requested, or if the styles are applied to the
document?annevk commentedon Feb 17, 2018
@guest271314 if an document starts with
<!doctype html>it'll be in "standards mode" (no-quirks mode per the specifications).I think what you tested was a good start:
document.styleSheetsaffected (test after load has happened/failed)?getComputedStyle())?loadevent dispatch on<link>?Don't think there are many other assertable things here.
guest271314 commentedon Feb 17, 2018
@annevk Not entirely sure what the parameters of a "cross-origin" stylesheet are? Do you mean where
Access-Control-Allow-Origin:*header is not set?These are the previous tests with suggested inclusions
plnkr https://plnkr.co/edit/wiEL5drnUvIGkdqmQQu2?p=preview.
Interesting results:
Chromium 64
Only dispatches
errorevent for a requested gist https://gist.githubusercontent.com/guest271314/451634131a32d6f302744f2cbee92512/raw/296db2d197f81f073eb1285f630ebcc87a53692c/crossOriginCSSRequestedWithLinkElement.css where was attempting to satisfy "cross-origin" request test. MIME checking occurs for the cross-origin request as wellThe
loadevent is dispatched for the remaining requests.Only the local request where
.cssextension is set has style applied to the element (the first<p>element).Firefox 60
The
loadevent is dispatched for the local request where.cssextension is set has style applied to the element (the first<p>element); and fordata URLwith MIME type set to"*/*"(the sixth<p>element).The error message for the cross-origin (gist) request
The
errorevent is dispatched for the remainder of<p>elements.guest271314 commentedon Feb 17, 2018
Including
crossOrigin="anonymous"to gist request results inDOMException: The operation is insecure.not being logged at Firefox 60, though theerrorevent is still dispatched and the associated style is not applied to the selector.annevk commentedon Feb 17, 2018
Cross-origin was meant as a stylesheet on a different origin from the HTML document. No
crossoriginattribute needed (though maybe we should test that as well, but I hope that it doesn't change the results).guest271314 commentedon Feb 17, 2018
The only change that can detect when
crossOriginattribute set to"anonymous"is that the errorDOMException: The operation is insecure.is not logged atconsole.The differences between Chromium and Firefox that have noticed so far are described at #3457 (comment):
errorevent is not dispatched at Chromium for any of the tests save for gist request (cross-origin)errorevent for all but two requests"*/*"annevk commentedon Feb 18, 2018
The best way would be through https://github.com/w3c/web-platform-tests which has support for that, so once we have tests all browsers can then use them as well.
annevk commentedon Sep 24, 2018
I have tests for this at web-platform-tests/wpt#13144. The HTML Standard does allude to missing and broken
Content-Typeresulting intext/csstreatment, but this should be spelled out better. While testing I also found some issues with Chrome/Edge/Safari that I don't think are allowed (they're loose for some cases where there's a validContent-Type). I'll file bugs on those.It's a little bit unclear to me how to clarify the standard here, since there isn't a clear loading pipeline as things stand.
cc @domfarolino
annevk commentedon Sep 24, 2018
See whatwg/mimesniff#30 (comment) for why I abstained from testing
*/*for now. It'd be easy to add, but it's unclear to me what the correct result is and where it should be special cased. I suspect we don't want to special case it for style sheet loadding.HTML: test stylesheet loading text/css requirement
Bug 1493308 [wpt PR 13144] - HTML: test stylesheet loading text/css r…
Bug 1493308 [wpt PR 13144] - HTML: test stylesheet loading text/css r…
Bug 1493308 [wpt PR 13144] - HTML: test stylesheet loading text/css r…
Bug 1493308 [wpt PR 13144] - HTML: test stylesheet loading text/css r…
Bug 1493308 [wpt PR 13144] - HTML: test stylesheet loading text/css r…