Skip to content

armgit / moli

Public Imported from GitHub
0

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

fix(html): reflect iframe CSP attribute

ldm0bf169dd74fa6
diff --git a/moli-renderer-v8/src/native_bridge/element.rs b/moli-renderer-v8/src/native_bridge/element.rs
index 3dcbbfe3c..3d4488073 100644
--- a/moli-renderer-v8/src/native_bridge/element.rs
+++ b/moli-renderer-v8/src/native_bridge/element.rs
@@ -3896,6 +3896,13 @@ struct HtmlIFrameElementPrototypeDeclaration {
setter = iframe_srcdoc_setter_function
)]
srcdoc: (),
+ #[webapi(
+ accessor_property,
+ getter = dom_string_reflection_getter_function,
+ setter = dom_string_reflection_setter_function,
+ data = DomStringReflection::IframeCsp
+ )]
+ csp: (),
#[webapi(
accessor_property,
getter = html_loading_getter_function,
diff --git a/moli-renderer-v8/src/native_bridge/element/reflection.rs b/moli-renderer-v8/src/native_bridge/element/reflection.rs
index 75d7df3c5..554bf77e8 100644
--- a/moli-renderer-v8/src/native_bridge/element/reflection.rs
+++ b/moli-renderer-v8/src/native_bridge/element/reflection.rs
@@ -188,6 +188,7 @@ pub(super) enum DomStringReflection {
HrWidth,
HtmlTimeDateTime,
HtmlVersion,
+ IframeCsp,
IframeFrameBorder,
IframeHeight,
IframeLoading,
@@ -411,6 +412,15 @@ const DOM_STRING_REFLECTION_DESCRIPTORS: &[(DomStringReflection, DomStringReflec
DomStringReflection::HtmlVersion,
DomStringReflectionDescriptor::new("HTMLHtmlElement", "version", "version"),
),
+ (
+ DomStringReflection::IframeCsp,
+ DomStringReflectionDescriptor::new_html_element(
+ "HTMLIFrameElement",
+ "iframe",
+ "csp",
+ "csp",
+ ),
+ ),
(
DomStringReflection::IframeFrameBorder,
DomStringReflectionDescriptor::new("HTMLIFrameElement", "frameborder", "frameBorder"),
diff --git a/moli-renderer-v8/src/script_vm/tests/dom_elements/detached.rs b/moli-renderer-v8/src/script_vm/tests/dom_elements/detached.rs
index bf0602724..ec05de215 100644
--- a/moli-renderer-v8/src/script_vm/tests/dom_elements/detached.rs
+++ b/moli-renderer-v8/src/script_vm/tests/dom_elements/detached.rs
@@ -7321,6 +7321,14 @@ fn detached_resource_template_accessors_use_owner_prototypes() {
if (!condition) throw new Error(message);
};
const own = (object, name) => Object.prototype.hasOwnProperty.call(object, name);
+ const throwsTypeError = callback => {
+ try {
+ callback();
+ return false;
+ } catch (error) {
+ return error.name === "TypeError";
+ }
+ };
const accessor = (prototype, name, hasSetter = true) => {
const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
assert(!!descriptor, `${prototype.constructor.name}.${name} descriptor missing`);
@@ -7334,6 +7342,7 @@ fn detached_resource_template_accessors_use_owner_prototypes() {
accessor(HTMLStyleElement.prototype, name);
}
accessor(HTMLLinkElement.prototype, "disabled");
+ accessor(HTMLIFrameElement.prototype, "csp");
accessor(HTMLIFrameElement.prototype, "sandbox");
accessor(HTMLIFrameElement.prototype, "allowFullscreen");
for (const name of ["default", "kind", "src", "srclang", "label"]) {
@@ -7343,10 +7352,14 @@ fn detached_resource_template_accessors_use_owner_prototypes() {
accessor(HTMLTrackElement.prototype, "track", false);
const div = document.createElement("div");
- for (const name of ["blocking", "sandbox", "allowFullscreen", "default", "srclang", "readyState", "track"]) {
+ for (const name of ["blocking", "csp", "sandbox", "allowFullscreen", "default", "srclang", "readyState", "track"]) {
assert(!own(HTMLElement.prototype, name), `${name} should not be on HTMLElement.prototype`);
assert(!(name in div), `${name} should not be on div`);
}
+ const cspDescriptor = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, "csp");
+ assert(throwsTypeError(() => cspDescriptor.get.call(div)), "iframe csp getter brand");
+ assert(throwsTypeError(() => cspDescriptor.set.call(div, "script-src 'none'")), "iframe csp setter brand");
+ assert(!div.hasAttribute("csp"), "iframe csp setter must not mutate an incompatible receiver");
const detachedDocument = document.implementation.createHTMLDocument("");
const styleElements = [document.createElement("style"), detachedDocument.createElement("style")];
@@ -7392,18 +7405,23 @@ fn detached_resource_template_accessors_use_owner_prototypes() {
}
for (const iframe of iframeElements) {
- for (const name of ["sandbox", "allowFullscreen"]) {
+ for (const name of ["csp", "sandbox", "allowFullscreen"]) {
assert(!own(iframe, name), `iframe.${name} should not be own before set`);
}
+ assert(iframe.csp === "", "iframe csp default");
+ iframe.csp = 123456;
iframe.sandbox = "allow-scripts";
iframe.allowFullscreen = true;
+ assert(iframe.csp === "123456" && iframe.getAttribute("csp") === "123456", "iframe csp");
assert(iframe.sandbox === "allow-scripts" && iframe.getAttribute("sandbox") === "allow-scripts", "iframe sandbox");
assert(iframe.allowFullscreen === true && iframe.getAttribute("allowfullscreen") === "", "iframe allowFullscreen");
- for (const name of ["sandbox", "allowFullscreen"]) {
+ for (const name of ["csp", "sandbox", "allowFullscreen"]) {
assert(!own(iframe, name), `iframe.${name} should stay inherited after set`);
assert(delete iframe[name], `iframe.${name} delete`);
assert(!own(iframe, name), `iframe.${name} should stay inherited after delete`);
}
+ iframe.setAttribute("csp", "default-src 'self'");
+ assert(iframe.csp === "default-src 'self'", "iframe csp after delete");
assert(iframe.sandbox === "allow-scripts", "iframe sandbox after delete");
assert(iframe.allowFullscreen === true, "iframe allowFullscreen after delete");
}