Bug 1877792 - Part 1: Change HttpBaseChannel.cpp to allow application/json r=yulia,necko-reviewers,jesup,valentin

Differential Revision: https://phabricator.services.mozilla.com/D155161
This commit is contained in:
Jonatan Klemets
2024-08-22 14:21:48 +00:00
parent 660be36926
commit 5ab8769ece
3 changed files with 31 additions and 3 deletions

View File

@@ -2896,8 +2896,9 @@ nsresult ProcessXCTO(HttpBaseChannel* aChannel, nsIURI* aURI,
if (aLoadInfo->GetExternalContentPolicyType() ==
ExtContentPolicy::TYPE_SCRIPT) {
if (nsContentUtils::IsJavascriptMIMEType(
NS_ConvertUTF8toUTF16(contentType))) {
auto utf16ContentType = NS_ConvertUTF8toUTF16(contentType);
if (nsContentUtils::IsJavascriptMIMEType(utf16ContentType) ||
nsContentUtils::IsJsonMimeType(utf16ContentType)) {
return NS_OK;
}
ReportMimeTypeMismatch(aChannel, "MimeTypeMismatch2", aURI, contentType,
@@ -2945,6 +2946,12 @@ nsresult EnsureMIMEOfScript(HttpBaseChannel* aChannel, nsIURI* aURI,
return NS_OK;
}
if (nsContentUtils::IsJsonMimeType(typeString)) {
AccumulateCategorical(
Telemetry::LABELS_SCRIPT_BLOCK_INCORRECT_MIME_3::text_json);
return NS_OK;
}
switch (aLoadInfo->InternalContentPolicyType()) {
case nsIContentPolicy::TYPE_SCRIPT:
case nsIContentPolicy::TYPE_INTERNAL_SCRIPT:
@@ -3139,7 +3146,8 @@ void WarnWrongMIMEOfScript(HttpBaseChannel* aChannel, nsIURI* aURI,
nsAutoCString contentType;
aResponseHead->ContentType(contentType);
NS_ConvertUTF8toUTF16 typeString(contentType);
if (!nsContentUtils::IsJavascriptMIMEType(typeString)) {
if (!nsContentUtils::IsJavascriptMIMEType(typeString) &&
!nsContentUtils::IsJsonMimeType(typeString)) {
ReportMimeTypeMismatch(aChannel, "WarnScriptWithWrongMimeType", aURI,
contentType, Report::Warning);
}