[wpt-sync] Sync PR 64303 - WebKit export of https://bugs.webkit.org/show_bug.cgi?id=322522
Categories
(Core :: DOM: Core & HTML, task, P4)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox162 | --- | fixed |
People
(Reporter: wpt-sync, Unassigned)
References
()
Details
(Whiteboard: [wptsync downstream])
Sync web-platform-tests PR 64303 into mozilla-central (this bug is closed when the sync is complete).
PR: https://github.com/web-platform-tests/wpt/pull/64303
Details from upstream follow.
Kiet Ho <kiet.ho@apple.com> wrote:
WebKit export of https://bugs.webkit.org/show_bug.cgi?id=322522
WebKit export from bug: JavaScript `<!---->import .<!---->.<!---->.<!----> with {<!----> type:<!----> "<!---->json"<!----> }<!---->`<!----> can inadvertently load the JSON as JavaScript
<pre>
JavaScriptimport ... with { type: "json" }can inadvertently load the JSON as JavaScriptIf a JSON is imported in JavaScript using the
importsyntax:import module from "url/to/malicious-javascript.js" with { type: "json" };and assuming
url/to/malicious-javascript.jsis served with MIME type
application/javascript, ScriptModuleLoader::notifyFinished will treat the
loaded source code as JavaScript and not JSON:(1) if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType))
(2) type = ModuleType::JavaScript;
(3) else if (loader.parameters() && loader.parameters()->type() == JSC::ScriptFetchParameters::JSON && MIMETypeRegistry::isSupportedJSONMIMEType(mimeType))
type = ModuleType::JSON;
else {
rejectWithFetchError(...);
return;
}(1) succeeds because the MIME type is JavaScript, so (2) executes, and the file
is treated as JavaScript, even though it's loaded with{ type: "json" }. (3)
checks for JSON MIME type, but it's not reached because check (1) succeeds. The
result is that the loaded file gets executed as JavaScript instead of JSON.Security ramification: If JavaScript from a site A imports a JSON from another
site B, it can change the JSON file to be a JavaScript file, and make its MIME
typeapplication/javascript. Then, when site A imports the JSON, JavaScript
from site B gets run instead.Fix this by changing the check to a switch-case on the module type, which brings
two benefits:
- If a new JSC::ScriptFetchParameters::Type is introduced in the future, the
compiler will warn us to add a new check for it.- Ensures that non-JavaScript types don't use the default path of treating it
as JavaScript.WebKit-Bug: <a href="https://bugs.webkit.org/show_bug.cgi?id=322522">https://bugs.webkit.org/show_bug.cgi?id=322522</a>
</pre>
| Assignee | ||
Updated•18 days ago
|
| Assignee | ||
Updated•6 days ago
|
| Assignee | ||
Updated•6 days ago
|
| Assignee | ||
Comment 1•6 days ago
|
||
Pushed to try (stability) https://treeherder.mozilla.org/jobs?repo=try&landoInstance=lando-prod-2025&landoCommitID=117812
| Assignee | ||
Comment 2•5 days ago
|
||
CI Results
Ran 9 Firefox configurations based on mozilla-central, and Firefox, and Chrome on GitHub CI
Total 26 tests and 8 subtests
Status Summary
Firefox
OK : 3[GitHub] 26[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt]
PASS: 318[GitHub] 411[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt]
Chrome
OK : 3
PASS: 318
Links
Comment 4•2 days ago
|
||
| bugherder | ||
Description
•