Bug 1877792 - Part 11: Only allow expected mime types r=dom-worker-reviewers,dom-core,asuth,hsivonen
Differential Revision: https://phabricator.services.mozilla.com/D218558
This commit is contained in:
@@ -3868,6 +3868,25 @@ bool ScriptLoader::ShouldCompileOffThread(ScriptLoadRequest* aRequest) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool MimeTypeMatchesExpectedModuleType(
|
||||
nsIChannel* aChannel, JS::ModuleType expectedModuleType) {
|
||||
nsAutoCString mimeType;
|
||||
aChannel->GetContentType(mimeType);
|
||||
NS_ConvertUTF8toUTF16 typeString(mimeType);
|
||||
|
||||
if (expectedModuleType == JS::ModuleType::JavaScript &&
|
||||
nsContentUtils::IsJavascriptMIMEType(typeString)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (expectedModuleType == JS::ModuleType::JSON &&
|
||||
nsContentUtils::IsJsonMimeType(typeString)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
nsresult ScriptLoader::PrepareLoadedRequest(ScriptLoadRequest* aRequest,
|
||||
nsIIncrementalStreamLoader* aLoader,
|
||||
nsresult aStatus) {
|
||||
@@ -3959,12 +3978,9 @@ nsresult ScriptLoader::PrepareLoadedRequest(ScriptLoadRequest* aRequest,
|
||||
if (aRequest->IsModuleRequest()) {
|
||||
ModuleLoadRequest* request = aRequest->AsModuleRequest();
|
||||
|
||||
// When loading a module, only responses with a JavaScript MIME type are
|
||||
// When loading a module, only responses with an expected MIME type are
|
||||
// acceptable.
|
||||
nsAutoCString mimeType;
|
||||
channel->GetContentType(mimeType);
|
||||
NS_ConvertUTF8toUTF16 typeString(mimeType);
|
||||
if (!nsContentUtils::IsJavascriptMIMEType(typeString)) {
|
||||
if (!MimeTypeMatchesExpectedModuleType(channel, request->mModuleType)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user