Skip to content

Add MIME type checking for HTTP(S) worker scripts#5302

Merged
domenic merged 1 commit intomasterfrom
nosniff-worker-scripts
Aug 12, 2020
Merged

Add MIME type checking for HTTP(S) worker scripts#5302
domenic merged 1 commit intomasterfrom
nosniff-worker-scripts

Conversation

@evilpie
Copy link
Member

evilpie commented Feb 18, 2020

@domenic
Copy link
Member Author

domenic commented Feb 18, 2020

Thanks! I'd be interested in also getting tests for blob/data (maybe not filesystem), since it sounds like at least at one point in time those were treated differently...

@evilpie
Copy link
Member

evilpie commented Feb 18, 2020

Thanks! I'd be interested in also getting tests for blob/data (maybe not filesystem), since it sounds like at least at one point in time those were treated differently...

Yes, right. We only enforce the MIME type for HTTP loads at the moment. This is the case we most care about anyway. One exception is module loads where we enforce the right MIME type also at the script loader level, so it also applies to data: and blob:. I think we are not generally opposed to also fixing those, but it's not a priority.

@evilpie
Copy link
Member

evilpie commented Mar 25, 2020

We have delayed shipping this change in light of the current events.

@evilpie
Copy link
Member

evilpie commented Jul 30, 2020

We now intent to ship this in Firefox 81.

@domenic
Copy link
Member Author

domenic commented Jul 30, 2020

Great! Is the plan still to not enforce this for data: and blob:? Also, let me know on the plan for test updates...

@evilpie
Copy link
Member

evilpie commented Jul 31, 2020

I think for data: and blob: we would first have to add warnings and telemetry. It's quite easy to produce blob URLs without a type: new Worker(URL.createObjectURL(new Blob(["1 + 1"])))

For tests is there anything we could just copy or extend? I think when I first did this a year ago I fixed all WPT tests that were unintentionally using the wrong mime type for workers.

@domenic
Copy link
Member Author

domenic commented Jul 31, 2020

Alright, I'll rebase this and add carve-outs for data: and blob: URLs, although doing so makes me sad.

Fixing existing tests sounds great. Just send me a link to the web-platform-tests/wpt pull request, or Firefox change that will eventually get synced there, so we can link the changes there to this PR.

@evilpie
Copy link
Member

evilpie commented Jul 31, 2020

So for reference purposes:

@domenic
Copy link
Member Author

domenic commented Jul 31, 2020

Working on precise spec text... what's the plan for about: and file: URLs? I'm trying to figure out if we should check HTTP(S) URLs explicitly, or if we should avoid checking data: and blob: URLs specifically.

@domenic domenic force-pushed the nosniff-worker-scripts branch from 5307855 to 5c15a90 Compare July 31, 2020 18:26
@domenic domenic changed the title Enforce JS MIME type checking for worker scripts Add MIME type checking for non-blob:/data: worker scripts Jul 31, 2020
@domenic domenic changed the base branch from master to editorial-tweaks-script-fetching July 31, 2020 18:31
@domenic domenic added the do not merge yet Pull request must not be merged per rationale in comment label Jul 31, 2020
@domenic
Copy link
Member Author

domenic commented Jul 31, 2020

Alright, I've got the pull request all straightened out, assuming that we're specifically exempting blob: and data: URLs.

For tests, we'll want a pull request/Firefox-side change for the https://github.com/web-platform-tests/wpt/blob/master/workers/Worker_script_mimetype.htm test you mentioned. It'd also be ideal to add specific tests (e.g. by expanding that test file) for:

  • blob: URLs with the wrong MIME type, or with no MIME type, still work
  • data: URLs with the wrong MIME type, or with no MIME type (which per the Fetch spec ends up as a MIME type of text/plain;charset=US-ASCII), still work.
  • about:blank does not work.

file: URLs don't seem very testable on web platform tests infrastructure.

@evilpie
Copy link
Member

evilpie commented Jul 31, 2020

Right now the Firefox implementation is restricted to blocking bad scripts coming from http or https specifically. If we start blocking data: and blob: I am pretty sure we would just do it for every other protocol as well.

@domenic
Copy link
Member Author

domenic commented Jul 31, 2020

OK cool, I'll switch around the PR. In that case we should have tests to check that about:blank still works.

@domenic domenic force-pushed the nosniff-worker-scripts branch from 5c15a90 to 6a5c732 Compare July 31, 2020 19:02
@domenic domenic changed the title Add MIME type checking for non-blob:/data: worker scripts Add MIME type checking for HTTP(S) worker scripts Jul 31, 2020
Base automatically changed from editorial-tweaks-script-fetching to master August 5, 2020 15:43
@domenic domenic removed the do not merge yet Pull request must not be merged per rationale in comment label Aug 5, 2020
@domenic domenic force-pushed the nosniff-worker-scripts branch from 6a5c732 to 1a90195 Compare August 5, 2020 15:52
@domenic domenic requested a review from annevk August 5, 2020 15:53
Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @evilpie for driving this and @domenic for taking care of the PR!

(Still not a fan of this style of inline lists, but yolo.)

@domenic
Copy link
Member Author

domenic commented Aug 6, 2020

I'll wait on merging until we have some test updates ready to go.

@domenic domenic added the needs tests Moving the issue forward requires someone to write tests label Aug 6, 2020
@domenic
Copy link
Member Author

domenic commented Aug 12, 2020

I'm updating the tests now; I'll update the OP with a link to the test pull request, and then merge.

It turns out that about:blank is cross-origin so that isn't an issue.

domenic added a commit to web-platform-tests/wpt that referenced this pull request Aug 12, 2020
@domenic domenic removed the needs tests Moving the issue forward requires someone to write tests label Aug 12, 2020
@domenic domenic merged commit 97c73c3 into master Aug 12, 2020
@domenic domenic deleted the nosniff-worker-scripts branch August 12, 2020 21:56
domenic added a commit to web-platform-tests/wpt that referenced this pull request Aug 17, 2020
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Aug 25, 2020
…ing tests, a=testonly

Automatic update from web-platform-tests
Update and expand worker MIME type checking tests

Follows whatwg/html#5302.

--

wpt-commits: 031409f5be576b09f592f114e50c241db96820c5
wpt-pr: 24983
ambroff pushed a commit to ambroff/gecko that referenced this pull request Nov 4, 2020
…ing tests, a=testonly

Automatic update from web-platform-tests
Update and expand worker MIME type checking tests

Follows whatwg/html#5302.

--

wpt-commits: 031409f5be576b09f592f114e50c241db96820c5
wpt-pr: 24983
bhearsum pushed a commit to mozilla-releng/staging-firefox that referenced this pull request May 1, 2025
…ing tests, a=testonly

Automatic update from web-platform-tests
Update and expand worker MIME type checking tests

Follows whatwg/html#5302.

--

wpt-commits: 031409f5be576b09f592f114e50c241db96820c5
wpt-pr: 24983
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants