commit 29510a29713bfa516c810e26a7ddd72631145cb5
parent b6c54c546d7ee108d904310b44255da06dcbae81
Author: Daniel Minor <dminor@mozilla.com>
Date: Fri, 12 Dec 2025 14:12:35 +0000
Bug 1994828 - Add checks for wasm mime type for script loading; r=dom-core,necko-reviewers,smaug,sunil
Differential Revision: https://phabricator.services.mozilla.com/D270149
Diffstat:
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp
@@ -4560,7 +4560,13 @@ static bool MimeTypeMatchesExpectedModuleType(
NS_ConvertUTF8toUTF16 typeString(mimeType);
switch (expectedModuleType) {
- case JS::ModuleType::JavaScript:
+ case JS::ModuleType::JavaScriptOrWasm:
+#ifdef NIGHTLY_BUILD
+ if (StaticPrefs::javascript_options_experimental_wasm_esm_integration()) {
+ return nsContentUtils::IsJavascriptMIMEType(typeString) ||
+ nsContentUtils::HasWasmMimeTypeEssence(typeString);
+ }
+#endif
return nsContentUtils::IsJavascriptMIMEType(typeString);
case JS::ModuleType::JSON:
return nsContentUtils::IsJsonMimeType(typeString);
diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -53,6 +53,7 @@
#include "mozilla/net/OpaqueResponseUtils.h"
#include "mozilla/net/UrlClassifierCommon.h"
#include "mozilla/net/UrlClassifierFeatureFactory.h"
+#include "mozilla/StaticPrefs_javascript.h"
#include "nsBufferedStreams.h"
#include "nsCOMPtr.h"
#include "nsCRT.h"
@@ -3232,6 +3233,14 @@ nsresult EnsureMIMEOfScript(HttpBaseChannel* aChannel, nsIURI* aURI,
return NS_OK;
}
+#ifdef NIGHTLY_BUILD
+ if (StaticPrefs::javascript_options_experimental_wasm_esm_integration()) {
+ if (nsContentUtils::HasWasmMimeTypeEssence(typeString)) {
+ return NS_OK;
+ }
+ }
+#endif
+
ReportMimeTypeMismatch(aChannel, "BlockWorkerWithWrongMimeType", aURI,
contentType, Report::Error);
return NS_ERROR_CORRUPTED_CONTENT;
@@ -3240,6 +3249,14 @@ nsresult EnsureMIMEOfScript(HttpBaseChannel* aChannel, nsIURI* aURI,
// ES6 modules require a strict MIME type check.
if (internalType == nsIContentPolicy::TYPE_INTERNAL_MODULE ||
internalType == nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD) {
+#ifdef NIGHTLY_BUILD
+ if (StaticPrefs::javascript_options_experimental_wasm_esm_integration()) {
+ if (nsContentUtils::HasWasmMimeTypeEssence(typeString)) {
+ return NS_OK;
+ }
+ }
+#endif
+
ReportMimeTypeMismatch(aChannel, "BlockModuleWithWrongMimeType", aURI,
contentType, Report::Error);
return NS_ERROR_CORRUPTED_CONTENT;
@@ -3280,6 +3297,14 @@ void WarnWrongMIMEOfScript(HttpBaseChannel* aChannel, nsIURI* aURI,
return;
}
+#ifdef NIGHTLY_BUILD
+ if (StaticPrefs::javascript_options_experimental_wasm_esm_integration()) {
+ if (nsContentUtils::HasWasmMimeTypeEssence(typeString)) {
+ return;
+ }
+ }
+#endif
+
ReportMimeTypeMismatch(aChannel, "WarnScriptWithWrongMimeType", aURI,
contentType, Report::Warning);
}