Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upcoming issues with SharedArrayBuffer #22

Open
Jaifroid opened this issue Dec 5, 2022 · 6 comments
Open

Upcoming issues with SharedArrayBuffer #22

Jaifroid opened this issue Dec 5, 2022 · 6 comments
Labels
build Code relating to building or publishing assets

Comments

@Jaifroid
Copy link
Collaborator

Jaifroid commented Dec 5, 2022

It is worth noting that Chrome will disable SharedArrayBuffer by default from Chrome 113 unless a site is cross origin isolated, which means that it serves these headers:

Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin

See https://developer.chrome.com/blog/enabling-shared-array-buffer/

It is relevant for this Repo, as the type of File Reader that we enable when compiling the WASM uses SharedArrayBuffer to pass a multi-gigabyte File to the WASM Worker without copying or loading in memory. This is why the WASM doesn't work on Chrome Mobile, where there is no support for SharedArrayBuffer except behind a flag, and it seems no support at all for it with POSIX threading enabled in source binaries.

For the PWA versions, we should be able to serve those headers. Other versions that don't use https: may struggle. We may need to look into alternative file systems for the WASM.

@Jaifroid Jaifroid added the build Code relating to building or publishing assets label Dec 5, 2022
@Jaifroid
Copy link
Collaborator Author

Jaifroid commented Dec 6, 2022

So, I tried adding these security headers to Kiwix JS PWA docker instance:

add_header Cross-Origin-Embedder-Policy require-corp;
add_header Cross-Origin-Opener-Policy same-origin;

Unfortunately, the effect is to block any programmatic access to the iframe. Need to investigate if there is a way to loosen this. I find it very strange that an iframe that is clearly serving content from the same origin should be blocked by these headers. It isn't serving (and cannot serve) content from other locations.

@Jaifroid
Copy link
Collaborator Author

Jaifroid commented Dec 6, 2022

Further info here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy. Note this text:

You can only access certain features like SharedArrayBuffer objects or Performance.now() with unthrottled timers, if your document has a COEP header with the value require-corp value set.

Suggested solution is to add crossorigin to any resources that need to be loaded, like <img src="https://thirdparty.com/img.png" crossorigin />. I can try adding this to the iframe document, I guess, but it would be impractical to add it to every resource requested from a ZIM. My initial puzzlement still stands: these resources are not cross origin...

@Jaifroid
Copy link
Collaborator Author

Jaifroid commented Dec 6, 2022

See also this convoluted solution: https://stackoverflow.com/a/71817085.

@Jaifroid
Copy link
Collaborator Author

Jaifroid commented Dec 6, 2022

@Jaifroid
Copy link
Collaborator Author

Jaifroid commented Feb 6, 2023

On reflection, it's not clear to me whether sharedArrayBuffer is the real issue here, or in fact the lack of support for Atomics in some browsers.

@stale
Copy link

stale bot commented May 26, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be now be reviewed manually. Thank you for your contributions.

@stale stale bot added the stale label May 26, 2023
@Jaifroid Jaifroid removed the stale label Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Code relating to building or publishing assets
Projects
None yet
Development

No branches or pull requests

1 participant