Skip to content
Info disclosure Disclosed report Intermediate CVE-2022-22760

Detecting whether the content-type of a cross-origin resource is application/javascript through importScripts

A Web Worker's importScripts function reveals whether a cross-origin resource has the application/javascript content-type by showing different error messages for a content-type mismatch versus a syntax error. An attacker could use this to perform XS-Search attacks, inferring information about cross-origin resources.

Luan Herrera Follow

Originally disclosed on Mozilla

  • Fixed in 35 days
  • Paid in 53 days
  • Disclosed after 35 days
Text
Created attachment 9250556
index.html

It is possible to import external resources from within a Web Worker using the "importScripts" function, and by checking the error message, confirm whether the content-type is application/javascript or not.

The error message that is shown when a script failed to load due to having an incorrect content-type ("NetworkError: WorkerGlobalScope.importScripts: Failed to load worker script at https://victim.com/xyz.js (nsresult = 0x804b001d)") should be the same as when the script failed to load when having a correct content-type, but invalid syntax ("NetworkError: A network error occurred").

This vulnerability is useful for XS-Search attacks. A real-world example is https://medium.com/@luanherrera/xs-searching-googles-bug-tracker-to-find-out-vulnerable-source-code-50d8135b7549 (more on https://github.com/xsleaks/xsleaks/wiki/Real-World-Examples).

VERSION
Version: 94.0.1 (64-bit)
Operating System: Windows 10

REPRODUCTION CASE
1. Access https://lbherrera.github.io/lab/firefox/detect-js-53ffdde341/index.html
2. Click on the "check" button and a message confirming that the content-type of the resource is "application/javascript" will be displayed.
3. Change the URL to a resource that doesn't contain the "application/javascript" content-type set and click on the "check" button.

I have also attached the file used in the PoC - if you prefer, you can reproduce the attack by downloading and hosting index.html on a web server.

CREDIT INFORMATION
Reporter credit: Luan Herrera (@lbherrera_)

The original report as published on Mozilla's Bugzilla, by Luan Herrera. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the browser returns distinguishable error messages for a content-type mismatch versus a syntax error when importScripts fails, leaking whether the resource is served as application/javascript.

Impact

This could enable XS-Search attacks that infer whether cross-origin resources are JavaScript, as demonstrated in a real-world example against Google's bug tracker.

What the attacker needed

Victim visits attacker-controlled page; attacker can run JavaScript in a Web Worker; target resource is cross-origin

The fix

The error messages for a content-type mismatch and a syntax error should be made identical.

How it was found

  1. Access the provided test page.
  2. Click the check button to see a message confirming the resource's content-type is application/javascript.
  3. Change the URL to a resource without the application/javascript content-type and click check again.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a web page loads a script from another site, the browser checks if the file is marked as JavaScript. This report shows that a background worker can be tricked into revealing whether that check passed or failed by looking at the error message. That small difference lets an attacker guess things about other websites' files.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

More by Luan Herrera

View all

11 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.