Skip to content

armgit / moli

Public Imported from GitHub
0

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

fix(svg): validate existing root factory receivers with native brands

ldm0557d40e12d51
diff --git a/moli-renderer-v8/src/context_bootstrap/svg_runtime/bindings.rs b/moli-renderer-v8/src/context_bootstrap/svg_runtime/bindings.rs
index 1c08bf98d..c8c885ff5 100644
--- a/moli-renderer-v8/src/context_bootstrap/svg_runtime/bindings.rs
+++ b/moli-renderer-v8/src/context_bootstrap/svg_runtime/bindings.rs
@@ -481,7 +481,7 @@ struct SvgGradientElementTemplateConstantsDeclaration {
}
#[derive(WebApiFunctionTemplate)]
-#[webapi(interface = web_api_interfaces::SVGSVGElement, enumerable)]
+#[webapi(interface = web_api_interfaces::SVGSVGElement, enumerable, receiver)]
struct SvgSvgElementTemplateMethodsDeclaration {
#[webapi(
method = "createSVGRect",
diff --git a/moli-renderer-v8/src/script_vm/tests/mod.rs b/moli-renderer-v8/src/script_vm/tests/mod.rs
index 3072e1add..0e7b7ce95 100644
--- a/moli-renderer-v8/src/script_vm/tests/mod.rs
+++ b/moli-renderer-v8/src/script_vm/tests/mod.rs
@@ -2168,6 +2168,7 @@ mod rendering_update;
mod script_terminal_completion;
mod streams;
mod svg_filter_interfaces;
+mod svg_root_factory_receivers;
mod svg_switch_mpath_interfaces;
mod url_components;
mod webgl_interfaces;
diff --git a/moli-renderer-v8/src/script_vm/tests/svg_root_factory_receivers.rs b/moli-renderer-v8/src/script_vm/tests/svg_root_factory_receivers.rs
new file mode 100644
index 000000000..c0785bbca
--- /dev/null
+++ b/moli-renderer-v8/src/script_vm/tests/svg_root_factory_receivers.rs
@@ -0,0 +1,46 @@
+use super::*;
+
+#[test]
+fn svg_root_factories_validate_native_receivers_in_main_and_child_realms() {
+ let mut vm = new_parsed_test_vm(
+ "https://svg-root-receivers.test/",
+ "<!doctype html><html><body><iframe></iframe></body></html>",
+ );
+ assert_eq!(vm.eval(r#"(() => {
+ const ns = 'http://www.w3.org/2000/svg';
+ const child = document.querySelector('iframe').contentWindow;
+ const check = (ok, label) => { if (!ok) throw Error(label); };
+ const error = f => { try { f(); } catch (e) { return e; } };
+ for (const realm of [window, child]) {
+ for (const doc of [realm.document, realm.document.implementation.createHTMLDocument('')]) {
+ const svg = doc.createElementNS(ns, 'svg');
+ const matrix = svg.createSVGMatrix();
+ check(matrix instanceof realm.SVGMatrix && matrix.a === 1 && matrix.d === 1, 'genuine matrix factory');
+ const transform = svg.createSVGTransform();
+ check(transform instanceof realm.SVGTransform && transform.matrix.a === 1, 'genuine transform factory');
+ matrix.a = 2;
+ matrix.e = 5;
+ const fromMatrix = svg.createSVGTransformFromMatrix(matrix);
+ check(fromMatrix instanceof realm.SVGTransform && fromMatrix.matrix.a === 2 && fromMatrix.matrix.e === 5, 'matrix conversion');
+ matrix.a = 4;
+ check(fromMatrix.matrix.a === 2, 'matrix conversion returns independent state');
+ let traps = 0;
+ const handler = {get() { traps++; throw Error('receiver trap'); }, getPrototypeOf() { traps++; throw Error('prototype trap'); }};
+ const revoked = realm.Proxy.revocable(svg, handler);
+ revoked.revoke();
+ const receivers = [{}, Object.create(svg), new realm.Proxy(svg, handler), revoked.proxy, doc, doc.createElementNS(ns, 'rect')];
+ for (const method of ['createSVGMatrix', 'createSVGTransform', 'createSVGTransformFromMatrix', 'createSVGRect', 'deselectAll']) {
+ const fn = realm.SVGSVGElement.prototype[method];
+ for (const receiver of receivers) {
+ check(error(() => fn.call(receiver, matrix)) instanceof realm.TypeError, method + ' invalid receiver');
+ }
+ }
+ check(traps === 0, 'receiver branding does not invoke author Proxy traps');
+ }
+ }
+ const otherSvg = child.document.createElementNS(ns, 'svg');
+ check(SVGSVGElement.prototype.createSVGMatrix.call(otherSvg) instanceof SVGMatrix, 'cross-realm genuine root');
+ check(SVGSVGElement.prototype.createSVGTransform.call(otherSvg) instanceof SVGTransform, 'callee-realm transform');
+ return true;
+ })()"#).unwrap(), "true");
+}