-
Notifications
You must be signed in to change notification settings - Fork 1
feat(container): gate WebRTC on a decision resolved before the product realm #444
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b5b1119
feat(container): gate WebRTC on a decision resolved before the produc…
filvecchiato 116e553
feat(ios): own product script registration so the container reaches e…
filvecchiato 2722efc
fix(container): report a lock that does not take instead of failing q…
filvecchiato 8e77adb
Merge branch 'main' into feat/gate-webrtc-egress
filvecchiato 4e15463
Merge branch 'main' into feat/gate-webrtc-egress
filvecchiato 6b6f9d1
Merge branch 'main' into feat/gate-webrtc-egress
filvecchiato 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,57 @@ | ||
| // User-script installation for a product web view. | ||
| // | ||
| // The lockdown container's guarantees depend on two things a host would | ||
| // otherwise have to get right by hand, so the package owns both. | ||
|
|
||
| #if canImport(WebKit) | ||
|
|
||
| import WebKit | ||
|
|
||
| public extension TrUAPIHost { | ||
| /// Registers the bootstrap and lockdown container on `controller` with the | ||
| /// frame scopes the lockdown depends on, resolving the container's policy | ||
| /// from `core`. | ||
| /// | ||
| /// Prefer this over registering the scripts by hand. Two properties are | ||
| /// easy to get wrong and silently fatal: | ||
| /// | ||
| /// - **The container must run in every frame.** A frame without it has | ||
| /// pristine `fetch`, `WebSocket`, `XMLHttpRequest` and | ||
| /// `RTCPeerConnection`, and a product reaches one through an `<iframe>` in | ||
| /// its own HTML — parsed before any script runs — so intercepting DOM | ||
| /// creation APIs is no substitute. The bootstrap stays main-frame-only: | ||
| /// a subframe then has no bridge endpoint and no policy, and every gate in | ||
| /// the container fails closed there. | ||
| /// - **The WebRTC decision is a peek, never a prompt**, and it is baked in | ||
| /// as a literal because the container enforces it inside the product's own | ||
| /// realm, where an asynchronous permission request would be forgeable. A | ||
| /// fresh grant therefore only applies once the web view reloads. | ||
| /// | ||
| /// Call before the web view loads the product page. | ||
| static func installProductScripts( | ||
| into controller: WKUserContentController, | ||
| core: any TrUAPIHostCoreProtocol, | ||
| endpoint: WsBridgeEndpoint | ||
| ) throws { | ||
| let webRtcAllowed = try core.permissionAuthorizationStatus( | ||
| request: .remote(RemotePermissionRequest(permission: .webRtc)) | ||
| ) == .authorized | ||
|
|
||
| controller.addUserScript(WKUserScript( | ||
| source: LocalhostBridgeBootstrap.script( | ||
| port: endpoint.port, | ||
| token: endpoint.token, | ||
| webRtcAllowed: webRtcAllowed | ||
| ), | ||
| injectionTime: .atDocumentStart, | ||
| forMainFrameOnly: true | ||
| )) | ||
| controller.addUserScript(WKUserScript( | ||
| source: try ContainerScriptBundle.load(), | ||
| injectionTime: .atDocumentStart, | ||
| forMainFrameOnly: false | ||
| )) | ||
| } | ||
| } | ||
|
|
||
| #endif |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.