Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

fix(renderer): unify javascript URL document ownership

ldm0b23c9bd0a9c2
diff --git a/moli-renderer-v8/src/context_bootstrap/window_runtime/dialogs.rs b/moli-renderer-v8/src/context_bootstrap/window_runtime/dialogs.rs
index 507300f34..7d852c800 100644
--- a/moli-renderer-v8/src/context_bootstrap/window_runtime/dialogs.rs
+++ b/moli-renderer-v8/src/context_bootstrap/window_runtime/dialogs.rs
@@ -173,7 +173,7 @@ pub(crate) fn window_open_callback<'s>(
window_open_entered_document_url(scope, host).to_string()
};
if url.scheme() == "javascript" {
- let source = crate::native_bridge::javascript_url_csp_source(&url);
+ let source = crate::javascript_url::csp_source(&url);
let host = unsafe { &mut *host_ptr };
let owner = host.entered_owner_dispatch_scope(scope);
if !host.allows_inline_javascript_navigation_by_csp(scope, owner, &source) {
diff --git a/moli-renderer-v8/src/document_runtime/security_policy.rs b/moli-renderer-v8/src/document_runtime/security_policy.rs
index a25b2702d..b7a27379b 100644
--- a/moli-renderer-v8/src/document_runtime/security_policy.rs
+++ b/moli-renderer-v8/src/document_runtime/security_policy.rs
@@ -1011,6 +1011,43 @@ impl DocumentRuntime {
}
}
+ pub(crate) fn non_url_csp_check_for_document(
+ &self,
+ document_handle: Option<DomHandle>,
+ document_url: &Url,
+ response_policies: &[String],
+ response_report_only_policies: &[String],
+ response_reporting_endpoints: &ContentSecurityPolicyReportingEndpoints,
+ kind: ContentSecurityPolicyNonUrlKind,
+ ) -> DocumentContentSecurityPolicyCheck {
+ let enforced_policies = self
+ .document_content_security_policy_strings_for_optional_document(
+ document_handle,
+ response_policies,
+ response_reporting_endpoints,
+ );
+ let enforced_violation = document_non_url_policy_violation_from_document_policies(
+ enforced_policies,
+ document_url,
+ kind,
+ ContentSecurityPolicyDisposition::Enforce,
+ );
+ let report_only_policies = document_response_content_security_policy_strings(
+ response_report_only_policies,
+ response_reporting_endpoints,
+ );
+ let report_only_violation = document_non_url_policy_violation_from_document_policies(
+ report_only_policies,
+ document_url,
+ kind,
+ ContentSecurityPolicyDisposition::Report,
+ );
+ DocumentContentSecurityPolicyCheck {
+ report_only_violation,
+ enforced_violation,
+ }
+ }
+
#[cfg(test)]
pub(crate) fn document_frame_csp_violation(
&self,
@@ -1031,7 +1068,7 @@ impl DocumentRuntime {
)
}
- pub(crate) fn script_element_request_csp_violation_for_child_document(
+ pub(crate) fn script_element_request_csp_violation_for_document(
&self,
document_handle: Option<DomHandle>,
document_url: &Url,
@@ -1039,7 +1076,7 @@ impl DocumentRuntime {
response_reporting_endpoints: &ContentSecurityPolicyReportingEndpoints,
request_url: &Url,
) -> Option<DocumentContentSecurityPolicyViolation> {
- self.script_element_request_csp_violation_for_child_document_with_redirect_status(
+ self.script_element_request_csp_violation_for_document_with_redirect_status(
document_handle,
document_url,
response_policies,
@@ -1050,7 +1087,7 @@ impl DocumentRuntime {
)
}
- pub(crate) fn script_element_request_csp_violation_for_child_document_with_redirect_status(
+ pub(crate) fn script_element_request_csp_violation_for_document_with_redirect_status(
&self,
document_handle: Option<DomHandle>,
document_url: &Url,
@@ -1075,14 +1112,14 @@ impl DocumentRuntime {
)
}
- pub(crate) fn script_element_request_csp_report_only_violation_for_child_document(
+ pub(crate) fn script_element_request_csp_report_only_violation_for_document(
&self,
document_url: &Url,
response_report_only_policies: &[String],
response_reporting_endpoints: &ContentSecurityPolicyReportingEndpoints,
request_url: &Url,
) -> Option<DocumentContentSecurityPolicyViolation> {
- self.script_element_request_csp_report_only_violation_for_child_document_with_redirect_status(
+ self.script_element_request_csp_report_only_violation_for_document_with_redirect_status(
document_url,
response_report_only_policies,
response_reporting_endpoints,
@@ -1092,7 +1129,7 @@ impl DocumentRuntime {
)
}
- pub(crate) fn script_element_request_csp_report_only_violation_for_child_document_with_redirect_status(
+ pub(crate) fn script_element_request_csp_report_only_violation_for_document_with_redirect_status(
&self,
document_url: &Url,
response_report_only_policies: &[String],
@@ -1113,7 +1150,7 @@ impl DocumentRuntime {
}
#[allow(clippy::too_many_arguments)]
- pub(crate) fn document_connect_csp_check_for_child_document_with_redirect_status(
+ pub(crate) fn document_connect_csp_check_for_document_with_redirect_status(
&self,
document_handle: Option<DomHandle>,
document_url: &Url,
@@ -1188,7 +1225,7 @@ impl DocumentRuntime {
)
}
- pub(crate) fn inline_script_csp_violation_for_child_document(
+ pub(crate) fn inline_script_csp_violation_for_document(
&self,
document_handle: Option<DomHandle>,
document_url: &Url,
@@ -1208,7 +1245,7 @@ impl DocumentRuntime {
)
}
- pub(crate) fn inline_script_csp_report_only_violation_for_child_document(
+ pub(crate) fn inline_script_csp_report_only_violation_for_document(
&self,
document_url: &Url,
response_report_only_policies: &[String],
@@ -1226,6 +1263,7 @@ impl DocumentRuntime {
)
}
+ #[cfg(test)]
pub(crate) fn wasm_eval_csp_violation(&self) -> Option<DocumentContentSecurityPolicyViolation> {
self.non_url_csp_violation(
ContentSecurityPolicyNonUrlKind::WasmEval,
@@ -1233,26 +1271,7 @@ impl DocumentRuntime {
)
}
- pub(crate) fn eval_csp_violation(
- &self,
- allow_trusted_types_eval: bool,
- ) -> Option<DocumentContentSecurityPolicyViolation> {
- self.non_url_csp_violation(
- eval_csp_kind(allow_trusted_types_eval),
- ContentSecurityPolicyDisposition::Enforce,
- )
- }
-
- pub(crate) fn eval_csp_report_only_violation(
- &self,
- allow_trusted_types_eval: bool,
- ) -> Option<DocumentContentSecurityPolicyViolation> {
- self.non_url_csp_report_only_violation(
- eval_csp_kind(allow_trusted_types_eval),
- ContentSecurityPolicyDisposition::Report,
- )
- }
-
+ #[cfg(test)]
fn non_url_csp_violation(
&self,
kind: ContentSecurityPolicyNonUrlKind,
@@ -1272,6 +1291,7 @@ impl DocumentRuntime {
)
}
+ #[cfg(test)]
fn non_url_csp_report_only_violation(
&self,
kind: ContentSecurityPolicyNonUrlKind,
@@ -1292,6 +1312,7 @@ impl DocumentRuntime {
)
}
+ #[cfg(test)]
pub(crate) fn wasm_eval_csp_report_only_violation(
&self,
) -> Option<DocumentContentSecurityPolicyViolation> {
@@ -1301,26 +1322,7 @@ impl DocumentRuntime {
)
}
- pub(crate) fn trusted_types_sink_csp_violation(
- &self,
- sink: &str,
- sample: &str,
- ) -> Option<DocumentContentSecurityPolicyViolation> {
- let document_url = self.document_url();
- let policies = self.document_content_security_policy_strings_for_optional_document(
- Some(self.document_handle()),
- &self.policy_container.response_content_security_policies,
- &self.policy_container.content_security_reporting_endpoints,
- );
- document_trusted_types_sink_policy_violation_from_document_policies(
- policies,
- document_url,
- sink,
- sample,
- ContentSecurityPolicyDisposition::Enforce,
- )
- }
-
+ #[cfg(test)]
pub(crate) fn trusted_types_sink_csp_report_only_violation(
&self,
sink: &str,
@@ -1342,6 +1344,7 @@ impl DocumentRuntime {
)
}
+ #[cfg(test)]
pub(crate) fn trusted_types_for_script_requirements(
&self,
) -> TrustedTypesForScriptRequirements {
@@ -1428,103 +1431,7 @@ impl DocumentRuntime {
document_policies_require_trusted_types_for_script(&policies)
}
- pub(crate) fn allows_trusted_types_eval(&self) -> bool {
- let policies = self.document_content_security_policy_strings_for_optional_document(
- Some(self.document_handle()),
- &self.policy_container.response_content_security_policies,
- &self.policy_container.content_security_reporting_endpoints,
- );
- document_policies_allow_trusted_types_eval(&policies)
- }
-
- pub(crate) fn allows_trusted_type_policy_name(&self, policy_name: &str) -> bool {
- let policies = self.document_content_security_policy_strings_for_optional_document(
- Some(self.document_handle()),
- &self.policy_container.response_content_security_policies,
- &self.policy_container.content_security_reporting_endpoints,
- );
- document_policies_allow_trusted_type_policy_name(policies, policy_name)
- }
-
- pub(crate) fn wasm_eval_csp_violation_for_child_document(
- &self,
- document_handle: Option<DomHandle>,
- document_url: &Url,
- response_policies: &[String],
- response_reporting_endpoints: &ContentSecurityPolicyReportingEndpoints,
- ) -> Option<DocumentContentSecurityPolicyViolation> {
- let policies = self.document_content_security_policy_strings_for_optional_document(
- document_handle,
- response_policies,
- response_reporting_endpoints,
- );
- document_non_url_policy_violation_from_document_policies(
- policies,
- document_url,
- ContentSecurityPolicyNonUrlKind::WasmEval,
- ContentSecurityPolicyDisposition::Enforce,
- )
- }
-
- pub(crate) fn eval_csp_violation_for_child_document(
- &self,
- document_handle: Option<DomHandle>,
- document_url: &Url,
- response_policies: &[String],
- response_reporting_endpoints: &ContentSecurityPolicyReportingEndpoints,
- allow_trusted_types_eval: bool,
- ) -> Option<DocumentContentSecurityPolicyViolation> {
- let policies = self.document_content_security_policy_strings_for_optional_document(
- document_handle,
- response_policies,
- response_reporting_endpoints,
- );
- document_non_url_policy_violation_from_document_policies(
- policies,
- document_url,
- eval_csp_kind(allow_trusted_types_eval),
- ContentSecurityPolicyDisposition::Enforce,
- )
- }
-
- pub(crate) fn trusted_types_sink_csp_violation_for_child_document(
- &self,
- document_handle: Option<DomHandle>,
- document_url: &Url,
- response_policies: &[String],
- response_reporting_endpoints: &ContentSecurityPolicyReportingEndpoints,
- sink: &str,
- sample: &str,
- ) -> Option<DocumentContentSecurityPolicyViolation> {
- let policies = self.document_content_security_policy_strings_for_optional_document(
- document_handle,
- response_policies,
- response_reporting_endpoints,
- );
- document_trusted_types_sink_policy_violation_from_document_policies(
- policies,
- document_url,
- sink,
- sample,
- ContentSecurityPolicyDisposition::Enforce,
- )
- }
-
- pub(crate) fn requires_trusted_types_for_script_for_child_document(
- &self,
- document_handle: Option<DomHandle>,
- response_policies: &[String],
- response_reporting_endpoints: &ContentSecurityPolicyReportingEndpoints,
- ) -> bool {
- let policies = self.document_content_security_policy_strings_for_optional_document(
- document_handle,
- response_policies,
- response_reporting_endpoints,
- );
- document_policies_require_trusted_types_for_script(&policies)
- }
-
- pub(crate) fn allows_trusted_types_eval_for_child_document(
+ pub(crate) fn allows_trusted_types_eval_for_document(
&self,
document_handle: Option<DomHandle>,
response_policies: &[String],
@@ -1538,7 +1445,7 @@ impl DocumentRuntime {
document_policies_allow_trusted_types_eval(&policies)
}
- pub(crate) fn allows_trusted_type_policy_name_for_child_document(
+ pub(crate) fn allows_trusted_type_policy_name_for_document(
&self,
document_handle: Option<DomHandle>,
response_policies: &[String],
@@ -1553,43 +1460,6 @@ impl DocumentRuntime {
document_policies_allow_trusted_type_policy_name(policies, policy_name)
}
- pub(crate) fn wasm_eval_csp_report_only_violation_for_child_document(
- &self,
- document_url: &Url,
- response_report_only_policies: &[String],
- response_reporting_endpoints: &ContentSecurityPolicyReportingEndpoints,
- ) -> Option<DocumentContentSecurityPolicyViolation> {
- let policies = document_response_content_security_policy_strings(
- response_report_only_policies,
- response_reporting_endpoints,
- );
- document_non_url_policy_violation_from_document_policies(
- policies,
- document_url,
- ContentSecurityPolicyNonUrlKind::WasmEval,
- ContentSecurityPolicyDisposition::Report,
- )
- }
-
- pub(crate) fn eval_csp_report_only_violation_for_child_document(
- &self,
- document_url: &Url,
- response_report_only_policies: &[String],
- response_reporting_endpoints: &ContentSecurityPolicyReportingEndpoints,
- allow_trusted_types_eval: bool,
- ) -> Option<DocumentContentSecurityPolicyViolation> {
- let policies = document_response_content_security_policy_strings(
- response_report_only_policies,
- response_reporting_endpoints,
- );
- document_non_url_policy_violation_from_document_policies(
- policies,
- document_url,
- eval_csp_kind(allow_trusted_types_eval),
- ContentSecurityPolicyDisposition::Report,
- )
- }
-
pub(crate) fn queue_content_security_policy_violation_event_best_effort<'s>(
&mut self,
scope: &mut v8::PinScope<'s, '_>,
@@ -2147,6 +2017,7 @@ fn document_inline_style_element_policy_violation_from_document_policies(
})
}
+#[cfg(test)]
fn document_trusted_types_sink_policy_violation_from_document_policies(
policies: Vec<DocumentContentSecurityPolicyString>,
document_url: &Url,
@@ -2206,14 +2077,6 @@ fn document_policies_require_trusted_types_for_script(
})
}
-fn eval_csp_kind(allow_trusted_types_eval: bool) -> ContentSecurityPolicyNonUrlKind {
- if allow_trusted_types_eval {
- ContentSecurityPolicyNonUrlKind::TrustedTypesEval
- } else {
- ContentSecurityPolicyNonUrlKind::Eval
- }
-}
-
fn document_policies_allow_trusted_types_eval(
policies: &[DocumentContentSecurityPolicyString],
) -> bool {
@@ -2506,22 +2369,28 @@ mod tests {
let reporting_endpoints = ContentSecurityPolicyReportingEndpoints::default();
assert!(
- runtime.requires_trusted_types_for_script_for_child_document(
- Some(child_document),
- &[],
- &reporting_endpoints,
- )
+ runtime
+ .trusted_types_for_script_requirements_for_document(
+ Some(child_document),
+ &[],
+ &[],
+ &reporting_endpoints,
+ )
+ .is_enforced()
);
assert!(
!runtime.requires_trusted_types_for_script(),
"a child document's meta policy must not affect the parent document"
);
assert!(
- runtime.requires_trusted_types_for_script_for_child_document(
- Some(child_document),
- &[],
- &reporting_endpoints,
- ),
+ runtime
+ .trusted_types_for_script_requirements_for_document(
+ Some(child_document),
+ &[],
+ &[],
+ &reporting_endpoints,
+ )
+ .is_enforced(),
"checking the parent must not discard the child document's delivered policy"
);
}
@@ -2851,7 +2720,7 @@ mod tests {
runtime.set_content_security_reporting_endpoints(reporting_endpoints());
let inline = runtime
- .inline_script_csp_violation_for_child_document(
+ .inline_script_csp_violation_for_document(
Some(runtime.document_handle()),
runtime.document_url(),
&["script-src 'none'; report-to csp".to_owned()],
@@ -3055,7 +2924,7 @@ mod tests {
let reporting_endpoints = ContentSecurityPolicyReportingEndpoints::default();
let violation = runtime
- .script_element_request_csp_violation_for_child_document(
+ .script_element_request_csp_violation_for_document(
None,
&document_url,
&response_policies,
@@ -3078,7 +2947,7 @@ mod tests {
let reporting_endpoints = ContentSecurityPolicyReportingEndpoints::default();
let violation = runtime
- .inline_script_csp_violation_for_child_document(
+ .inline_script_csp_violation_for_document(
None,
&document_url,
&blocking_policies,
@@ -3090,7 +2959,7 @@ mod tests {
assert_eq!(violation.blocked_uri, "inline");
assert!(
runtime
- .inline_script_csp_violation_for_child_document(
+ .inline_script_csp_violation_for_document(
None,
&document_url,
&allowing_policies,
diff --git a/moli-renderer-v8/src/dom_parser.rs b/moli-renderer-v8/src/dom_parser.rs
index 5aa5247af..892e11c6d 100644
--- a/moli-renderer-v8/src/dom_parser.rs
+++ b/moli-renderer-v8/src/dom_parser.rs
@@ -282,12 +282,12 @@ pub(crate) fn parse_detached_html_document_from_source_with_declarative_shadow_r
build_detached_document_from_dom_host(scope, parsed, DetachedDocumentKind::Html, true)
}
-/// Builds the DOM projection used for a child browsing-context document.
+/// Builds the DOM projection used for a non-top browsing-context document.
///
/// The projection never executes scripts itself. `html_parser` carries the
/// target Document's scripting state solely for parser behavior such as
/// `<noscript>` tokenization; every caller must select that state explicitly.
-pub(crate) fn parse_child_document_projection_from_source<'s>(
+pub(crate) fn parse_browsing_context_document_projection_from_source<'s>(
scope: &mut v8::PinScope<'s, '_>,
document_url: Url,
source: &str,
@@ -295,9 +295,9 @@ pub(crate) fn parse_child_document_projection_from_source<'s>(
character_set: Option<&str>,
html_parser: HtmlParser,
) -> Option<v8::Local<'s, v8::Object>> {
- let source = preserve_decoded_bom_only_child_body(source, content_type);
+ let source = preserve_decoded_bom_only_browsing_context_body(source, content_type);
let (parsed, kind) =
- parse_child_document_snapshot(document_url, &source, content_type, html_parser);
+ parse_browsing_context_document_snapshot(document_url, &source, content_type, html_parser);
build_detached_document_from_dom_host_with_content_type(
scope,
parsed,
@@ -308,7 +308,7 @@ pub(crate) fn parse_child_document_projection_from_source<'s>(
)
}
-pub(crate) fn preserve_decoded_bom_only_child_body<'a>(
+pub(crate) fn preserve_decoded_bom_only_browsing_context_body<'a>(
source: &'a str,
content_type: Option<&str>,
) -> std::borrow::Cow<'a, str> {
@@ -319,7 +319,7 @@ pub(crate) fn preserve_decoded_bom_only_child_body<'a>(
}
}
-fn parse_child_document_snapshot(
+fn parse_browsing_context_document_snapshot(
document_url: Url,
source: &str,
content_type: Option<&str>,
@@ -438,7 +438,7 @@ mod tests {
#[test]
fn child_document_snapshot_uses_xml_parser_for_xml_like_urls() {
- let (xml, xml_kind) = parse_child_document_snapshot(
+ let (xml, xml_kind) = parse_browsing_context_document_snapshot(
Url::parse("https://example.test/common/dummy.xml").unwrap(),
"<foo>Dummy XML document</foo>\n",
None,
@@ -451,7 +451,7 @@ mod tests {
Some("Dummy XML document")
);
- let (xhtml, xhtml_kind) = parse_child_document_snapshot(
+ let (xhtml, xhtml_kind) = parse_browsing_context_document_snapshot(
Url::parse("https://example.test/common/dummy.xhtml").unwrap(),
r#"<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Dummy XHTML document</title></head><body /></html>
"#,
@@ -465,7 +465,7 @@ mod tests {
Some("Dummy XHTML document")
);
- let (html, html_kind) = parse_child_document_snapshot(
+ let (html, html_kind) = parse_browsing_context_document_snapshot(
Url::parse("https://example.test/common/dummy.html").unwrap(),
"<p>Dummy HTML document</p>\n",
None,
@@ -480,9 +480,9 @@ mod tests {
}
#[test]
- fn child_document_projection_uses_explicit_scripting_mode() {
+ fn browsing_context_document_projection_uses_explicit_scripting_mode() {
let parse = |parser| {
- parse_child_document_snapshot(
+ parse_browsing_context_document_snapshot(
Url::parse("https://example.test/child.html").expect("test URL"),
"<noscript><span id='fallback'></span></noscript>",
Some("text/html"),
diff --git a/moli-renderer-v8/src/javascript_url.rs b/moli-renderer-v8/src/javascript_url.rs
new file mode 100644
index 000000000..6ea50a0f6
--- /dev/null
+++ b/moli-renderer-v8/src/javascript_url.rs
@@ -0,0 +1,27 @@
+use percent_encoding::percent_decode_str;
+use url::Url;
+
+pub(crate) fn decoded_source(url: &Url) -> String {
+ let source = url
+ .as_str()
+ .strip_prefix("javascript:")
+ .unwrap_or_else(|| url.path());
+ percent_decode_str(source).decode_utf8_lossy().into_owned()
+}
+
+pub(crate) fn csp_source(url: &Url) -> String {
+ format!("javascript:{}", decoded_source(url))
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn source_and_csp_source_share_percent_decoding() {
+ let url = Url::parse("javascript:globalThis%2Evalue%20%3D%201").expect("javascript URL");
+
+ assert_eq!(decoded_source(&url), "globalThis.value = 1");
+ assert_eq!(csp_source(&url), "javascript:globalThis.value = 1");
+ }
+}
diff --git a/moli-renderer-v8/src/lib.rs b/moli-renderer-v8/src/lib.rs
index c96534611..44db7e74a 100644
--- a/moli-renderer-v8/src/lib.rs
+++ b/moli-renderer-v8/src/lib.rs
@@ -57,6 +57,7 @@ mod frame_owner_model;
mod host;
mod host_bindings;
mod inspector_microtasks;
+mod javascript_url;
mod layout_renderer;
mod link_as;
mod live_document_parser;
diff --git a/moli-renderer-v8/src/native_bridge/context_host/child_documents/commit.rs b/moli-renderer-v8/src/native_bridge/context_host/child_documents/commit.rs
index 633bd4f84..e184f54c9 100644
--- a/moli-renderer-v8/src/native_bridge/context_host/child_documents/commit.rs
+++ b/moli-renderer-v8/src/native_bridge/context_host/child_documents/commit.rs
@@ -173,7 +173,7 @@ impl JsContextHost {
let source = if is_xml_document {
std::borrow::Cow::Borrowed(snapshot.markup.as_str())
} else {
- crate::dom_parser::preserve_decoded_bom_only_child_body(
+ crate::dom_parser::preserve_decoded_bom_only_browsing_context_body(
&snapshot.markup,
snapshot.content_type.as_deref(),
)
diff --git a/moli-renderer-v8/src/native_bridge/context_host/child_frame_navigation/commit.rs b/moli-renderer-v8/src/native_bridge/context_host/child_frame_navigation/commit.rs
index e93d82065..09c9683d1 100644
--- a/moli-renderer-v8/src/native_bridge/context_host/child_frame_navigation/commit.rs
+++ b/moli-renderer-v8/src/native_bridge/context_host/child_frame_navigation/commit.rs
@@ -17,7 +17,6 @@ use crate::{
FrameScriptJobKind, PendingChildJavascriptUrlDocumentScript,
},
};
-use percent_encoding::percent_decode_str;
use url::Url;
pub(crate) struct ChildFrameNavigationCommitTaskRun {
@@ -468,7 +467,7 @@ impl JsContextHost {
snapshot.local_window_id,
snapshot.document_id,
);
- let source = javascript_url_source(&url);
+ let source = crate::javascript_url::decoded_source(&url);
let work = PendingChildJavascriptUrlDocumentScript {
child_handle: handle,
owner: task_owner,
@@ -769,11 +768,3 @@ impl JsContextHost {
}
}
}
-
-fn javascript_url_source(url: &Url) -> String {
- let source = url
- .as_str()
- .strip_prefix("javascript:")
- .unwrap_or_else(|| url.path());
- percent_decode_str(source).decode_utf8_lossy().into_owned()
-}
diff --git a/moli-renderer-v8/src/native_bridge/context_host/mod.rs b/moli-renderer-v8/src/native_bridge/context_host/mod.rs
index dc84dbd3e..db6601508 100644
--- a/moli-renderer-v8/src/native_bridge/context_host/mod.rs
+++ b/moli-renderer-v8/src/native_bridge/context_host/mod.rs
@@ -199,14 +199,16 @@ pub(crate) use moli_page_types::{
NavigationActivationSeed, NavigationHistoryDocumentId, NavigationHistoryEntryId,
NavigationHistoryEntryKey, NavigationHistoryEntrySeed, NavigationHistorySerializedEntry,
};
-pub(crate) use navigation::{PendingLocationNavigation, PendingTopLevelNavigation};
+pub(crate) use navigation::{
+ PendingLocationNavigation, PendingLocationNavigationKind, PendingTopLevelNavigation,
+};
pub(crate) use popups::{
LightweightPopupClassicScriptFetchTarget, LightweightPopupDocumentFetchTarget,
LightweightPopupNavigationTaskToken, PopupClassicScriptLoadApplication,
PopupDocumentLoadApplication, PopupDocumentLoadBodyActivity, active_lightweight_popup_id,
defer_active_lightweight_popup_restore, enter_active_lightweight_popup_scope,
- enter_top_level_lightweight_popup_scope, javascript_url_csp_source,
- lightweight_popup_id_from_window, restore_active_lightweight_popup_scope,
+ enter_top_level_lightweight_popup_scope, lightweight_popup_id_from_window,
+ restore_active_lightweight_popup_scope,
restore_deferred_active_lightweight_popup_scope_if_present,
};
pub(crate) use range_records::{RangeBoundarySide, RangeRecordHandle};
diff --git a/moli-renderer-v8/src/native_bridge/context_host/navigation.rs b/moli-renderer-v8/src/native_bridge/context_host/navigation.rs
index c6acfc98b..310a7853b 100644
--- a/moli-renderer-v8/src/native_bridge/context_host/navigation.rs
+++ b/moli-renderer-v8/src/native_bridge/context_host/navigation.rs
@@ -69,6 +69,22 @@ pub(crate) struct PendingLocationNavigation {
Option<crate::types::ServiceWorkerClientNavigateContinuation>,
}
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub(crate) enum PendingLocationNavigationKind {
+ JavascriptUrl,
+ Document,
+}
+
+impl PendingLocationNavigation {
+ pub(crate) fn kind(&self) -> PendingLocationNavigationKind {
+ if self.url.scheme() == "javascript" {
+ PendingLocationNavigationKind::JavascriptUrl
+ } else {
+ PendingLocationNavigationKind::Document
+ }
+ }
+}
+
pub(crate) enum PendingTopLevelNavigation {
Location(Box<PendingLocationNavigation>),
#[cfg(test)]
@@ -192,16 +208,12 @@ impl JsContextHost {
)
}
- pub(crate) fn pending_location_navigation_scheme_is(&self, scheme: &str) -> bool {
- self.pending_top_level_navigation
- .as_ref()
- .is_some_and(|pending| {
- matches!(
- pending,
- PendingTopLevelNavigation::Location(pending)
- if pending.url.scheme() == scheme
- )
- })
+ pub(crate) fn pending_location_navigation_kind(&self) -> Option<PendingLocationNavigationKind> {
+ match self.pending_top_level_navigation.as_ref()? {
+ PendingTopLevelNavigation::Location(pending) => Some(pending.kind()),
+ #[cfg(test)]
+ PendingTopLevelNavigation::HistoryTraversal(_) => None,
+ }
}
pub(crate) fn pending_location_navigation_runtime_command_cause(
@@ -238,6 +250,16 @@ impl JsContextHost {
Some(*pending)
}
+ pub(crate) fn take_pending_location_navigation_of_kind(
+ &mut self,
+ expected: PendingLocationNavigationKind,
+ ) -> Option<PendingLocationNavigation> {
+ if self.pending_location_navigation_kind() != Some(expected) {
+ return None;
+ }
+ self.take_pending_location_navigation()
+ }
+
pub(crate) fn clear_pending_location_navigation(&mut self) {
if self.has_pending_location_navigation() {
self.clear_pending_top_level_navigation();
diff --git a/moli-renderer-v8/src/native_bridge/context_host/popups.rs b/moli-renderer-v8/src/native_bridge/context_host/popups.rs
index 3fa41d7ca..08a41927e 100644
--- a/moli-renderer-v8/src/native_bridge/context_host/popups.rs
+++ b/moli-renderer-v8/src/native_bridge/context_host/popups.rs
@@ -52,7 +52,6 @@ use moli_fetch::Request;
use moli_storage_key::{MoliStorageKey, StoragePartitionRelation, site_for_url};
use moli_url::origin_ascii_serialization;
use moli_webapi_declare::{ObjectLiteralDeclaration, WebApiObject};
-use percent_encoding::percent_decode_str;
use std::collections::{HashMap, HashSet};
use url::Url;
@@ -865,16 +864,17 @@ impl JsContextHost {
self.lightweight_popup_window_names.insert(name, popup_id);
}
if moli_url::is_about_blank(&initial_url)
- && let Some(document) = crate::dom_parser::parse_child_document_projection_from_source(
- scope,
- initial_url.clone(),
- "<!doctype html><html><head></head><body></body></html>",
- Some("text/html"),
- None,
- crate::parser::HtmlParser::with_scripting_enabled(
- self.lightweight_popup_scripting_enabled(popup_id),
- ),
- )
+ && let Some(document) =
+ crate::dom_parser::parse_browsing_context_document_projection_from_source(
+ scope,
+ initial_url.clone(),
+ "<!doctype html><html><head></head><body></body></html>",
+ Some("text/html"),
+ None,
+ crate::parser::HtmlParser::with_scripting_enabled(
+ self.lightweight_popup_scripting_enabled(popup_id),
+ ),
+ )
{
if let Some(document_handle) =
self.remember_lightweight_popup_document_handle(scope, popup_id, document)
@@ -903,7 +903,7 @@ impl JsContextHost {
let navigation_task =
LightweightPopupNavigationTaskToken::from_parts(initial_document_owner, navigation_id);
let queue_synthetic_load = if parsed_url.scheme() == "javascript" {
- let source = javascript_url_source(&parsed_url);
+ let source = crate::javascript_url::decoded_source(&parsed_url);
self.queue_lightweight_popup_javascript_url_task(scope, navigation_task, source);
true
} else if moli_url::is_about_blank(&initial_url) {
@@ -961,7 +961,7 @@ impl JsContextHost {
document_target,
)?;
if target_url.scheme() == "javascript" {
- let source = javascript_url_source(&target_url);
+ let source = crate::javascript_url::decoded_source(&target_url);
self.queue_lightweight_popup_javascript_url_task(scope, navigation_task, source);
return Some(window);
}
@@ -1497,7 +1497,7 @@ impl JsContextHost {
let previous_url = current_url.clone().unwrap_or_else(about_blank_url);
if target_url.scheme() == "javascript" {
let owner = self.entered_owner_dispatch_scope(scope);
- let csp_source = javascript_url_csp_source(&target_url);
+ let csp_source = crate::javascript_url::csp_source(&target_url);
if !self.allows_inline_javascript_navigation_by_csp(scope, owner, &csp_source) {
return true;
}
@@ -1508,7 +1508,7 @@ impl JsContextHost {
) else {
return false;
};
- let source = javascript_url_source(&target_url);
+ let source = crate::javascript_url::decoded_source(&target_url);
self.queue_lightweight_popup_javascript_url_task(scope, navigation_task, source);
return true;
}
@@ -2087,16 +2087,18 @@ impl JsContextHost {
} else {
String::new()
};
- let Some(document) = crate::dom_parser::parse_child_document_projection_from_source(
- scope,
- document_url,
- "<!doctype html><html><head></head><body></body></html>",
- Some("text/html"),
- None,
- crate::parser::HtmlParser::with_scripting_enabled(
- self.lightweight_popup_scripting_enabled(popup_id),
- ),
- ) else {
+ let Some(document) =
+ crate::dom_parser::parse_browsing_context_document_projection_from_source(
+ scope,
+ document_url,
+ "<!doctype html><html><head></head><body></body></html>",
+ Some("text/html"),
+ None,
+ crate::parser::HtmlParser::with_scripting_enabled(
+ self.lightweight_popup_scripting_enabled(popup_id),
+ ),
+ )
+ else {
return;
};
if let Some(document_handle) =
@@ -2767,7 +2769,7 @@ impl JsContextHost {
source: LightweightPopupDocumentProjectionSource<'_>,
) -> Option<LightweightPopupDocumentProjectionApplication> {
let popup_id = source.task.popup_id();
- let document = crate::dom_parser::parse_child_document_projection_from_source(
+ let document = crate::dom_parser::parse_browsing_context_document_projection_from_source(
scope,
source.document_url.clone(),
source.markup,
@@ -2918,7 +2920,7 @@ impl JsContextHost {
continue;
};
if let Some(violation) = unsafe { &*self.runtime }
- .script_element_request_csp_report_only_violation_for_child_document(
+ .script_element_request_csp_report_only_violation_for_document(
&continuation.document_url,
&continuation.response_content_security_report_only_policies,
&continuation.response_content_security_reporting_endpoints,
@@ -2934,7 +2936,7 @@ impl JsContextHost {
}
}
if let Some(violation) = unsafe { &*self.runtime }
- .script_element_request_csp_violation_for_child_document(
+ .script_element_request_csp_violation_for_document(
Some(continuation.document_handle),
&continuation.document_url,
&continuation.response_content_security_policies,
@@ -2980,7 +2982,7 @@ impl JsContextHost {
}
if script_src.is_none()
&& let Some(violation) = unsafe { &*self.runtime }
- .inline_script_csp_report_only_violation_for_child_document(
+ .inline_script_csp_report_only_violation_for_document(
&continuation.document_url,
&continuation.response_content_security_report_only_policies,
&continuation.response_content_security_reporting_endpoints,
@@ -2996,7 +2998,7 @@ impl JsContextHost {
}
if script_src.is_none()
&& let Some(violation) = unsafe { &*self.runtime }
- .inline_script_csp_violation_for_child_document(
+ .inline_script_csp_violation_for_document(
Some(continuation.document_handle),
&continuation.document_url,
&continuation.response_content_security_policies,
@@ -3298,7 +3300,7 @@ impl JsContextHost {
let redirect_status =
crate::content_security_policy::ContentSecurityPolicyRedirectStatus::FollowedRedirect;
if let Some(violation) = unsafe { &*self.runtime }
- .script_element_request_csp_report_only_violation_for_child_document_with_redirect_status(
+ .script_element_request_csp_report_only_violation_for_document_with_redirect_status(
document_url,
response_content_security_report_only_policies,
response_content_security_reporting_endpoints,
@@ -3313,7 +3315,7 @@ impl JsContextHost {
);
}
if let Some(violation) = unsafe { &*self.runtime }
- .script_element_request_csp_violation_for_child_document_with_redirect_status(
+ .script_element_request_csp_violation_for_document_with_redirect_status(
document_handle,
document_url,
response_content_security_policies,
@@ -4507,18 +4509,6 @@ fn about_blank_url() -> Url {
Url::parse("about:blank").expect("about:blank should parse")
}
-pub(crate) fn javascript_url_csp_source(url: &Url) -> String {
- format!("javascript:{}", javascript_url_source(url))
-}
-
-fn javascript_url_source(url: &Url) -> String {
- let source = url
- .as_str()
- .strip_prefix("javascript:")
- .unwrap_or_else(|| url.path());
- percent_decode_str(source).decode_utf8_lossy().into_owned()
-}
-
fn urls_refer_to_same_document_except_fragment(current: Option<&Url>, target: &Url) -> bool {
let Some(current) = current else {
return false;
diff --git a/moli-renderer-v8/src/native_bridge/context_host/security_policy.rs b/moli-renderer-v8/src/native_bridge/context_host/security_policy.rs
index 74339f725..054124668 100644
--- a/moli-renderer-v8/src/native_bridge/context_host/security_policy.rs
+++ b/moli-renderer-v8/src/native_bridge/context_host/security_policy.rs
@@ -23,7 +23,7 @@ use crate::{
pub(crate) enum DocumentCspOutcome {
Allowed,
Blocked(DocumentContentSecurityPolicyViolation),
- SkippedChildContext,
+ SkippedNonTopContext,
}
#[derive(Debug, Clone)]
@@ -44,6 +44,16 @@ fn policy_child_window_handle(scope: &mut v8::PinScope<'_, '_>) -> Option<DomHan
.and_then(|value| child_window_handle_from_marker_data(scope, value))
}
+fn policy_owner_dispatch_scope(scope: &mut v8::PinScope<'_, '_>) -> OwnerDispatchScope {
+ if let Some(handle) = policy_child_window_handle(scope) {
+ return OwnerDispatchScope::Child(handle);
+ }
+ if let Some(popup_id) = active_lightweight_popup_id(scope) {
+ return OwnerDispatchScope::LightweightPopup(popup_id);
+ }
+ OwnerDispatchScope::Top
+}
+
impl DocumentCspOutcome {
pub(crate) fn blocks_request(&self) -> bool {
matches!(self, Self::Blocked(_))
@@ -52,7 +62,7 @@ impl DocumentCspOutcome {
pub(crate) fn into_blocking_violation(self) -> Option<DocumentContentSecurityPolicyViolation> {
match self {
Self::Blocked(violation) => Some(violation),
- Self::Allowed | Self::SkippedChildContext => None,
+ Self::Allowed | Self::SkippedNonTopContext => None,
}
}
}
@@ -218,8 +228,8 @@ impl JsContextHost {
request_url: &url::Url,
kind: DocumentSubresourceCspKind,
) -> DocumentCspOutcome {
- if policy_child_window_handle(scope).is_some() {
- return DocumentCspOutcome::SkippedChildContext;
+ if policy_owner_dispatch_scope(scope) != OwnerDispatchScope::Top {
+ return DocumentCspOutcome::SkippedNonTopContext;
}
let (report_only_violation, enforced_violation) = self
.document_subresource_csp_check(request_url, kind)
@@ -532,16 +542,15 @@ impl JsContextHost {
let policy_container = self.lightweight_popup_policy_container(popup_id)?;
// SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
Some(
- unsafe { &*self.runtime }
- .document_connect_csp_check_for_child_document_with_redirect_status(
- self.lightweight_popup_document_handle(popup_id),
- document_url,
- &policy_container.response_content_security_policies,
- &policy_container.response_content_security_report_only_policies,
- &policy_container.content_security_reporting_endpoints,
- request_url,
- redirect_status,
- ),
+ unsafe { &*self.runtime }.document_connect_csp_check_for_document_with_redirect_status(
+ self.lightweight_popup_document_handle(popup_id),
+ document_url,
+ &policy_container.response_content_security_policies,
+ &policy_container.response_content_security_report_only_policies,
+ &policy_container.content_security_reporting_endpoints,
+ request_url,
+ redirect_status,
+ ),
)
}
@@ -557,16 +566,15 @@ impl JsContextHost {
self.child_response_content_security_report_only_policies(handle);
let response_reporting_endpoints = self.child_content_security_reporting_endpoints(handle);
// SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- unsafe { &*self.runtime }
- .document_connect_csp_check_for_child_document_with_redirect_status(
- self.child_browsing_context_document_handle(handle),
- document_url,
- response_policies,
- response_report_only_policies,
- &response_reporting_endpoints,
- request_url,
- redirect_status,
- )
+ unsafe { &*self.runtime }.document_connect_csp_check_for_document_with_redirect_status(
+ self.child_browsing_context_document_handle(handle),
+ document_url,
+ response_policies,
+ response_report_only_policies,
+ &response_reporting_endpoints,
+ request_url,
+ redirect_status,
+ )
}
pub(crate) fn frame_navigation_csp_violation(
@@ -720,44 +728,64 @@ impl JsContextHost {
scope: &mut v8::PinScope<'s, '_>,
allow_trusted_types_eval: bool,
) -> bool {
- let (report_only_violation, enforced_violation) =
- if let Some(handle) = policy_child_window_handle(scope) {
- (
- self.child_eval_csp_report_only_violation(handle, allow_trusted_types_eval),
- self.child_eval_csp_violation(handle, allow_trusted_types_eval),
- )
+ let owner = policy_owner_dispatch_scope(scope);
+ let Some(check) = self.non_url_csp_check_for_owner(
+ owner,
+ if allow_trusted_types_eval {
+ ContentSecurityPolicyNonUrlKind::TrustedTypesEval
} else {
- // SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- let runtime = unsafe { &*self.runtime };
- (
- runtime.eval_csp_report_only_violation(allow_trusted_types_eval),
- runtime.eval_csp_violation(allow_trusted_types_eval),
- )
- };
- self.apply_code_generation_csp_check(scope, report_only_violation, enforced_violation, true)
+ ContentSecurityPolicyNonUrlKind::Eval
+ },
+ ) else {
+ return true;
+ };
+ self.apply_code_generation_csp_check(scope, owner, check, true)
}
pub(crate) fn allows_wasm_code_generation_by_csp<'s>(
&mut self,
scope: &mut v8::PinScope<'s, '_>,
) -> bool {
- let report_only_violation = self.wasm_eval_csp_report_only_violation(scope);
- let enforced_violation = self.wasm_eval_csp_violation(scope);
- self.apply_code_generation_csp_check(
- scope,
- report_only_violation,
- enforced_violation,
- false,
+ let owner = policy_owner_dispatch_scope(scope);
+ let Some(check) =
+ self.non_url_csp_check_for_owner(owner, ContentSecurityPolicyNonUrlKind::WasmEval)
+ else {
+ return true;
+ };
+ self.apply_code_generation_csp_check(scope, owner, check, false)
+ }
+
+ fn non_url_csp_check_for_owner(
+ &self,
+ owner: OwnerDispatchScope,
+ kind: ContentSecurityPolicyNonUrlKind,
+ ) -> Option<DocumentContentSecurityPolicyCheck> {
+ let snapshot = self.owner_document_policy_snapshot(owner)?;
+ // SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
+ Some(
+ unsafe { &*self.runtime }.non_url_csp_check_for_document(
+ snapshot.document_handle,
+ &snapshot.document_url,
+ &snapshot.policy_container.response_content_security_policies,
+ &snapshot
+ .policy_container
+ .response_content_security_report_only_policies,
+ &snapshot
+ .policy_container
+ .content_security_reporting_endpoints,
+ kind,
+ ),
)
}
fn apply_code_generation_csp_check<'s>(
&mut self,
scope: &mut v8::PinScope<'s, '_>,
- mut report_only_violation: Option<DocumentContentSecurityPolicyViolation>,
- mut enforced_violation: Option<DocumentContentSecurityPolicyViolation>,
+ owner: OwnerDispatchScope,
+ check: DocumentContentSecurityPolicyCheck,
include_call_location: bool,
) -> bool {
+ let (mut report_only_violation, mut enforced_violation) = check.into_violations();
if report_only_violation.is_none() && enforced_violation.is_none() {
return true;
}
@@ -773,153 +801,29 @@ impl JsContextHost {
}
let host_ptr: *mut JsContextHost = self;
if let Some(violation) = report_only_violation {
- self.dispatch_content_security_policy_violation_event_best_effort(
- scope, host_ptr, &violation,
+ self.dispatch_content_security_policy_violation_event_for_owner_best_effort(
+ scope, host_ptr, owner, &violation,
);
}
let Some(violation) = enforced_violation else {
return true;
};
- self.dispatch_content_security_policy_violation_event_best_effort(
- scope, host_ptr, &violation,
+ self.dispatch_content_security_policy_violation_event_for_owner_best_effort(
+ scope, host_ptr, owner, &violation,
);
false
}
- pub(crate) fn wasm_eval_csp_violation(
- &self,
- scope: &mut v8::PinScope<'_, '_>,
- ) -> Option<DocumentContentSecurityPolicyViolation> {
- if let Some(handle) = policy_child_window_handle(scope) {
- return self.child_wasm_eval_csp_violation(handle);
- }
- // SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- unsafe { &*self.runtime }.wasm_eval_csp_violation()
- }
-
- pub(crate) fn wasm_eval_csp_report_only_violation(
- &self,
- scope: &mut v8::PinScope<'_, '_>,
- ) -> Option<DocumentContentSecurityPolicyViolation> {
- if let Some(handle) = policy_child_window_handle(scope) {
- return self.child_wasm_eval_csp_report_only_violation(handle);
- }
- // SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- unsafe { &*self.runtime }.wasm_eval_csp_report_only_violation()
- }
-
pub(crate) fn child_wasm_eval_csp_violation(
&self,
handle: DomHandle,
) -> Option<DocumentContentSecurityPolicyViolation> {
- let document_url = self.child_browsing_context_current_url(handle)?;
- let response_policies = self.child_response_content_security_policies(handle);
- let response_reporting_endpoints = self.child_content_security_reporting_endpoints(handle);
- // SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- unsafe { &*self.runtime }.wasm_eval_csp_violation_for_child_document(
- self.child_browsing_context_document_handle(handle),
- &document_url,
- response_policies,
- &response_reporting_endpoints,
- )
- }
-
- pub(crate) fn child_wasm_eval_csp_report_only_violation(
- &self,
- handle: DomHandle,
- ) -> Option<DocumentContentSecurityPolicyViolation> {
- let document_url = self.child_browsing_context_current_url(handle)?;
- let response_report_only_policies =
- self.child_response_content_security_report_only_policies(handle);
- let response_reporting_endpoints = self.child_content_security_reporting_endpoints(handle);
- // SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- unsafe { &*self.runtime }.wasm_eval_csp_report_only_violation_for_child_document(
- &document_url,
- response_report_only_policies,
- &response_reporting_endpoints,
- )
- }
-
- fn child_eval_csp_violation(
- &self,
- handle: DomHandle,
- allow_trusted_types_eval: bool,
- ) -> Option<DocumentContentSecurityPolicyViolation> {
- let document_url = self.child_browsing_context_current_url(handle)?;
- let response_policies = self.child_response_content_security_policies(handle);
- let response_reporting_endpoints = self.child_content_security_reporting_endpoints(handle);
- // SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- unsafe { &*self.runtime }.eval_csp_violation_for_child_document(
- self.child_browsing_context_document_handle(handle),
- &document_url,
- response_policies,
- &response_reporting_endpoints,
- allow_trusted_types_eval,
- )
- }
-
- fn child_eval_csp_report_only_violation(
- &self,
- handle: DomHandle,
- allow_trusted_types_eval: bool,
- ) -> Option<DocumentContentSecurityPolicyViolation> {
- let document_url = self.child_browsing_context_current_url(handle)?;
- let response_report_only_policies =
- self.child_response_content_security_report_only_policies(handle);
- let response_reporting_endpoints = self.child_content_security_reporting_endpoints(handle);
- // SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- unsafe { &*self.runtime }.eval_csp_report_only_violation_for_child_document(
- &document_url,
- response_report_only_policies,
- &response_reporting_endpoints,
- allow_trusted_types_eval,
- )
- }
-
- pub(crate) fn trusted_types_sink_csp_violation(
- &self,
- scope: &mut v8::PinScope<'_, '_>,
- sink: &str,
- sample: &str,
- ) -> Option<DocumentContentSecurityPolicyViolation> {
- if let Some(handle) = policy_child_window_handle(scope) {
- return self.child_trusted_types_sink_csp_violation(handle, sink, sample);
- }
- // SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- unsafe { &*self.runtime }.trusted_types_sink_csp_violation(sink, sample)
- }
-
- pub(crate) fn trusted_types_sink_csp_report_only_violation(
- &self,
- scope: &mut v8::PinScope<'_, '_>,
- sink: &str,
- sample: &str,
- ) -> Option<DocumentContentSecurityPolicyViolation> {
- if policy_child_window_handle(scope).is_some() {
- return None;
- }
- // SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- unsafe { &*self.runtime }.trusted_types_sink_csp_report_only_violation(sink, sample)
- }
-
- pub(crate) fn child_trusted_types_sink_csp_violation(
- &self,
- handle: DomHandle,
- sink: &str,
- sample: &str,
- ) -> Option<DocumentContentSecurityPolicyViolation> {
- let document_url = self.child_browsing_context_current_url(handle)?;
- let response_policies = self.child_response_content_security_policies(handle);
- let response_reporting_endpoints = self.child_content_security_reporting_endpoints(handle);
- // SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- unsafe { &*self.runtime }.trusted_types_sink_csp_violation_for_child_document(
- self.child_browsing_context_document_handle(handle),
- &document_url,
- response_policies,
- &response_reporting_endpoints,
- sink,
- sample,
- )
+ self.non_url_csp_check_for_owner(
+ OwnerDispatchScope::Child(handle),
+ ContentSecurityPolicyNonUrlKind::WasmEval,
+ )?
+ .into_violations()
+ .1
}
pub(crate) fn allows_trusted_type_policy_name(
@@ -927,77 +831,51 @@ impl JsContextHost {
scope: &mut v8::PinScope<'_, '_>,
policy_name: &str,
) -> bool {
- if let Some(handle) = policy_child_window_handle(scope) {
- return self.child_allows_trusted_type_policy_name(handle, policy_name);
- }
+ let Some(snapshot) =
+ self.owner_document_policy_snapshot(policy_owner_dispatch_scope(scope))
+ else {
+ return true;
+ };
// SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- unsafe { &*self.runtime }.allows_trusted_type_policy_name(policy_name)
+ unsafe { &*self.runtime }.allows_trusted_type_policy_name_for_document(
+ snapshot.document_handle,
+ &snapshot.policy_container.response_content_security_policies,
+ &snapshot
+ .policy_container
+ .content_security_reporting_endpoints,
+ policy_name,
+ )
}
pub(crate) fn requires_trusted_types_for_script(
&self,
scope: &mut v8::PinScope<'_, '_>,
) -> bool {
- if let Some(handle) = policy_child_window_handle(scope) {
- return self.child_requires_trusted_types_for_script(handle);
- }
- // SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- unsafe { &*self.runtime }.requires_trusted_types_for_script()
+ self.trusted_types_for_script_requirements(scope)
+ .is_enforced()
}
pub(crate) fn trusted_types_for_script_requirements(
&self,
scope: &mut v8::PinScope<'_, '_>,
) -> TrustedTypesForScriptRequirements {
- if let Some(handle) = policy_child_window_handle(scope) {
- return TrustedTypesForScriptRequirements::enforced_only(
- self.child_requires_trusted_types_for_script(handle),
- );
- }
- // SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- unsafe { &*self.runtime }.trusted_types_for_script_requirements()
+ self.trusted_types_for_script_requirements_for_owner(policy_owner_dispatch_scope(scope))
+ .unwrap_or_default()
}
pub(crate) fn allows_trusted_types_eval(&self, scope: &mut v8::PinScope<'_, '_>) -> bool {
- if let Some(handle) = policy_child_window_handle(scope) {
- let response_policies = self.child_response_content_security_policies(handle);
- let response_reporting_endpoints =
- self.child_content_security_reporting_endpoints(handle);
- // SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- return unsafe { &*self.runtime }.allows_trusted_types_eval_for_child_document(
- self.child_browsing_context_document_handle(handle),
- response_policies,
- &response_reporting_endpoints,
- );
- }
- // SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- unsafe { &*self.runtime }.allows_trusted_types_eval()
- }
-
- pub(crate) fn child_allows_trusted_type_policy_name(
- &self,
- handle: DomHandle,
- policy_name: &str,
- ) -> bool {
- let response_policies = self.child_response_content_security_policies(handle);
- let response_reporting_endpoints = self.child_content_security_reporting_endpoints(handle);
- // SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- unsafe { &*self.runtime }.allows_trusted_type_policy_name_for_child_document(
- self.child_browsing_context_document_handle(handle),
- response_policies,
- &response_reporting_endpoints,
- policy_name,
- )
- }
-
- pub(crate) fn child_requires_trusted_types_for_script(&self, handle: DomHandle) -> bool {
- let response_policies = self.child_response_content_security_policies(handle);
- let response_reporting_endpoints = self.child_content_security_reporting_endpoints(handle);
+ let Some(snapshot) =
+ self.owner_document_policy_snapshot(policy_owner_dispatch_scope(scope))
+ else {
+ return false;
+ };
// SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- unsafe { &*self.runtime }.requires_trusted_types_for_script_for_child_document(
- self.child_browsing_context_document_handle(handle),
- response_policies,
- &response_reporting_endpoints,
+ unsafe { &*self.runtime }.allows_trusted_types_eval_for_document(
+ snapshot.document_handle,
+ &snapshot.policy_container.response_content_security_policies,
+ &snapshot
+ .policy_container
+ .content_security_reporting_endpoints,
)
}
@@ -1031,15 +909,10 @@ impl JsContextHost {
host_ptr: *mut JsContextHost,
violation: &DocumentContentSecurityPolicyViolation,
) {
- if let Some(handle) = policy_child_window_handle(scope) {
- self.dispatch_child_content_security_policy_violation_event_best_effort(
- scope, handle, violation,
- );
- return;
- }
- // SAFETY: JsContextHost is owned by the ScriptVm that owns this DocumentRuntime.
- unsafe { &mut *self.runtime }
- .queue_content_security_policy_violation_event_best_effort(scope, host_ptr, violation);
+ let owner = policy_owner_dispatch_scope(scope);
+ self.dispatch_content_security_policy_violation_event_for_owner_best_effort(
+ scope, host_ptr, owner, violation,
+ );
}
pub(crate) fn dispatch_trusted_types_sink_csp_violation_event_best_effort<'s>(
@@ -1115,18 +988,15 @@ impl JsContextHost {
i32::try_from(frame.get_column()).unwrap_or_default().max(0);
(source_file, line_number, column_number)
});
- let violations = [
- self.trusted_types_sink_csp_report_only_violation(scope, sink, sample),
- self.trusted_types_sink_csp_violation(scope, sink, sample),
- ];
- for mut violation in violations.into_iter().flatten() {
+ let owner = policy_owner_dispatch_scope(scope);
+ for mut violation in self.trusted_types_sink_csp_violations_for_owner(owner, sink, sample) {
if let Some((source_file, line_number, column_number)) = &source_location {
violation.source_file.clone_from(source_file);
violation.line_number = *line_number;
violation.column_number = *column_number;
}
- self.dispatch_content_security_policy_violation_event_best_effort(
- scope, host_ptr, &violation,
+ self.dispatch_content_security_policy_violation_event_for_owner_best_effort(
+ scope, host_ptr, owner, &violation,
);
}
}
diff --git a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_content.rs b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_content.rs
index 72a825cf7..04bf4b84b 100644
--- a/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_content.rs
+++ b/moli-renderer-v8/src/native_bridge/document/detached_install/accessors/iframe_content.rs
@@ -45,7 +45,7 @@ pub(in crate::native_bridge) fn detached_iframe_content_document<'s>(
} else {
parsed_base_url
};
- let document = crate::dom_parser::parse_child_document_projection_from_source(
+ let document = crate::dom_parser::parse_browsing_context_document_projection_from_source(
scope,
snapshot.url.clone(),
&snapshot.markup,
diff --git a/moli-renderer-v8/src/native_bridge/element/activation/targets.rs b/moli-renderer-v8/src/native_bridge/element/activation/targets.rs
index eb5c34c7a..d94c8d304 100644
--- a/moli-renderer-v8/src/native_bridge/element/activation/targets.rs
+++ b/moli-renderer-v8/src/native_bridge/element/activation/targets.rs
@@ -289,7 +289,7 @@ fn hyperlink_javascript_url_allowed_by_csp(
else {
return false;
};
- let source = crate::native_bridge::javascript_url_csp_source(&url);
+ let source = crate::javascript_url::csp_source(&url);
unsafe { &mut *runtime_ptr }.allows_inline_javascript_navigation_by_csp(scope, owner, &source)
}
diff --git a/moli-renderer-v8/src/runtime/owner.rs b/moli-renderer-v8/src/runtime/owner.rs
index 60a304544..db3b44dae 100644
--- a/moli-renderer-v8/src/runtime/owner.rs
+++ b/moli-renderer-v8/src/runtime/owner.rs
@@ -4241,7 +4241,7 @@ impl RendererOwnerHandle {
match entry
.page_vm_mut()
.vm_mut()
- .publish_pending_non_javascript_location_navigation()
+ .publish_pending_document_location_navigation()
{
Ok(published) => published,
Err(error) => {
@@ -4333,7 +4333,7 @@ impl RendererOwnerHandle {
) && let Err(error) = entry
.page_vm_mut()
.vm_mut()
- .publish_pending_non_javascript_location_navigation()
+ .publish_pending_document_location_navigation()
{
let concrete_output = entry
.page_vm_mut()
diff --git a/moli-renderer-v8/src/runtime/owner_local_store/entry.rs b/moli-renderer-v8/src/runtime/owner_local_store/entry.rs
index 5494f0300..9b49afb7e 100644
--- a/moli-renderer-v8/src/runtime/owner_local_store/entry.rs
+++ b/moli-renderer-v8/src/runtime/owner_local_store/entry.rs
@@ -298,7 +298,7 @@ impl LivePageEntry {
&self,
) -> Option<crate::page_task_queue::RendererTopLevelNavigationHandoff> {
let vm = self.active_page_vm()?.vm();
- vm.pending_location_navigation_scheme_is("javascript")
+ vm.has_pending_javascript_location_navigation()
.then(|| vm.pending_location_navigation_handoff())
.flatten()
}
diff --git a/moli-renderer-v8/src/runtime/owner_local_store/mod.rs b/moli-renderer-v8/src/runtime/owner_local_store/mod.rs
index 8ff1deda5..a2692d86c 100644
--- a/moli-renderer-v8/src/runtime/owner_local_store/mod.rs
+++ b/moli-renderer-v8/src/runtime/owner_local_store/mod.rs
@@ -1790,7 +1790,7 @@ impl RendererOwnerLocalStore {
entry
.page_vm_mut()
.vm_mut()
- .publish_pending_non_javascript_location_navigation()?;
+ .publish_pending_document_location_navigation()?;
}
let javascript_dialog_broker = entry.page_vm().javascript_dialog_broker();
let devtools_target = entry.page_vm().devtools_target();
@@ -2605,7 +2605,7 @@ impl RendererOwnerLocalStore {
entry
.page_vm_mut()
.vm_mut()
- .publish_pending_non_javascript_location_navigation()
+ .publish_pending_document_location_navigation()
.map(|_| ())
} else {
Ok(())
diff --git a/moli-renderer-v8/src/runtime/page_vm/document_lifecycle_turn.rs b/moli-renderer-v8/src/runtime/page_vm/document_lifecycle_turn.rs
index 9c064b7fb..cbe89e43b 100644
--- a/moli-renderer-v8/src/runtime/page_vm/document_lifecycle_turn.rs
+++ b/moli-renderer-v8/src/runtime/page_vm/document_lifecycle_turn.rs
@@ -332,9 +332,7 @@ impl PageVm {
)
.await?;
if self.vm().has_pending_location_navigation()
- && !self
- .vm()
- .pending_location_navigation_scheme_is("javascript")
+ && !self.vm().has_pending_javascript_location_navigation()
{
return Ok(self
.transition_lifecycle_for_pending_top_level_navigation(
@@ -455,9 +453,7 @@ impl PageVm {
)
.await?;
if self.vm().has_pending_location_navigation()
- && !self
- .vm()
- .pending_location_navigation_scheme_is("javascript")
+ && !self.vm().has_pending_javascript_location_navigation()
{
return Ok(self
.transition_lifecycle_for_pending_top_level_navigation(
diff --git a/moli-renderer-v8/src/runtime/page_vm/followed_navigation.rs b/moli-renderer-v8/src/runtime/page_vm/followed_navigation.rs
index fc48e143a..6361313b4 100644
--- a/moli-renderer-v8/src/runtime/page_vm/followed_navigation.rs
+++ b/moli-renderer-v8/src/runtime/page_vm/followed_navigation.rs
@@ -2,7 +2,6 @@ use std::{future::Future, pin::Pin, time::Instant};
use anyhow::{Result, anyhow, ensure};
use moli_fetch::{BrowserNavigationRequestKind, FetchCancelHandle, Request, StreamingRawResponse};
-use percent_encoding::percent_decode_str;
use tokio::sync::oneshot;
use tracing::debug;
use url::Url;
@@ -25,14 +24,6 @@ use crate::runtime::{
use super::{PageVm, PageVmEnvConfig, PageVmRuntimeHooks};
-fn javascript_location_navigation_source(url: &Url) -> String {
- let source = url
- .as_str()
- .strip_prefix("javascript:")
- .unwrap_or_else(|| url.path());
- percent_decode_str(source).decode_utf8_lossy().into_owned()
-}
-
pub(super) enum LoadedFollowedLocationNavigation {
NoDocument,
Download(RendererPendingDownloadActivation),
@@ -681,6 +672,7 @@ impl PageVm {
PageVmFollowNavigationTurnOutcome::Completed,
)));
};
+ let navigation_kind = pending.kind();
let initiator_url = self.vm().document_runtime.document_url().clone();
let navigation_handoff = pending.handoff;
let url = pending.url.clone();
@@ -694,7 +686,7 @@ impl PageVm {
let service_worker_client_navigate = pending.service_worker_client_navigate;
tracing::debug!(stage = ?stage, %url, "following pending location navigation asynchronously");
- if url.scheme() == "javascript" {
+ if navigation_kind == crate::native_bridge::PendingLocationNavigationKind::JavascriptUrl {
if let Some(client_id) = reserved_service_worker_client_id {
self.vm_mut()
.unregister_reserved_service_worker_client_after_navigation_abort(client_id);
@@ -1098,7 +1090,9 @@ impl PageVm {
&mut self,
stage: PageVmInitStage,
) -> Result<PageVmFollowNavigationTurnOutcome> {
- let Some(pending) = self.vm_mut().take_pending_location_navigation_with_seed() else {
+ let Some(pending) = self.vm_mut().take_pending_location_navigation_of_kind(
+ crate::native_bridge::PendingLocationNavigationKind::JavascriptUrl,
+ ) else {
return Ok(PageVmFollowNavigationTurnOutcome::Completed);
};
let initiator_url = self.vm().document_runtime.document_url().clone();
@@ -1135,7 +1129,7 @@ impl PageVm {
url: Url,
stage: PageVmInitStage,
) -> Result<PageVmFollowNavigationTurnOutcome> {
- let source = javascript_location_navigation_source(&url);
+ let source = crate::javascript_url::decoded_source(&url);
tracing::debug!(
stage = ?stage,
%url,
diff --git a/moli-renderer-v8/src/runtime/page_vm/javascript_navigation_lifecycle.rs b/moli-renderer-v8/src/runtime/page_vm/javascript_navigation_lifecycle.rs
index b3fb0a284..1a4640adc 100644
--- a/moli-renderer-v8/src/runtime/page_vm/javascript_navigation_lifecycle.rs
+++ b/moli-renderer-v8/src/runtime/page_vm/javascript_navigation_lifecycle.rs
@@ -113,9 +113,7 @@ impl PageVm {
return None;
}
let current_document = self.document_lifecycle.identity();
- let suspends_exact_lifecycle = self
- .vm()
- .pending_location_navigation_scheme_is("javascript")
+ let suspends_exact_lifecycle = self.vm().has_pending_javascript_location_navigation()
&& pending_document_lifecycle_turn
.as_ref()
.is_some_and(|pending| pending.document == current_document);
diff --git a/moli-renderer-v8/src/runtime/page_vm/mod.rs b/moli-renderer-v8/src/runtime/page_vm/mod.rs
index 6becd7f39..0338f9fda 100644
--- a/moli-renderer-v8/src/runtime/page_vm/mod.rs
+++ b/moli-renderer-v8/src/runtime/page_vm/mod.rs
@@ -1871,9 +1871,7 @@ impl PageVm {
fn request_pending_cross_document_navigation_termination(&self) -> bool {
if !self.vm().has_pending_location_navigation()
- || self
- .vm()
- .pending_location_navigation_scheme_is("javascript")
+ || self.vm().has_pending_javascript_location_navigation()
{
return false;
}
@@ -3652,7 +3650,7 @@ impl PageVm {
}
};
let navigation_triggered = if navigation_triggered
- && page_vm.vm().pending_location_navigation_scheme_is("javascript")
+ && page_vm.vm().has_pending_javascript_location_navigation()
{
match page_vm.follow_pending_javascript_location_navigation_if_present(
PageVmInitStage::Load,
@@ -3779,9 +3777,7 @@ impl PageVm {
page_vm.vm_mut().resync_child_browsing_contexts();
let navigation_triggered = page_vm.vm_mut().has_pending_location_navigation();
let navigation_triggered = if navigation_triggered
- && page_vm
- .vm()
- .pending_location_navigation_scheme_is("javascript")
+ && page_vm.vm().has_pending_javascript_location_navigation()
{
match page_vm.follow_pending_javascript_location_navigation_if_present(
PageVmInitStage::Load,
diff --git a/moli-renderer-v8/src/runtime/page_vm/tests/lifecycle.rs b/moli-renderer-v8/src/runtime/page_vm/tests/lifecycle.rs
index 74bf7e85b..ae15760ac 100644
--- a/moli-renderer-v8/src/runtime/page_vm/tests/lifecycle.rs
+++ b/moli-renderer-v8/src/runtime/page_vm/tests/lifecycle.rs
@@ -1195,7 +1195,7 @@ location.href
assert!(
!page_vm
.vm_mut()
- .publish_pending_non_javascript_location_navigation()?,
+ .publish_pending_document_location_navigation()?,
"a javascript: pending navigation must never be published to the browser"
);
assert!(
diff --git a/moli-renderer-v8/src/script_vm.rs b/moli-renderer-v8/src/script_vm.rs
index ac82e1e1b..1d821fd31 100644
--- a/moli-renderer-v8/src/script_vm.rs
+++ b/moli-renderer-v8/src/script_vm.rs
@@ -5398,10 +5398,17 @@ impl ScriptVm {
.has_pending_location_navigation()
}
- pub(super) fn pending_location_navigation_scheme_is(&self, scheme: &str) -> bool {
+ pub(super) fn pending_location_navigation_kind(
+ &self,
+ ) -> Option<super::native_bridge::PendingLocationNavigationKind> {
self._context_host
.borrow()
- .pending_location_navigation_scheme_is(scheme)
+ .pending_location_navigation_kind()
+ }
+
+ pub(super) fn has_pending_javascript_location_navigation(&self) -> bool {
+ self.pending_location_navigation_kind()
+ == Some(super::native_bridge::PendingLocationNavigationKind::JavascriptUrl)
}
pub(super) fn pending_location_navigation_runtime_command_cause(
@@ -5564,14 +5571,22 @@ impl ScriptVm {
.take_pending_location_navigation()
}
- pub(super) fn take_pending_non_javascript_location_navigation(
+ pub(super) fn take_pending_location_navigation_of_kind(
+ &mut self,
+ kind: super::native_bridge::PendingLocationNavigationKind,
+ ) -> Option<super::native_bridge::PendingLocationNavigation> {
+ self._context_host
+ .borrow_mut()
+ .take_pending_location_navigation_of_kind(kind)
+ }
+
+ pub(super) fn take_pending_document_location_navigation(
&mut self,
) -> Option<super::native_bridge::PendingLocationNavigation> {
- if self.pending_location_navigation_scheme_is("javascript") {
- return None;
- }
let source_url = self.document_runtime.document_url().clone();
- let pending = self.take_pending_location_navigation_with_seed()?;
+ let pending = self.take_pending_location_navigation_of_kind(
+ super::native_bridge::PendingLocationNavigationKind::Document,
+ )?;
self.restore_top_level_location_runtime_state(&source_url);
Some(pending)
}
@@ -5583,10 +5598,8 @@ impl ScriptVm {
/// proves that the browser owns the navigation. At that exact boundary we
/// consume it once, freeze its source Document and command cause, and stop
/// relying on protocol to pull mutable Page state in a later turn.
- pub(super) fn publish_pending_non_javascript_location_navigation(
- &mut self,
- ) -> anyhow::Result<bool> {
- let Some(pending) = self.take_pending_non_javascript_location_navigation() else {
+ pub(super) fn publish_pending_document_location_navigation(&mut self) -> anyhow::Result<bool> {
+ let Some(pending) = self.take_pending_document_location_navigation() else {
return Ok(false);
};
let source_document = pending.source_document.ok_or_else(|| {
diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs
index 6d758ba26..1314fbb0a 100644
--- a/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs
+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs
@@ -25317,6 +25317,94 @@ popup.location.href = `javascript:
);
}
+#[tokio::test]
+async fn lightweight_popup_nested_eval_uses_popup_response_csp() {
+ let result = lightweight_popup_nested_eval_result(
+ "script-src 'unsafe-inline' 'unsafe-eval'",
+ "Content-Security-Policy: script-src 'unsafe-inline'",
+ "EvalError",
+ )
+ .await;
+ assert_eq!(result, "EvalError");
+}
+
+#[tokio::test]
+async fn lightweight_popup_nested_eval_uses_popup_response_trusted_types() {
+ let result = lightweight_popup_nested_eval_result(
+ "script-src 'unsafe-inline' 'unsafe-eval'",
+ "Content-Security-Policy: script-src 'unsafe-inline' 'unsafe-eval'; require-trusted-types-for 'script'",
+ "EvalError",
+ )
+ .await;
+ assert_eq!(result, "EvalError");
+}
+
+async fn lightweight_popup_nested_eval_result(
+ opener_policy: &'static str,
+ popup_policy_header: &'static str,
+ expected: &'static str,
+) -> String {
+ let (popup_url, server) = spawn_lightweight_popup_response_html_server(
+ "popup nested eval policy test server",
+ "popup nested eval policy",
+ popup_policy_header,
+ r#"<!doctype html><script>
+trustedTypes.createPolicy("default", {
+ createScript: (value, _type, sink) => sink === "Location href" ? value : null
+});
+onload = () => {
+ location.href = `javascript:
+ try {
+ eval("globalThis.__popupNestedEvalRan = true");
+ opener.postMessage("allowed", "*");
+ } catch (error) {
+ opener.postMessage(error.name, "*");
+ }
+ `;
+};
+</script>"#,
+ )
+ .await;
+ let loader = ResourceRequestClient::new(&moli_fetch::FetchConfig::default()).expect("loader");
+ let document_url = Url::parse(&popup_url)
+ .expect("popup url")
+ .join("/base/page.html")
+ .expect("document url");
+ let mut vm = new_storage_page_task_executor_test_vm_with_loader(document_url.as_str(), &loader);
+ vm.set_response_content_security_policies(&[opener_policy.to_owned()]);
+ let popup_url_literal = serde_json::to_string(&popup_url).expect("serialize popup url");
+
+ vm.eval(&format!(
+ r#"
+globalThis.__popupNestedEvalResult = "pending";
+addEventListener("message", event => {{
+ globalThis.__popupNestedEvalResult = String(event.data);
+}});
+open({popup_url_literal});
+"#
+ ))
+ .expect("popup nested eval setup should evaluate");
+ wait_for_one_page_resource_completion_selected_task_executor_test_turn(
+ &mut vm,
+ &loader,
+ "popup nested eval document completion",
+ )
+ .await;
+ server
+ .await
+ .expect("popup nested eval policy server should finish");
+ advance_page_task_executor_until_eval_equals(
+ &mut vm,
+ &loader,
+ "String(globalThis.__popupNestedEvalResult)",
+ expected,
+ "popup nested eval policy result",
+ )
+ .await;
+ vm.eval("String(globalThis.__popupNestedEvalResult)")
+ .expect("popup nested eval result should evaluate")
+}
+
#[tokio::test]
async fn lightweight_popup_post_message_round_trips_with_wasm_module() {
let loader = ResourceRequestClient::new(&moli_fetch::FetchConfig::default()).expect("loader");
diff --git a/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms.rs b/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms.rs
index 96cbd3ea2..68d46a61d 100644
--- a/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms.rs
+++ b/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms.rs
@@ -3528,7 +3528,7 @@ fn taking_protocol_handoff_location_navigation_restores_source_location() {
assert_eq!(assigned_path, "/download");
let pending_url = vm
- .take_pending_non_javascript_location_navigation()
+ .take_pending_document_location_navigation()
.map(|pending| pending.url)
.expect("location assignment should queue a protocol-visible navigation");
assert_eq!(