Skip to content

armgit / moli

Public Imported from GitHub
0

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

fix(webidl): derive touch receiver checks

ldm0c42ad75e84d5
diff --git a/moli-renderer-v8/src/context_bootstrap/touch_runtime.rs b/moli-renderer-v8/src/context_bootstrap/touch_runtime.rs
index 104ce036c..56f96bf69 100644
--- a/moli-renderer-v8/src/context_bootstrap/touch_runtime.rs
+++ b/moli-renderer-v8/src/context_bootstrap/touch_runtime.rs
@@ -29,7 +29,7 @@ const TOUCH_EVENT_CTRL_KEY_SLOT: &str = "__lmTouchEventCtrlKey";
const TOUCH_EVENT_SHIFT_KEY_SLOT: &str = "__lmTouchEventShiftKey";
#[derive(WebApiFunctionTemplate)]
-#[webapi(interface = web_api_interfaces::Touch)]
+#[webapi(interface = web_api_interfaces::Touch, receiver)]
struct TouchPrototypeDeclaration {
#[webapi(accessor_property, getter = touch_getter, data = callback_data_index_value(scope, 0), enumerable)]
identifier: (),
diff --git a/moli-renderer-v8/src/script_vm/tests/mod.rs b/moli-renderer-v8/src/script_vm/tests/mod.rs
index 127160a03..b76243026 100644
--- a/moli-renderer-v8/src/script_vm/tests/mod.rs
+++ b/moli-renderer-v8/src/script_vm/tests/mod.rs
@@ -1,4 +1,5 @@
mod beforeinput_target_validation;
+
mod child_document_web_fonts;
mod credential_container;
mod credential_json_options;
@@ -7,6 +8,7 @@ mod current_pass_css_fonts;
mod document_encodings;
mod message_port_transfer;
mod picture_in_picture_interfaces;
+mod touch_native_receivers;
mod visual_viewport_receiver;
mod writable_stream_native_receivers;
use super::post_parse::dynamic_script_execute_is_runnable_before_dom_content_loaded;
diff --git a/moli-renderer-v8/src/script_vm/tests/touch_native_receivers.rs b/moli-renderer-v8/src/script_vm/tests/touch_native_receivers.rs
new file mode 100644
index 000000000..83ace144c
--- /dev/null
+++ b/moli-renderer-v8/src/script_vm/tests/touch_native_receivers.rs
@@ -0,0 +1,60 @@
+use super::*;
+
+#[test]
+fn touch_native_receivers_reject_forgery_before_conversion_in_the_callee_realm() {
+ let mut vm = new_storage_html_test_vm("https://touch-native-receivers.test/");
+ let result = vm.eval(r#"
+ document.body.innerHTML = '<iframe></iframe>';
+ const other = document.querySelector('iframe').contentWindow;
+ const touch = new Touch({identifier: 7, target: document.body});
+ let conversions = 0;
+ let traps = 0;
+ const poison = {
+ [Symbol.toPrimitive]() { conversions++; return '3'; },
+ get subtree() { conversions++; throw new Error('unexpected options conversion'); }
+ };
+ const cases = [
+ ["Touch", "identifier", "get", touch, [], [poison]],
+ ["Touch", "target", "get", touch, [], [poison]],
+ ["Touch", "screenX", "get", touch, [], [poison]],
+ ["Touch", "screenY", "get", touch, [], [poison]],
+ ["Touch", "clientX", "get", touch, [], [poison]],
+ ["Touch", "clientY", "get", touch, [], [poison]],
+ ["Touch", "pageX", "get", touch, [], [poison]],
+ ["Touch", "pageY", "get", touch, [], [poison]],
+ ["Touch", "radiusX", "get", touch, [], [poison]],
+ ["Touch", "radiusY", "get", touch, [], [poison]],
+ ["Touch", "rotationAngle", "get", touch, [], [poison]],
+ ["Touch", "force", "get", touch, [], [poison]],
+ ];
+ for (const realm of [window, other]) {
+ for (const [interfaceName, name, kind, value, validArgs, invalidArgs] of cases) {
+ const prototype = realm[interfaceName].prototype;
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, name);
+ const operation = kind === 'method' ? prototype[name] : descriptor && descriptor[kind];
+ if (typeof operation !== 'function')
+ throw new Error(interfaceName + '.' + name + ': missing prototype member');
+ const result = Reflect.apply(operation, value, validArgs);
+ if (kind === 'get' && result === undefined)
+ throw new Error(interfaceName + '.' + name + ': genuine receiver lost native state');
+ const author = new Proxy(value, {
+ get() { traps++; throw new Error('unexpected receiver get'); },
+ getPrototypeOf() { traps++; throw new Error('unexpected receiver prototype'); }
+ });
+ const revoked = Proxy.revocable(value, {}); revoked.revoke();
+ for (const receiver of [null, undefined, {}, Object.create(value),
+ Object.create(prototype), author, revoked.proxy]) {
+ let error;
+ try { Reflect.apply(operation, receiver, invalidArgs); }
+ catch (caught) { error = caught; }
+ if (!error || Object.getPrototypeOf(error) !== realm.TypeError.prototype)
+ throw new Error(interfaceName + '.' + name + ': expected callee TypeError');
+ }
+ }
+ }
+ if (conversions !== 0 || traps !== 0)
+ throw new Error('receiver validation ran author code before rejection');
+ 'ok';
+ "#).unwrap();
+ assert_eq!(result, "ok");
+}