Closed Bug 2087424 Opened 18 days ago Closed 2 days ago

[wpt-sync] Sync PR 64303 - WebKit export of https://bugs.webkit.org/show_bug.cgi?id=322522

Categories

(Core :: DOM: Core & HTML, task, P4)

task

Tracking

()

RESOLVED FIXED
162 Branch
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>
JavaScript import ... with { type: &quot;json&quot; } can inadvertently load the JSON as JavaScript

If a JSON is imported in JavaScript using the import syntax:

 import module from &quot;url/to/malicious-javascript.js&quot; with { type: &quot;json&quot; };

and assuming url/to/malicious-javascript.js is 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: &quot;json&quot; }. (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
type application/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:

  1. If a new JSC::ScriptFetchParameters::Type is introduced in the future, the
    compiler will warn us to add a new check for it.
  2. 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>

Whiteboard: [wptsync downstream] → [wptsync downstream error]
Component: web-platform-tests → DOM: Core & HTML
Product: Testing → Core
Whiteboard: [wptsync downstream error] → [wptsync downstream]

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

Gecko CI (Treeherder)
GitHub PR Head
GitHub PR Base

Status: NEW → RESOLVED
Closed: 2 days ago
Resolution: --- → FIXED
Target Milestone: --- → 162 Branch
You need to log in before you can comment on or make changes to this bug.