mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-30 02:57:29 +09:00
Issue #2402 - Optionally strictly enforce the MIME type of scripts loaded by importScripts(). https://bugzilla.mozilla.org/show_bug.cgi?id=1514680 This is default on in Firefox 67 but Moonchild requested it be set off by default.
This commit is contained in:
parent
b7abd4a127
commit
811bcbefd4
3 changed files with 34 additions and 22 deletions
|
|
@ -82,6 +82,8 @@ MimeTypeMismatch=The resource from “%1$S” was blocked due to MIME type misma
|
||||||
XCTOHeaderValueMissing=X-Content-Type-Options header warning: value was “%1$S”; did you mean to send “nosniff”?
|
XCTOHeaderValueMissing=X-Content-Type-Options header warning: value was “%1$S”; did you mean to send “nosniff”?
|
||||||
|
|
||||||
BlockScriptWithWrongMimeType=Script from “%1$S” was blocked because of a disallowed MIME type.
|
BlockScriptWithWrongMimeType=Script from “%1$S” was blocked because of a disallowed MIME type.
|
||||||
|
# LOCALIZATION NOTE: Do not translate "importScripts()"
|
||||||
|
BlockImportScriptsWithWrongMimeType=Loading script from “%1$S” with importScripts() was blocked because of a disallowed MIME type.
|
||||||
|
|
||||||
# LOCALIZATION NOTE: Do not translate "data: URI".
|
# LOCALIZATION NOTE: Do not translate "data: URI".
|
||||||
BlockTopLevelDataURINavigation=Navigation to toplevel data: URI not allowed (Blocked loading of: “%1$S”)
|
BlockTopLevelDataURINavigation=Navigation to toplevel data: URI not allowed (Blocked loading of: “%1$S”)
|
||||||
|
|
|
||||||
|
|
@ -2202,6 +2202,9 @@ pref("security.sri.enable", true);
|
||||||
// Block scripts with wrong MIME type such as image/ or video/.
|
// Block scripts with wrong MIME type such as image/ or video/.
|
||||||
pref("security.block_script_with_wrong_mime", true);
|
pref("security.block_script_with_wrong_mime", true);
|
||||||
|
|
||||||
|
// Block scripts with wrong MIME type when loading via importScripts() in workers.
|
||||||
|
pref("security.block_importScripts_with_wrong_mime", false);
|
||||||
|
|
||||||
// Block images of wrong MIME for XCTO: nosniff.
|
// Block images of wrong MIME for XCTO: nosniff.
|
||||||
pref("security.xcto_nosniff_block_images", false);
|
pref("security.xcto_nosniff_block_images", false);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1160,35 +1160,42 @@ EnsureMIMEOfScript(nsIURI* aURI, nsHttpResponseHead* aResponseHead, nsILoadInfo*
|
||||||
|
|
||||||
if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("text/plain"))) {
|
if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("text/plain"))) {
|
||||||
// script load has type text/plain
|
// script load has type text/plain
|
||||||
return NS_OK;
|
} else if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("text/xml"))) {
|
||||||
}
|
|
||||||
|
|
||||||
if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("text/xml"))) {
|
|
||||||
// script load has type text/xml
|
// script load has type text/xml
|
||||||
return NS_OK;
|
} else if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("application/octet-stream"))) {
|
||||||
}
|
|
||||||
|
|
||||||
if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("application/octet-stream"))) {
|
|
||||||
// script load has type application/octet-stream
|
// script load has type application/octet-stream
|
||||||
return NS_OK;
|
} else if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("application/xml"))) {
|
||||||
}
|
|
||||||
|
|
||||||
if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("application/xml"))) {
|
|
||||||
// script load has type application/xml
|
// script load has type application/xml
|
||||||
return NS_OK;
|
} else if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("text/html"))) {
|
||||||
}
|
|
||||||
|
|
||||||
if (StringBeginsWith(contentType, NS_LITERAL_CSTRING("text/html"))) {
|
|
||||||
// script load has type text/html
|
// script load has type text/html
|
||||||
return NS_OK;
|
} else if (contentType.IsEmpty()) {
|
||||||
}
|
|
||||||
|
|
||||||
if (contentType.IsEmpty()) {
|
|
||||||
// script load has no type
|
// script load has no type
|
||||||
return NS_OK;
|
} else {
|
||||||
|
// script load has unknown type
|
||||||
|
// We restrict importScripts() in worker code to JavaScript MIME types.
|
||||||
|
if (aLoadInfo->InternalContentPolicyType() ==
|
||||||
|
nsIContentPolicy::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS) {
|
||||||
|
// Instead of consulting Preferences::GetBool() all the time we
|
||||||
|
// can cache the result to speed things up.
|
||||||
|
static bool sCachedBlockImportScriptsWithWrongMime = false;
|
||||||
|
static bool sIsInited = false;
|
||||||
|
if (!sIsInited) {
|
||||||
|
sIsInited = true;
|
||||||
|
Preferences::AddBoolVarCache(
|
||||||
|
&sCachedBlockImportScriptsWithWrongMime,
|
||||||
|
"security.block_importScripts_with_wrong_mime");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not block the load if the feature is not enabled.
|
||||||
|
if (!sCachedBlockImportScriptsWithWrongMime) {
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReportTypeBlocking(aURI, aLoadInfo, "BlockImportScriptsWithWrongMimeType");
|
||||||
|
return NS_ERROR_CORRUPTED_CONTENT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// script load has unknown type
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue