three.js icon indicating copy to clipboard operation
three.js copied to clipboard

SW: Add secure headers and clean up

Open LeviPesin opened this issue 3 years ago • 13 comments

Fixes https://github.com/mrdoob/three.js/issues/24212

Description

Add the required secure headers to the editor's service worker and clean up it.

@mattrossman Please confirm this works.

LeviPesin avatar Jun 09 '22 10:06 LeviPesin

I'm testing it here: https://rawcdn.githack.com/LeviPesin/three.js-1/a0f8cbd345e98f3e9ecf3fc1bf922add84d98905/editor/index.html

It isn't working for me.

The FetchEvent for "https://rawcdn.githack.com/LeviPesin/three.js-1/a0f8cbd345e98f3e9ecf3fc1bf922add84d98905/editor/index.html" resulted in a network error response: a Response whose "body" is locked cannot be used to respond to a request.

The trace points to this line:

https://github.com/LeviPesin/three.js-1/blob/a0f8cbd345e98f3e9ecf3fc1bf922add84d98905/editor/sw.js#L257

Perhaps there is some additional code from coi-serviceworker that should be copied over.

mattrossman avatar Jun 09 '22 12:06 mattrossman

Should be fixed now.

LeviPesin avatar Jun 09 '22 13:06 LeviPesin

Not seeing it on my end: https://rawcdn.githack.com/LeviPesin/three.js-1/9d87837f28a96116bea898506350269f2bf59a8c/editor/index.html

image

mattrossman avatar Jun 09 '22 13:06 mattrossman

It seems that unpkg does not provide CORP header, so we cannot use COEP: require-corp and should use the new COEP: credentialless.

LeviPesin avatar Jun 09 '22 14:06 LeviPesin

But it still does not work... I am unsure why.

LeviPesin avatar Jun 09 '22 14:06 LeviPesin

In my case https://github.com/mattrossman/three.js/commit/bc818a752ae2e3ad13adceaa142608c7c9f56de0 I had to copy the two libs (ffmpeg.wasm and es-module-shims) from unpkg locally. Working demo.

mattrossman avatar Jun 09 '22 15:06 mattrossman

I think @mrdoob should decide should we keep these libs locally, investigate ways to enable the SW to work with cross-origin requests, or just use a non-SharedArrayBuffer version.

LeviPesin avatar Jun 09 '22 15:06 LeviPesin

Is the non-SharedArrayBuffer version 10x slower or something? 🤔

mrdoob avatar Jun 10 '22 01:06 mrdoob

I think it is exactly number-of-coresX slower, because SharedArrayBuffer allows multithreading. I think we can actually keep the libs like we do with the other libs?

LeviPesin avatar Jun 10 '22 08:06 LeviPesin

Alright, lets host the libraries then 👍

mrdoob avatar Jun 13 '22 07:06 mrdoob

Done.

LeviPesin avatar Jun 16 '22 10:06 LeviPesin

Is there something preventing merging this PR?

LeviPesin avatar Jul 26 '22 10:07 LeviPesin

@mrdoob Can this PR be merged, please?

LeviPesin avatar Sep 01 '22 07:09 LeviPesin

@mrdoob @Mugen87 Something preventing the merge?

LeviPesin avatar Sep 27 '22 09:09 LeviPesin

Sorry for the delay!

mrdoob avatar Sep 29 '22 02:09 mrdoob

Thanks!

mrdoob avatar Sep 29 '22 02:09 mrdoob