-
Notifications
You must be signed in to change notification settings - Fork 1
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
RFC: Sandbox for WebApps #1
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
--- | ||
Status: Draft | ||
Authors: | ||
- Hyeseong Kim <tim@daangn.com> | ||
Start Date: 2023-01-05 | ||
RFC PR: | ||
Related Issues: (leave this empty) | ||
--- | ||
|
||
# Sandbox Environment for Web Applications | ||
|
||
## Summary | ||
|
||
Brane Project provides sandbox environment for client-side Web applications, built on top of | ||
|
||
1. Cross-origin iframe | ||
2. A DOM implementation for [Web Workers] | ||
3. An unified abstraction for scheduling and fine-grained access control | ||
|
||
## Motivation | ||
|
||
TBD | ||
|
||
## Detailed design | ||
|
||
Brane Project uses both cross-origin iframe and [Web Workers] to make a sandbox environment. | ||
|
||
Even Web Worker alone can isolate the JavaScript context, but it's not a complete sandbox. This is because the worker still has access to IndexedDB, cookie storage, etc from the same origin. To provide a separate origin for the application, a separate subdomain is used and an iframe is used to access it. | ||
|
||
But Brane doesn't use the iframe's DOM directly because it can slow down the main thread (even if it runs in a separate process due to [`crossOriginIsolated`](https://developer.mozilla.org/en-US/docs/Web/API/crossOriginIsolated), it turns out that communication with the iframe's worker thread is more efficient than communication with the iframe's main thread as a result of the [benchmark](https://github.com/braneproject/cross-origin-isolated-playground/blob/main/cross-origin-worker)), and also the `sandbox` property frame's origin to `null` so disables browser features that require origin policy. | ||
|
||
So the guest application is isolated as a worker launched in the cross-origin iframe. | ||
|
||
To run UI applications in Web Workers, a DOM implementation must be provided instead of the browser. And a transfer layer is also necessary to synchronize the interactions with the actual display. Although there are several JavaScript DOM implementations available, they aren't being used, and a custom implementation needs to be developed to work with the transfer layer properly. | ||
|
||
The cross-origin iframe runs in `crossOriginIsolated` mode to handle scheduling for DOM requests from the worker. The [`Atomics`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics) API makes it able to implement interfaces that require to be blocking & synchronous. | ||
|
||
All of this is should be able to be controlled via shims injected by the provider and policy code exist on the host. | ||
|
||
### Implementation | ||
|
||
[Working in progress](https://github.com/braneproject/web-sandbox/tree/initial-impl) | ||
|
||
## Drawbacks | ||
|
||
TBD | ||
|
||
## Other Approaches | ||
|
||
### Isolate JS by embeded JS intepreter | ||
|
||
TBD | ||
|
||
### Isolate JS by ShadowRealm API | ||
|
||
TBD | ||
|
||
## Security Consideration | ||
|
||
TBD | ||
|
||
## Privacy Consideration | ||
|
||
TBD | ||
|
||
## Related Works | ||
|
||
- **[TreeHouse](https://www.usenix.org/conference/atc12/technical-sessions/presentation/ingram)** by Lon Ingram and Michael Walfish\ | ||
TreeHouse is a research that has very similar concepts and goals. However, it was from 2012 and had limitations due to browser technology at the time. | ||
- **[WorkerDOM](https://github.com/ampproject/worker-dom)** by AMP Porject\ | ||
WorkerDOM is the backend for `<amp-script>` tag hosting third-party content in AMP pages. It actually can run many of SPAs today, but it didn't solve the blocking vs event-driven mismatch problem mentioned in early research like TreeHouse. | ||
- **[Partytown](https://partytown.builder.io/)** by Builder.io\ | ||
Partytown is a library that automatically relocate third-party scripts into a worker. It proves the concept of [sandboxing](https://partytown.builder.io/sandboxing) by implementing blocking communication using `Proxy` and `Atomics`, but [itself is not suitable for MiniApps usecase](https://partytown.builder.io/trade-offs#ui-intensive-third-party-scripts). | ||
|
||
## Unresolved Questions | ||
|
||
Optional, but suggested for first drafts. What parts of the design are still TBD? | ||
|
||
[Web Workers]: https://html.spec.whatwg.org/multipage/#workers | ||
[ShadowRealm]: https://tc39.es/proposal-shadowrealm/ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each of those should be break down into separated RFCs