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

fix: Disable Initialization Script Injection into Subframes on MacOS #1269

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/disable-script-inject-subframe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wry": patch
---

On macOS, disable initialization script injection into subframes.
1 change: 1 addition & 0 deletions src/webkitgtk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ impl InnerWebView {
if let Some(manager) = self.webview.user_content_manager() {
let script = UserScript::new(
js,
// TODO: feature to allow injecting into subframes
UserContentInjectedFrames::TopFrame,
UserScriptInjectionTime::Start,
&[],
Expand Down
1 change: 1 addition & 0 deletions src/webview2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,7 @@ impl InnerWebView {
);
}

// TODO: feature to allow injecting into (specific) subframes
#[inline]
fn add_script_to_execute_on_document_created(webview: &ICoreWebView2, js: String) -> Result<()> {
let webview = webview.clone();
Expand Down
6 changes: 2 additions & 4 deletions src/wkwebview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,10 +1085,8 @@ r#"Object.defineProperty(window, 'ipc', {
unsafe {
let userscript: id = msg_send![class!(WKUserScript), alloc];
let script: id =
// FIXME: We allow subframe injection because webview2 does and cannot be disabled (currently).
// once webview2 allows disabling all-frame script injection, forMainFrameOnly should be enabled
// if it does not break anything. (originally added for isolation pattern).
msg_send![userscript, initWithSource:NSString::new(js) injectionTime:0 forMainFrameOnly:0];
// TODO: feature to allow injecting into subframes
msg_send![userscript, initWithSource:NSString::new(js) injectionTime:0 forMainFrameOnly:1];
let _: () = msg_send![self.manager, addUserScript: script];
}
}
Expand Down
Loading