Skip to content

Truly independent web browser

LibWeb: Perform the security check on every binding receiver

Shannon Booth5393cc3a14c5
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/async_iterable.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/async_iterable.rs
index 64603bc410a..73672a49e2e 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/async_iterable.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/async_iterable.rs
@@ -17,7 +17,7 @@ use libjs_rust::api::{
};
use crate::bindings::CallContext;
-use crate::bindings::interface::{Interface, define_operation};
+use crate::bindings::interface::{Interface, SecurityCheckType, define_operation, perform_a_security_check};
use crate::bindings::promise::{NativeSteps, WebIdlPromise, create_promise};
use crate::bindings::services::web_bindings_ensure_web_iterator_prototype;
@@ -120,6 +120,7 @@ pub(crate) fn create_default_async_iterator<T: DefaultAsyncIteratorClasses>(
/// rejected.
fn validate_this<T: DefaultAsyncIteratorClasses>(
vm: &Vm,
+ identifier: &str,
this_validation_promise_capability: WebIdlPromise,
) -> Result<IteratorCell<T>, Value> {
let reject = |error: Value| {
@@ -144,10 +145,17 @@ fn validate_this<T: DefaultAsyncIteratorClasses>(
// * the platform object object,
// * the identifier "next", and
// * the type "method".
- // NB: A default asynchronous iterator object is not a platform object.
-
+ //
+ // If this threw an exception e, then:
+ // 1. Perform ! Call(thisValidationPromiseCapability.[[Reject]], undefined, « e »).
+ // 2. Return thisValidationPromiseCapability.[[Promise]].
+ // NB: The "return" method passes the identifier "return".
// 7. If object is not a default asynchronous iterator object for interface, then:
let Some(iterator) = default_async_iterator_of::<T>(object) else {
+ // NB: This runs after the check above, which no Window or Location object passes.
+ perform_a_security_check(vm, Value::from_object(object), identifier, SecurityCheckType::Method)
+ .map_err(|throw| reject(throw.value()))?;
+
// 1. Let error be a new TypeError.
let name = format!("{}AsyncIterator", T::NAME);
let error = vm
@@ -248,7 +256,7 @@ pub(crate) fn async_iterator_next<T: DefaultAsyncIteratorClasses>(vm: &Vm) -> Th
// 5. IfAbruptRejectPromise(object, thisValidationPromiseCapability).
// 6. If object is a platform object, then perform a security check, passing:
// 7. If object is not a default asynchronous iterator object for interface, then:
- let iterator = match validate_this::<T>(vm, this_validation_promise_capability) {
+ let iterator = match validate_this::<T>(vm, "next", this_validation_promise_capability) {
Ok(iterator) => iterator,
Err(promise) => return Ok(promise),
};
@@ -377,7 +385,7 @@ pub(crate) fn async_iterator_return<T: DefaultAsyncIteratorClasses>(vm: &Vm) ->
// 5. IfAbruptRejectPromise(object, returnPromiseCapability).
// 6. If object is a platform object, then perform a security check, passing:
// 7. If object is not a default asynchronous iterator object for interface, then:
- let iterator = match validate_this::<T>(vm, return_promise_capability) {
+ let iterator = match validate_this::<T>(vm, "return", return_promise_capability) {
Ok(iterator) => iterator,
Err(promise) => return Ok(promise),
};
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/interface.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/interface.rs
index d8b150f0997..2c51216c27d 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/interface.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/interface.rs
@@ -32,8 +32,8 @@ use crate::bindings::CallContext;
use crate::bindings::realm_data::wrapper_world_of;
use crate::bindings::services::{
web_bindings_define_unforgeable_attributes, web_bindings_ensure_web_constructor, web_bindings_ensure_web_prototype,
- web_bindings_realm_is_secure_context, web_bindings_realm_is_window, web_bindings_rust_wrapper_for,
- web_bindings_set_rust_wrapper, web_bindings_with_temporary_execution_context,
+ web_bindings_perform_a_security_check, web_bindings_realm_is_secure_context, web_bindings_realm_is_window,
+ web_bindings_rust_wrapper_for, web_bindings_set_rust_wrapper, web_bindings_with_temporary_execution_context,
};
/// What an implementation can tell the bindings about its objects, as a C++ implementation object does by overriding
@@ -198,13 +198,46 @@ impl<T: Interface> ConstructedObject<T> for Ref<T> {
}
}
+/// HTML::SecurityCheckType.
+#[derive(Clone, Copy)]
+#[repr(u8)]
+pub(crate) enum SecurityCheckType {
+ Method,
+ Getter,
+ Setter,
+}
+
+/// https://webidl.spec.whatwg.org/#dfn-perform-a-security-check
+pub(crate) fn perform_a_security_check(
+ vm: &Vm,
+ platform_object: Value,
+ identifier: &str,
+ check_type: SecurityCheckType,
+) -> ThrowCompletionOr<()> {
+ let realm = vm.current_realm().expect("a native function runs in a realm");
+ // SAFETY: The realm is live, the value is live while the native function runs, and the identifier is lent for the
+ // call.
+ unsafe {
+ web_bindings_perform_a_security_check(
+ realm.as_ptr().cast(),
+ platform_object.to_raw(),
+ ak::Span::new(identifier.as_bytes()),
+ check_type as u8,
+ )
+ }
+ .into_completion()
+ .map(|_| ())
+}
+
/// The object an attribute or an operation of an interface runs on, if it is a wrapper of the interface or of an
/// interface that inherits from it, with the object's realm. A nullish this value stands for the global object of
-/// the current realm.
+/// the current realm. https://webidl.spec.whatwg.org/#implementation-check-an-object
pub(crate) fn this_object(
vm: &Vm,
wrapper_class: &'static JSHostClass,
interface_name: &str,
+ identifier: &str,
+ check_type: SecurityCheckType,
) -> ThrowCompletionOr<(Gc<Object>, Gc<Realm>)> {
let mut this_value = vm.this_value();
if this_value.is_nullish() {
@@ -217,6 +250,8 @@ pub(crate) fn this_object(
return Ok((object, object.shape().realm()));
}
}
+ // NB: This runs after the check above, which no Window or Location object passes.
+ perform_a_security_check(vm, this_value, identifier, check_type)?;
vm.throw_completion(ErrorKind::TypeError, ErrorType::NotAnObjectOfType, &[&interface_name])
}
@@ -258,8 +293,12 @@ pub(crate) fn to_interface<T: Interface>(vm: &Vm, value: Value) -> ThrowCompleti
}
/// The `this` value of an operation of a setlike or maplike, its implementation, and the context of its realm.
-pub(crate) fn this_implementation<T: Interface>(vm: &Vm) -> ThrowCompletionOr<(Gc<Object>, Ref<T>, CallContext<'_>)> {
- let (wrapper, realm) = this_object(vm, T::wrapper_class(), T::NAME)?;
+pub(crate) fn this_implementation<'vm, T: Interface>(
+ vm: &'vm Vm,
+ identifier: &str,
+ check_type: SecurityCheckType,
+) -> ThrowCompletionOr<(Gc<Object>, Ref<T>, CallContext<'vm>)> {
+ let (wrapper, realm) = this_object(vm, T::wrapper_class(), T::NAME, identifier, check_type)?;
Ok((wrapper, implementation_of(wrapper), CallContext::new(vm, realm)))
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/iterable.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/iterable.rs
index 82fc7deed30..617ea2cf45d 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/iterable.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/iterable.rs
@@ -18,7 +18,9 @@ use libjs_rust::api::{
use crate::bindings::CallContext;
use crate::bindings::conversions::ToJs;
-use crate::bindings::interface::{Interface, define_operation, this_object};
+use crate::bindings::interface::{
+ Interface, SecurityCheckType, define_operation, perform_a_security_check, this_object,
+};
use crate::bindings::services::web_bindings_ensure_web_iterator_prototype;
// https://webidl.spec.whatwg.org/#default-iterator-object-kind
@@ -141,10 +143,10 @@ pub(crate) fn iterator_next<T: DefaultIteratorClasses>(vm: &Vm) -> ThrowCompleti
// * the platform object object,
// * the identifier "next", and
// * the type "method".
- // NB: A default iterator object is not a platform object.
-
// 5. If object is not a default iterator object for interface, then throw a TypeError.
let Some(iterator) = default_iterator_of::<T>(object) else {
+ // NB: This runs after the check above, which no Window or Location object passes.
+ perform_a_security_check(vm, Value::from_object(object), "next", SecurityCheckType::Method)?;
let name = format!("{}Iterator", T::NAME);
return vm.throw_completion(ErrorKind::TypeError, ErrorType::NotAnObjectOfType, &[&name]);
};
@@ -241,7 +243,13 @@ pub(crate) fn entries<T: DefaultIteratorClasses>(vm: &Vm) -> ThrowCompletionOr<V
// 2. If jsValue is a platform object, then perform a security check, passing jsValue, "%Symbol.iterator%", and
// "method".
// 3. If jsValue does not implement definition, then throw a TypeError.
- let (js_value, realm) = this_object(vm, T::wrapper_class(), T::NAME)?;
+ let (js_value, realm) = this_object(
+ vm,
+ T::wrapper_class(),
+ T::NAME,
+ "%Symbol.iterator%",
+ SecurityCheckType::Method,
+ )?;
// 4. Return a newly created default iterator object for definition, with jsValue as its target, "key+value" as its
// kind, and index set to 0.
@@ -258,7 +266,7 @@ pub(crate) fn keys<T: DefaultIteratorClasses>(vm: &Vm) -> ThrowCompletionOr<Valu
// 1. Let jsValue be ? ToObject(this value).
// 2. If jsValue is a platform object, then perform a security check, passing jsValue, "keys", and "method".
// 3. If jsValue does not implement definition, then throw a TypeError.
- let (js_value, realm) = this_object(vm, T::wrapper_class(), T::NAME)?;
+ let (js_value, realm) = this_object(vm, T::wrapper_class(), T::NAME, "keys", SecurityCheckType::Method)?;
// 4. Return a newly created default iterator object for definition, with jsValue as its target, "key" as its kind,
// and index set to 0.
@@ -275,7 +283,7 @@ pub(crate) fn values<T: DefaultIteratorClasses>(vm: &Vm) -> ThrowCompletionOr<Va
// 1. Let jsValue be ? ToObject(this value).
// 2. If jsValue is a platform object, then perform a security check, passing jsValue, "values", and "method".
// 3. If jsValue does not implement definition, then throw a TypeError.
- let (js_value, realm) = this_object(vm, T::wrapper_class(), T::NAME)?;
+ let (js_value, realm) = this_object(vm, T::wrapper_class(), T::NAME, "values", SecurityCheckType::Method)?;
// 4. Return a newly created default iterator object for definition, with jsValue as its target, "value" as its
// kind, and index set to 0.
@@ -295,7 +303,7 @@ pub(crate) fn for_each<T: DefaultIteratorClasses>(vm: &Vm) -> ThrowCompletionOr<
// 1. Let jsValue be ? ToObject(this value).
// 2. If jsValue is a platform object, then perform a security check, passing jsValue, "forEach", and "method".
// 3. If jsValue does not implement definition, then throw a TypeError.
- let (js_value, realm) = this_object(vm, T::wrapper_class(), T::NAME)?;
+ let (js_value, realm) = this_object(vm, T::wrapper_class(), T::NAME, "forEach", SecurityCheckType::Method)?;
let cx = CallContext::new(vm, realm);
// 4. Let idlCallback be callback, converted to a Function.
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/maplike.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/maplike.rs
index 7b767b1ce5e..330e09d1e7e 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/maplike.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/maplike.rs
@@ -14,7 +14,9 @@ use libjs_rust::api::{
use crate::bindings::CallContext;
use crate::bindings::conversions::{ToJs, to_dom_string};
-use crate::bindings::interface::{Interface, define_attribute, define_operation, this_implementation};
+use crate::bindings::interface::{
+ Interface, SecurityCheckType, define_attribute, define_operation, this_implementation,
+};
/// What the implementation of an interface with a maplike declaration, whose keys are strings, implements.
pub(crate) trait Maplike: Interface {
@@ -84,7 +86,7 @@ pub(crate) fn context_of_map<'vm>(cx: &CallContext<'vm>, map: Gc<Map>) -> CallCo
// https://webidl.spec.whatwg.org/#js-map-size
pub(crate) fn map_size<T: Maplike>(vm: &Vm) -> ThrowCompletionOr<Value> {
// 1. Let O be the this value, implementation-checked against A with identifier "size" and type "getter".
- let (_, implementation, cx) = this_implementation::<T>(vm)?;
+ let (_, implementation, cx) = this_implementation::<T>(vm, "size", SecurityCheckType::Getter)?;
// 2. Let map be the map entries of the IDL value that represents a reference to O.
let map = implementation.map_entries(&cx);
@@ -93,8 +95,8 @@ pub(crate) fn map_size<T: Maplike>(vm: &Vm) -> ThrowCompletionOr<Value> {
Ok(Value::from_f64(map.map_size() as f64))
}
-fn create_map_iterator<T: Maplike>(vm: &Vm, kind: PropertyKind) -> ThrowCompletionOr<Value> {
- let (_, implementation, cx) = this_implementation::<T>(vm)?;
+fn create_map_iterator<T: Maplike>(vm: &Vm, identifier: &str, kind: PropertyKind) -> ThrowCompletionOr<Value> {
+ let (_, implementation, cx) = this_implementation::<T>(vm, identifier, SecurityCheckType::Method)?;
let map = implementation.map_entries(&cx);
Ok(Value::from_object(
MapIterator::create(vm, cx.realm(), map, kind).upcast::<Object>(),
@@ -106,7 +108,7 @@ pub(crate) fn map_iterator_entries<T: Maplike>(vm: &Vm) -> ThrowCompletionOr<Val
// 1. Let O be the this value, implementation-checked against A with identifier "entries" and type "method".
// 2. Let map be the map entries of the IDL value that represents a reference to O.
// 3. Return the result of creating a map iterator from map with kind "key+value".
- create_map_iterator::<T>(vm, PropertyKind::KeyAndValue)
+ create_map_iterator::<T>(vm, "entries", PropertyKind::KeyAndValue)
}
// https://webidl.spec.whatwg.org/#js-map-keys
@@ -114,7 +116,7 @@ pub(crate) fn map_iterator_keys<T: Maplike>(vm: &Vm) -> ThrowCompletionOr<Value>
// 1. Let O be the this value, implementation-checked against A with identifier "keys" and type "method".
// 2. Let map be the map entries of the IDL value that represents a reference to O.
// 3. Return the result of creating a map iterator from map with kind "key".
- create_map_iterator::<T>(vm, PropertyKind::Key)
+ create_map_iterator::<T>(vm, "keys", PropertyKind::Key)
}
// https://webidl.spec.whatwg.org/#js-map-values
@@ -122,13 +124,13 @@ pub(crate) fn map_iterator_values<T: Maplike>(vm: &Vm) -> ThrowCompletionOr<Valu
// 1. Let O be the this value, implementation-checked against A with identifier "values" and type "method".
// 2. Let map be the map entries of the IDL value that represents a reference to O.
// 3. Return the result of creating a map iterator from map with kind "value".
- create_map_iterator::<T>(vm, PropertyKind::Value)
+ create_map_iterator::<T>(vm, "values", PropertyKind::Value)
}
// https://webidl.spec.whatwg.org/#js-map-forEach
pub(crate) fn map_for_each<T: Maplike>(vm: &Vm) -> ThrowCompletionOr<Value> {
// 1. Let O be the this value, implementation-checked against A with identifier "forEach" and type "method".
- let (wrapper, implementation, cx) = this_implementation::<T>(vm)?;
+ let (wrapper, implementation, cx) = this_implementation::<T>(vm, "forEach", SecurityCheckType::Method)?;
// 2. Let map be the map entries of the IDL value that represents a reference to O.
let map = implementation.map_entries(&cx);
@@ -165,8 +167,8 @@ pub(crate) fn map_for_each<T: Maplike>(vm: &Vm) -> ThrowCompletionOr<Value> {
}
/// The map entries of the this value, and the key argument converted to the key type and back to a JS value.
-fn entries_and_key<T: Maplike>(vm: &Vm) -> ThrowCompletionOr<(Gc<Map>, Value)> {
- let (_, implementation, cx) = this_implementation::<T>(vm)?;
+fn entries_and_key<T: Maplike>(vm: &Vm, identifier: &str) -> ThrowCompletionOr<(Gc<Map>, Value)> {
+ let (_, implementation, cx) = this_implementation::<T>(vm, identifier, SecurityCheckType::Method)?;
let map = implementation.map_entries(&cx);
let key = to_dom_string(vm, vm.argument(0))?;
Ok((map, key.to_js(&cx)?))
@@ -175,7 +177,7 @@ fn entries_and_key<T: Maplike>(vm: &Vm) -> ThrowCompletionOr<(Gc<Map>, Value)> {
// https://webidl.spec.whatwg.org/#js-map-get
pub(crate) fn map_get<T: Maplike>(vm: &Vm) -> ThrowCompletionOr<Value> {
// 1. Let O be the this value, implementation-checked against A with identifier "get" and type "method".
- let (_, implementation, cx) = this_implementation::<T>(vm)?;
+ let (_, implementation, cx) = this_implementation::<T>(vm, "get", SecurityCheckType::Method)?;
// 3. Let keyType be the key type specified in the maplike declaration.
// 4. Let keyArg be the first argument passed to this function, or undefined if not supplied.
@@ -194,7 +196,7 @@ pub(crate) fn map_has<T: Maplike>(vm: &Vm) -> ThrowCompletionOr<Value> {
// 3. Let keyType be the key type specified in the maplike declaration.
// 4. Let keyArg be the first argument passed to this function, or undefined if not supplied.
// 5. Let key be keyArg converted to an IDL value of type keyType.
- let (map, key) = entries_and_key::<T>(vm)?;
+ let (map, key) = entries_and_key::<T>(vm, "has")?;
// 7. If map[key] exists, then return true, otherwise return false.
Ok(Value::from_bool(map.map_has(key)))
@@ -203,7 +205,7 @@ pub(crate) fn map_has<T: Maplike>(vm: &Vm) -> ThrowCompletionOr<Value> {
// https://webidl.spec.whatwg.org/#js-map-set
pub(crate) fn map_set<T: MaplikeDeclaration + WritableMaplike>(vm: &Vm) -> ThrowCompletionOr<Value> {
// 1. Let O be the this value, implementation-checked against A with identifier "set" and type "method".
- let (wrapper, implementation, cx) = this_implementation::<T>(vm)?;
+ let (wrapper, implementation, cx) = this_implementation::<T>(vm, "set", SecurityCheckType::Method)?;
// 3. Let keyType be the key type specified in the maplike declaration, and valueType be the value type.
// 4. Let keyArg be the first argument passed to this function, or undefined if not supplied.
@@ -225,7 +227,7 @@ pub(crate) fn map_set<T: MaplikeDeclaration + WritableMaplike>(vm: &Vm) -> Throw
// https://webidl.spec.whatwg.org/#js-map-delete
pub(crate) fn map_delete<T: WritableMaplike>(vm: &Vm) -> ThrowCompletionOr<Value> {
// 1. Let O be the this value, implementation-checked against A with identifier "delete" and type "method".
- let (_, implementation, cx) = this_implementation::<T>(vm)?;
+ let (_, implementation, cx) = this_implementation::<T>(vm, "delete", SecurityCheckType::Method)?;
// 3. Let keyType be the key type specified in the maplike declaration.
// 4. Let keyArg be the first argument passed to this function, or undefined if not supplied.
@@ -241,7 +243,7 @@ pub(crate) fn map_delete<T: WritableMaplike>(vm: &Vm) -> ThrowCompletionOr<Value
// https://webidl.spec.whatwg.org/#js-map-clear
pub(crate) fn map_clear<T: WritableMaplike>(vm: &Vm) -> ThrowCompletionOr<Value> {
// 1. Let O be the this value, implementation-checked against A with identifier "clear" and type "method".
- let (_, implementation, cx) = this_implementation::<T>(vm)?;
+ let (_, implementation, cx) = this_implementation::<T>(vm, "clear", SecurityCheckType::Method)?;
// 3. Clear map.
// NOTE: The map is preserved because there may be existing iterators, currently suspended, iterating over it.
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/services.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/services.rs
index 5b3f2f08e2d..25b0cf72278 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/services.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/services.rs
@@ -71,6 +71,15 @@ unsafe extern "C" {
on_origin: unsafe extern "C" fn(*mut c_void, *const liburl_rust::FfiOrigin),
) -> bool;
+ /// HTML::perform_a_security_check() of the value, with the identifier, which is ASCII, and the
+ /// HTML::SecurityCheckType.
+ pub(crate) fn web_bindings_perform_a_security_check(
+ realm: *mut c_void,
+ platform_object: u64,
+ identifier: ak::Span<'_, u8>,
+ check_type: u8,
+ ) -> libjs_rust::api::RawNativeFunctionResult;
+
/// The wrapper in the realm of a new DOMException with the name, which is ASCII, and the message, a borrowed
/// AK::Utf16String.
pub(crate) fn web_bindings_create_dom_exception(
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/setlike.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/setlike.rs
index 43f1685e405..630f6c91f8f 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/setlike.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/setlike.rs
@@ -14,7 +14,9 @@ use libjs_rust::api::{
};
use crate::bindings::CallContext;
-use crate::bindings::interface::{Interface, define_attribute, define_operation, this_implementation};
+use crate::bindings::interface::{
+ Interface, SecurityCheckType, define_attribute, define_operation, this_implementation,
+};
use crate::bindings::realm_data::{WrapperWorld, wrapper_world_of};
/// The JS collection of an object in each wrapper world that asked for it, as the entries of a collection hold the
@@ -131,7 +133,7 @@ pub(crate) fn context_of_set<'vm>(cx: &CallContext<'vm>, set: Gc<Set>) -> CallCo
// https://webidl.spec.whatwg.org/#js-set-size
pub(crate) fn set_size<T: Setlike>(vm: &Vm) -> ThrowCompletionOr<Value> {
// 1. Let O be the this value, implementation-checked against A with identifier "size" and type "getter".
- let (_, implementation, _) = this_implementation::<T>(vm)?;
+ let (_, implementation, _) = this_implementation::<T>(vm, "size", SecurityCheckType::Getter)?;
// 2. Let set be the set entries of the IDL value that represents a reference to O.
// 3. Return set's size, converted to a JavaScript value.
@@ -139,8 +141,8 @@ pub(crate) fn set_size<T: Setlike>(vm: &Vm) -> ThrowCompletionOr<Value> {
Ok(Value::from_f64(implementation.set_entries_size() as f64))
}
-fn create_set_iterator<T: Setlike>(vm: &Vm, kind: PropertyKind) -> ThrowCompletionOr<Value> {
- let (_, implementation, cx) = this_implementation::<T>(vm)?;
+fn create_set_iterator<T: Setlike>(vm: &Vm, identifier: &str, kind: PropertyKind) -> ThrowCompletionOr<Value> {
+ let (_, implementation, cx) = this_implementation::<T>(vm, identifier, SecurityCheckType::Method)?;
let set = implementation.set_entries(&cx);
Ok(Value::from_object(
SetIterator::create(vm, cx.realm(), set, kind).upcast::<Object>(),
@@ -152,7 +154,7 @@ pub(crate) fn set_iterator_entries<T: Setlike>(vm: &Vm) -> ThrowCompletionOr<Val
// 1. Let O be the this value, implementation-checked against A with identifier "entries" and type "method".
// 2. Let set be the set entries of the IDL value that represents a reference to O.
// 3. Return the result of creating a set iterator from set with kind "key+value".
- create_set_iterator::<T>(vm, PropertyKind::KeyAndValue)
+ create_set_iterator::<T>(vm, "entries", PropertyKind::KeyAndValue)
}
// https://webidl.spec.whatwg.org/#js-set-values
@@ -160,13 +162,13 @@ pub(crate) fn set_iterator_values<T: Setlike>(vm: &Vm) -> ThrowCompletionOr<Valu
// 1. Let O be the this value, implementation-checked against A with identifier "values" and type "method".
// 2. Let set be the set entries of the IDL value that represents a reference to O.
// 3. Return the result of creating a set iterator from set with kind "value".
- create_set_iterator::<T>(vm, PropertyKind::Value)
+ create_set_iterator::<T>(vm, "values", PropertyKind::Value)
}
// https://webidl.spec.whatwg.org/#js-set-forEach
pub(crate) fn set_for_each<T: Setlike>(vm: &Vm) -> ThrowCompletionOr<Value> {
// 1. Let O be the this value, implementation-checked against A with identifier "forEach" and type "method".
- let (wrapper, implementation, cx) = this_implementation::<T>(vm)?;
+ let (wrapper, implementation, cx) = this_implementation::<T>(vm, "forEach", SecurityCheckType::Method)?;
// 2. Let set be the set entries of the IDL value that represents a reference to O.
let set = implementation.set_entries(&cx);
@@ -199,7 +201,7 @@ pub(crate) fn set_for_each<T: Setlike>(vm: &Vm) -> ThrowCompletionOr<Value> {
// https://webidl.spec.whatwg.org/#js-set-has
pub(crate) fn set_has<T: SetlikeDeclaration>(vm: &Vm) -> ThrowCompletionOr<Value> {
// 1. Let O be the this value, implementation-checked against A with identifier "has" and type "method".
- let (_, implementation, _) = this_implementation::<T>(vm)?;
+ let (_, implementation, _) = this_implementation::<T>(vm, "has", SecurityCheckType::Method)?;
// 2. Let set be the set entries of the IDL value that represents a reference to O.
// 3. Let valueType be the value type specified in the setlike declaration.
@@ -216,7 +218,7 @@ pub(crate) fn set_has<T: SetlikeDeclaration>(vm: &Vm) -> ThrowCompletionOr<Value
// https://webidl.spec.whatwg.org/#js-set-add
pub(crate) fn set_add<T: SetlikeDeclaration + WritableSetlike>(vm: &Vm) -> ThrowCompletionOr<Value> {
// 1. Let O be the this value, implementation-checked against A with identifier "add" and type "method".
- let (wrapper, implementation, cx) = this_implementation::<T>(vm)?;
+ let (wrapper, implementation, cx) = this_implementation::<T>(vm, "add", SecurityCheckType::Method)?;
// 3. Let valueType be the value type specified in the setlike declaration.
// 4. Let valueArg be the first argument passed to this function, or undefined if not supplied.
@@ -234,7 +236,7 @@ pub(crate) fn set_add<T: SetlikeDeclaration + WritableSetlike>(vm: &Vm) -> Throw
// https://webidl.spec.whatwg.org/#js-set-delete
pub(crate) fn set_delete<T: SetlikeDeclaration + WritableSetlike>(vm: &Vm) -> ThrowCompletionOr<Value> {
// 1. Let O be the this value, implementation-checked against A with identifier "delete" and type "method".
- let (_, implementation, cx) = this_implementation::<T>(vm)?;
+ let (_, implementation, cx) = this_implementation::<T>(vm, "delete", SecurityCheckType::Method)?;
// 3. Let valueType be the value type specified in the setlike declaration.
// 4. Let valueArg be the first argument passed to this function, or undefined if not supplied.
@@ -251,7 +253,7 @@ pub(crate) fn set_delete<T: SetlikeDeclaration + WritableSetlike>(vm: &Vm) -> Th
// https://webidl.spec.whatwg.org/#js-set-clear
pub(crate) fn set_clear<T: WritableSetlike>(vm: &Vm) -> ThrowCompletionOr<Value> {
// 1. Let O be the this value, implementation-checked against A with identifier "clear" and type "method".
- let (_, implementation, cx) = this_implementation::<T>(vm)?;
+ let (_, implementation, cx) = this_implementation::<T>(vm, "clear", SecurityCheckType::Method)?;
// 3. Empty set.
implementation.set_clear(&cx);
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/css_style_properties.rs b/Libraries/LibWeb/Bindings/Rust/src/css/css_style_properties.rs
index 615a99f7494..31363a21eb9 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/css/css_style_properties.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/css_style_properties.rs
@@ -28,6 +28,13 @@ pub(crate) struct CSSPropertyAccessor {
property_name: &'static str,
}
+impl CSSPropertyAccessor {
+ /// The accessor's security check identifier, which differs from the attribute's only where that cannot matter.
+ pub(crate) fn property_name(&self) -> &'static str {
+ self.property_name
+ }
+}
+
#[derive(Trace)]
#[gc(crate = libjs_rust)]
pub(crate) struct CSSStyleProperties {
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_audio/audio_param_map.rs b/Libraries/LibWeb/Bindings/Rust/src/web_audio/audio_param_map.rs
index d3e3a78fa43..7348db014ca 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/web_audio/audio_param_map.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/web_audio/audio_param_map.rs
@@ -10,7 +10,7 @@ use libjs_rust::api::{Gc, GcRefCell, Map, Trace, Value, Vm};
use super::audio_param::AudioParam;
use crate::bindings::CallContext;
use crate::bindings::conversions::{ToJs, to_dom_string};
-use crate::bindings::interface::{Ref, Wrappable, allocate, this_implementation, wrap};
+use crate::bindings::interface::{Ref, SecurityCheckType, Wrappable, allocate, this_implementation, wrap};
use crate::bindings::maplike::Maplike;
// https://webaudio.github.io/web-audio-api/#AudioParamMap
@@ -50,7 +50,7 @@ impl Maplike for AudioParamMap {
// https://webidl.spec.whatwg.org/#js-map-has
fn has(vm: &Vm) -> libjs_rust::api::ThrowCompletionOr<Value> {
// 1. Let O be the this value, implementation-checked against A with identifier "has" and type "method".
- let (_, implementation, _cx) = this_implementation::<Self>(vm)?;
+ let (_, implementation, _cx) = this_implementation::<Self>(vm, "has", SecurityCheckType::Method)?;
// 2. Let map be the map entries of the IDL value that represents a reference to O.
let map = &implementation.entries;
diff --git a/Libraries/LibWeb/Bindings/RustBindingsServices.cpp b/Libraries/LibWeb/Bindings/RustBindingsServices.cpp
index 751cdd70972..78de6fd8f2a 100644
--- a/Libraries/LibWeb/Bindings/RustBindingsServices.cpp
+++ b/Libraries/LibWeb/Bindings/RustBindingsServices.cpp
@@ -15,6 +15,7 @@
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/Bindings/WrapperWorld.h>
#include <LibWeb/DOM/Document.h>
+#include <LibWeb/HTML/CrossOrigin/AbstractOperations.h>
#include <LibWeb/HTML/CustomElements/CustomElementReactions.h>
#include <LibWeb/HTML/EventLoop/EventLoop.h>
#include <LibWeb/HTML/Scripting/Agent.h>
@@ -108,6 +109,7 @@ bool web_bindings_worker_global_scope_is_closing(HTML::WorkerGlobalScope*);
void web_bindings_with_temporary_execution_context(void* realm, bool callbacks_enabled, void* context, void (*steps)(void*));
bool web_bindings_object_implements_interface(JSObject* object, u16 interface_name);
JSObject* web_bindings_create_dom_exception(void* realm, ReadonlyBytes name, FlatPtr message);
+JSCompletion web_bindings_perform_a_security_check(void* realm, JSValue platform_object, ReadonlyBytes identifier, u8 type);
bool web_bindings_extract_an_origin(JSObject* object, void* ctx, void (*on_origin)(void*, URL::FFI::FfiOrigin const*));
void* web_css_wrap_object(void* realm, void* cell);
@@ -254,6 +256,16 @@ JSObject* web_bindings_create_dom_exception(void* realm, ReadonlyBytes name, Fla
return JS::HostABI::object_to_abi(wrap(host_defined_wrapper_world(js_realm), js_realm, exception).ptr());
}
+JSCompletion web_bindings_perform_a_security_check(void* realm, JSValue platform_object, ReadonlyBytes identifier, u8 type)
+{
+ auto& vm = static_cast<JS::Realm*>(realm)->vm();
+ auto identifier_string = Utf16String::from_utf8_without_validation(StringView { identifier });
+ auto result = HTML::perform_a_security_check(vm, JS::HostABI::value_from_abi(platform_object), identifier_string.utf16_view(), static_cast<HTML::SecurityCheckType>(type));
+ if (result.is_error())
+ return JS::HostABI::throw_completion_to_abi(result.error().value());
+ return JS::HostABI::normal_completion_to_abi(JS::HostABI::value_to_abi(JS::js_undefined()));
+}
+
// https://html.spec.whatwg.org/multipage/browsers.html#extract-an-origin
bool web_bindings_extract_an_origin(JSObject* object, void* ctx, void (*on_origin)(void*, URL::FFI::FfiOrigin const*))
{
diff --git a/Libraries/LibWeb/WebIDL/AsyncIterator.h b/Libraries/LibWeb/WebIDL/AsyncIterator.h
index 61bff77975e..34d8162d5aa 100644
--- a/Libraries/LibWeb/WebIDL/AsyncIterator.h
+++ b/Libraries/LibWeb/WebIDL/AsyncIterator.h
@@ -16,6 +16,7 @@
#include <LibJS/Runtime/VM.h>
#include <LibJS/Runtime/ValueInlines.h>
#include <LibWeb/Export.h>
+#include <LibWeb/HTML/CrossOrigin/AbstractOperations.h>
#include <LibWeb/WebIDL/Promise.h>
namespace Web::WebIDL {
@@ -35,7 +36,7 @@ public:
template<typename AsyncIteratorInterface>
static JS::ThrowCompletionOr<GC::Ptr<JS::Object>> next(JS::Realm& realm, StringView interface_name)
{
- auto validation_result = validate_this<AsyncIteratorInterface>(realm, interface_name);
+ auto validation_result = validate_this<AsyncIteratorInterface>(realm, interface_name, u"next"sv);
return validation_result.visit(
[](GC::Ref<AsyncIteratorInterface> iterator) {
@@ -51,7 +52,7 @@ public:
static JS::ThrowCompletionOr<GC::Ptr<JS::Object>> return_(JS::Realm& realm, StringView interface_name, JS::Value value)
{
auto return_promise_capability = WebIDL::create_promise(realm);
- auto validation_result = validate_this<AsyncIteratorInterface>(realm, interface_name, return_promise_capability);
+ auto validation_result = validate_this<AsyncIteratorInterface>(realm, interface_name, u"return"sv, return_promise_capability);
return validation_result.visit(
[&](GC::Ref<AsyncIteratorInterface> iterator) {
@@ -74,7 +75,7 @@ protected:
private:
template<typename AsyncIteratorInterface>
- static Variant<JS::Completion, GC::Ref<JS::Object>, GC::Ref<AsyncIteratorInterface>> validate_this(JS::Realm& realm, StringView interface_name, GC::Ptr<WebIDL::Promise> this_validation_promise_capability = {})
+ static Variant<JS::Completion, GC::Ref<JS::Object>, GC::Ref<AsyncIteratorInterface>> validate_this(JS::Realm& realm, StringView interface_name, Utf16View const& identifier, GC::Ptr<WebIDL::Promise> this_validation_promise_capability = {})
{
// NOTE: This defines the steps to validate `this` that are common between "next" and "return".
auto& vm = realm.vm();
@@ -91,7 +92,7 @@ private:
// 5. IfAbruptRejectPromise(object, thisValidationPromiseCapability).
auto object = TRY_OR_REJECT(vm, this_validation_promise_capability, this_value.to_object(vm));
- // FIXME: 6. If object is a platform object, then perform a security check, passing:
+ // 6. If object is a platform object, then perform a security check, passing:
// * the platform object object,
// * the identifier "next", and
// * the type "method".
@@ -99,6 +100,8 @@ private:
// If this threw an exception e, then:
// Perform ! Call(thisValidationPromiseCapability.[[Reject]], undefined, « e »).
// Return thisValidationPromiseCapability.[[Promise]].
+ // NB: The "return" method passes the identifier "return".
+ TRY_OR_REJECT(vm, this_validation_promise_capability, HTML::perform_a_security_check(vm, object, identifier, HTML::SecurityCheckType::Method));
// 7. If object is not a default asynchronous iterator object for interface, then:
auto* iterator = JS::host_data_if<AsyncIteratorInterface>(*object);
diff --git a/Meta/Generators/libweb_bindings/attributes.py b/Meta/Generators/libweb_bindings/attributes.py
index c8c04243811..9ab934513db 100644
--- a/Meta/Generators/libweb_bindings/attributes.py
+++ b/Meta/Generators/libweb_bindings/attributes.py
@@ -18,6 +18,7 @@ from Generators.libweb_bindings.extended_attributes import wrap_with_extended_at
from Generators.libweb_bindings.glue_headers import bindings_glue_header_for_interface
from Generators.libweb_bindings.includes import GeneratedIncludes
from Generators.libweb_bindings.realms import member_realm_expr
+from Generators.libweb_bindings.security_checks import implementation_check
from Generators.libweb_bindings.security_checks import interface_needs_security_check
from Generators.libweb_bindings.security_checks import on_the_window
from Generators.libweb_bindings.security_checks import perform_a_security_check
@@ -613,7 +614,7 @@ def write_attribute_getter(
"""
)
out.write(
- f""" idl_object = TRY(impl_from(vm, js_value));
+ f""" idl_object = TRY({implementation_check("js_value", attribute.name, "getter")});
[[maybe_unused]] auto& this_object_realm = js_value.as_object().shape().realm();
{getter_steps}
@@ -654,7 +655,7 @@ def write_attribute_getter(
"""
)
- impl_from_js_value = "TRY(impl_from(vm, js_value))"
+ impl_from_js_value = f"TRY({implementation_check('js_value', attribute.name, 'getter')})"
this_object_realm = "js_value.as_object().shape().realm()"
if window_member_is_cross_origin_accessible(interface, attribute.name, "getter"):
out.write(f" {the_remote_window(includes, 'js_value')}\n")
@@ -723,7 +724,7 @@ def write_attribute_setter(
"""
)
out.write(
- """ auto maybe_idl_object = impl_from(vm, js_value);
+ f""" auto maybe_idl_object = {implementation_check("js_value", attribute.name, "setter")};
"""
)
if window_member_is_cross_origin_accessible(interface, attribute.name, "setter"):
diff --git a/Meta/Generators/libweb_bindings/interfaces.py b/Meta/Generators/libweb_bindings/interfaces.py
index f7f0a890f88..56a87a587a5 100644
--- a/Meta/Generators/libweb_bindings/interfaces.py
+++ b/Meta/Generators/libweb_bindings/interfaces.py
@@ -23,6 +23,7 @@ from Generators.libweb_bindings.includes import GeneratedIncludes
from Generators.libweb_bindings.named_and_indexed_properties import interface_supports_named_properties
from Generators.libweb_bindings.named_and_indexed_properties import legacy_platform_object_info_functions
from Generators.libweb_bindings.overload_resolution import parameter_list_length
+from Generators.libweb_bindings.security_checks import interface_needs_security_check
from Generators.libweb_bindings.wrappers import create_wrapper_function_name
from Generators.libweb_bindings.wrappers import interface_and_inherited_interfaces
from Generators.libweb_bindings.wrappers import interface_needs_wrapper
@@ -142,7 +143,7 @@ def write_wrapper_implementation(
write_create_wrapper_function(out, context, interface)
-def write_impl_from(out: TextIO, includes: GeneratedIncludes, interface: Interface) -> None:
+def write_impl_from(out: TextIO, includes: GeneratedIncludes, context: GenerationContext, interface: Interface) -> None:
if not interface_needs_impl_from(interface):
return
@@ -156,27 +157,37 @@ def write_impl_from(out: TextIO, includes: GeneratedIncludes, interface: Interfa
if interface_needs_wrapper(interface):
includes.add("LibWeb/Bindings/Wrappable.h")
+ includes.add("LibWeb/HTML/CrossOrigin/AbstractOperations.h")
+ security_check = ""
+ if not interface_needs_security_check(context, interface):
+ security_check = """
+ // NB: This runs after the check above, which no Window or Location object passes.
+ TRY(HTML::perform_a_security_check(vm, js_value, identifier, type));
+"""
+
object_conversion = (
f"Web::Bindings::impl_from<{fully_qualified_name_for_interface(interface)}>(&js_value.as_object())"
)
out.write(
- f"""[[maybe_unused]] static JS::ThrowCompletionOr<{fully_qualified_name_for_interface(interface)}*> impl_from(JS::VM& vm, JS::Value js_value)
+ f"""// https://webidl.spec.whatwg.org/#implementation-check-an-object
+[[maybe_unused]] static JS::ThrowCompletionOr<{fully_qualified_name_for_interface(interface)}*> impl_from(JS::VM& vm, JS::Value js_value, [[maybe_unused]] Utf16View const& identifier, [[maybe_unused]] HTML::SecurityCheckType type)
{{
{window_proxy_special_case}
if (js_value.is_object()) {{
if (auto* impl = {object_conversion})
return impl;
}}
+{security_check}
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "{interface.namespaced_name}");
}}
-[[maybe_unused]] static JS::ThrowCompletionOr<{fully_qualified_name_for_interface(interface)}*> impl_from(JS::VM& vm)
+[[maybe_unused]] static JS::ThrowCompletionOr<{fully_qualified_name_for_interface(interface)}*> impl_from(JS::VM& vm, Utf16View const& identifier, HTML::SecurityCheckType type)
{{
auto this_value = vm.this_value();
if (this_value.is_nullish())
this_value = &vm.current_realm()->global_object();
- return impl_from(vm, this_value);
+ return impl_from(vm, this_value, identifier, type);
}}
"""
@@ -339,7 +350,7 @@ JS::ThrowCompletionOr<GC::Ref<JS::Object>> {interface.constructor_class}::constr
)
out.write("}\n\n")
- write_impl_from(out, includes, interface)
+ write_impl_from(out, includes, context, interface)
operations.write_static_operations(out, context, includes, interface)
attributes.write_static_attribute_getters(out, context, includes, interface)
named_and_indexed_properties.write_named_properties_object_implementation(out, includes, interface)
@@ -375,7 +386,7 @@ void {interface.prototype_class}::define_unforgeable_attributes(JS::Realm& realm
operations.define_the_stringifier(out, includes, interface, unforgeable=True)
out.write("}\n\n")
- write_impl_from(out, includes, interface)
+ write_impl_from(out, includes, context, interface)
operations.write_static_operations(out, context, includes, interface)
attributes.write_static_attribute_getters(out, context, includes, interface)
attributes.write_attribute_getters(out, context, includes, interface)
diff --git a/Meta/Generators/libweb_bindings/iterables.py b/Meta/Generators/libweb_bindings/iterables.py
index dd7495faee2..405fa78a90d 100644
--- a/Meta/Generators/libweb_bindings/iterables.py
+++ b/Meta/Generators/libweb_bindings/iterables.py
@@ -191,7 +191,7 @@ def write_pair_iterable_declaration_functions(
// 1. Let jsValue be ? ToObject(this value).
// 2. If jsValue is a platform object, then perform a security check, passing jsValue, "%Symbol.iterator%", and "method".
// 3. If jsValue does not implement definition, then throw a TypeError.
- auto* this_impl = TRY(impl_from(vm, this_value));
+ auto* this_impl = TRY(impl_from(vm, this_value, u"%Symbol.iterator%"sv, HTML::SecurityCheckType::Method));
[[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();
// 4. Return a newly created default iterator object for definition, with jsValue as its target, "key+value" as its kind, and index set to 0.
@@ -208,7 +208,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::keys)
// 1. Let jsValue be ? ToObject(this value).
// 2. If jsValue is a platform object, then perform a security check, passing jsValue, "keys", and "method".
// 3. If jsValue does not implement definition, then throw a TypeError.
- auto* this_impl = TRY(impl_from(vm, this_value));
+ auto* this_impl = TRY(impl_from(vm, this_value, u"keys"sv, HTML::SecurityCheckType::Method));
[[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();
// 4. Return a newly created default iterator object for definition, with jsValue as its target, "key" as its kind, and index set to 0.
@@ -225,7 +225,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::values)
// 1. Let jsValue be ? ToObject(this value).
// 2. If jsValue is a platform object, then perform a security check, passing jsValue, "values", and "method".
// 3. If jsValue does not implement definition, then throw a TypeError.
- auto* this_impl = TRY(impl_from(vm, this_value));
+ auto* this_impl = TRY(impl_from(vm, this_value, u"values"sv, HTML::SecurityCheckType::Method));
[[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();
// 4. Return a newly created default iterator object for definition, with jsValue as its target, "value" as its kind, and index set to 0.
@@ -238,7 +238,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::for_each)
auto this_value = vm.this_value();
if (this_value.is_nullish())
this_value = &realm.global_object();
- auto* this_impl = TRY(impl_from(vm, this_value));
+ auto* this_impl = TRY(impl_from(vm, this_value, u"forEach"sv, HTML::SecurityCheckType::Method));
[[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();
auto callback = vm.argument(0);
@@ -292,8 +292,11 @@ static JS::ThrowCompletionOr<{fully_qualified_name_for_interface(interface)}Iter
{{
auto this_object = TRY(vm.this_value().to_object(vm));
auto* iterator = JS::host_data_if<{fully_qualified_name_for_interface(interface)}Iterator>(*this_object);
- if (!iterator)
+ if (!iterator) {{
+ // NB: This runs after the check above, which no Window or Location object passes.
+ TRY(HTML::perform_a_security_check(vm, this_object, u"next"sv, HTML::SecurityCheckType::Method));
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "{iterator_interface_name}");
+ }}
return iterator;
}}
@@ -334,7 +337,7 @@ def write_async_iterable_declaration_functions(
auto this_value = vm.this_value();
if (this_value.is_nullish())
this_value = &realm.global_object();
- auto* impl = TRY(impl_from(vm, this_value));
+ auto* impl = TRY(impl_from(vm, this_value, u"values"sv, HTML::SecurityCheckType::Method));
[[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();
"""
@@ -436,7 +439,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::get_size)
this_value = &realm.global_object();
// 1. Let O be the this value, implementation-checked against A with identifier "size" and type "getter".
- auto* this_impl = TRY(impl_from(vm, this_value));
+ auto* this_impl = TRY(impl_from(vm, this_value, u"size"sv, HTML::SecurityCheckType::Getter));
[[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();
// 2. Let map be the map entries of the IDL value that represents a reference to O.
@@ -455,7 +458,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::entries)
this_value = &realm.global_object();
// 1. Let O be the this value, implementation-checked against A with identifier "entries" and type "method".
- auto* this_impl = TRY(impl_from(vm, this_value));
+ auto* this_impl = TRY(impl_from(vm, this_value, u"entries"sv, HTML::SecurityCheckType::Method));
auto& this_object_realm = this_value.as_object().shape().realm();
// 2. Let map be the map entries of the IDL value that represents a reference to O.
@@ -474,7 +477,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::keys)
this_value = &realm.global_object();
// 1. Let O be the this value, implementation-checked against A with identifier "keys" and type "method".
- auto* this_impl = TRY(impl_from(vm, this_value));
+ auto* this_impl = TRY(impl_from(vm, this_value, u"keys"sv, HTML::SecurityCheckType::Method));
auto& this_object_realm = this_value.as_object().shape().realm();
// 2. Let map be the map entries of the IDL value that represents a reference to O.
@@ -493,7 +496,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::values)
this_value = &realm.global_object();
// 1. Let O be the this value, implementation-checked against A with identifier "values" and type "method".
- auto* this_impl = TRY(impl_from(vm, this_value));
+ auto* this_impl = TRY(impl_from(vm, this_value, u"values"sv, HTML::SecurityCheckType::Method));
auto& this_object_realm = this_value.as_object().shape().realm();
// 2. Let map be the map entries of the IDL value that represents a reference to O.
@@ -512,7 +515,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::for_each)
this_value = &realm.global_object();
// 1. Let O be the this value, implementation-checked against A with identifier "forEach" and type "method".
- auto* this_impl = TRY(impl_from(vm, this_value));
+ auto* this_impl = TRY(impl_from(vm, this_value, u"forEach"sv, HTML::SecurityCheckType::Method));
auto& this_object_realm = this_value.as_object().shape().realm();
// 2. Let map be the map entries of the IDL value that represents a reference to O.
@@ -549,7 +552,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::get)
this_value = &realm.global_object();
// 1. Let O be the this value, implementation-checked against A with identifier "get" and type "method".
- auto* this_impl = TRY(impl_from(vm, this_value));
+ auto* this_impl = TRY(impl_from(vm, this_value, u"get"sv, HTML::SecurityCheckType::Method));
auto& this_object_realm = this_value.as_object().shape().realm();
// 3. Let keyType be the key type specified in the maplike declaration.
@@ -574,7 +577,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::has)
this_value = &realm.global_object();
// 1. Let O be the this value, implementation-checked against A with identifier "has" and type "method".
- auto* this_impl = TRY(impl_from(vm, this_value));
+ auto* this_impl = TRY(impl_from(vm, this_value, u"has"sv, HTML::SecurityCheckType::Method));
// 3. Let keyType be the key type specified in the maplike declaration.
// 4. Let keyArg be the first argument passed to this function, or undefined if not supplied.
@@ -601,7 +604,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::set)
this_value = &realm.global_object();
// 1. Let O be the this value, implementation-checked against A with identifier "set" and type "method".
- auto* this_impl = TRY(impl_from(vm, this_value));
+ auto* this_impl = TRY(impl_from(vm, this_value, u"set"sv, HTML::SecurityCheckType::Method));
auto& this_object_realm = this_value.as_object().shape().realm();
// 3. Let keyType be the key type specified in the maplike declaration, and valueType be the value type.
@@ -638,7 +641,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::delete_)
this_value = &realm.global_object();
// 1. Let O be the this value, implementation-checked against A with identifier "delete" and type "method".
- auto* this_impl = TRY(impl_from(vm, this_value));
+ auto* this_impl = TRY(impl_from(vm, this_value, u"delete"sv, HTML::SecurityCheckType::Method));
// 3. Let keyType be the key type specified in the maplike declaration.
// 4. Let keyArg be the first argument passed to this function, or undefined if not supplied.
@@ -669,8 +672,8 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::clear)
if (this_value.is_nullish())
this_value = &realm.global_object();
- // 1. Let O be the this value, implementation-checked against A with identifier "delete" and type "method".
- auto* this_impl = TRY(impl_from(vm, this_value));
+ // 1. Let O be the this value, implementation-checked against A with identifier "clear" and type "method".
+ auto* this_impl = TRY(impl_from(vm, this_value, u"clear"sv, HTML::SecurityCheckType::Method));
// 3. Clear map.
// NOTE: The map is preserved because there may be existing iterators, currently suspended, iterating over it.
@@ -710,7 +713,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::get_size)
this_value = &realm.global_object();
// 1. Let O be the this value, implementation-checked against A with identifier "size" and type "getter".
- auto* this_impl = TRY(impl_from(vm, this_value));
+ auto* this_impl = TRY(impl_from(vm, this_value, u"size"sv, HTML::SecurityCheckType::Getter));
auto& this_object_realm = this_value.as_object().shape().realm();
auto& wrapper_world = host_defined_wrapper_world(this_object_realm);
@@ -730,7 +733,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::entries)
this_value = &realm.global_object();
// 1. Let O be the this value, implementation-checked against A with identifier "entries" and type "method".
- auto* this_impl = TRY(impl_from(vm, this_value));
+ auto* this_impl = TRY(impl_from(vm, this_value, u"entries"sv, HTML::SecurityCheckType::Method));
auto& this_object_realm = this_value.as_object().shape().realm();
auto& wrapper_world = host_defined_wrapper_world(this_object_realm);
@@ -750,7 +753,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::values)
this_value = &realm.global_object();
// 1. Let O be the this value, implementation-checked against A with identifier "values" and type "method".
- auto* this_impl = TRY(impl_from(vm, this_value));
+ auto* this_impl = TRY(impl_from(vm, this_value, u"values"sv, HTML::SecurityCheckType::Method));
auto& this_object_realm = this_value.as_object().shape().realm();
auto& wrapper_world = host_defined_wrapper_world(this_object_realm);
@@ -770,7 +773,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::for_each)
this_value = &realm.global_object();
// 1. Let O be the this value, implementation-checked against A with identifier "forEach" and type "method".
- auto* this_impl = TRY(impl_from(vm, this_value));
+ auto* this_impl = TRY(impl_from(vm, this_value, u"forEach"sv, HTML::SecurityCheckType::Method));
auto& this_object_realm = this_value.as_object().shape().realm();
auto& wrapper_world = host_defined_wrapper_world(this_object_realm);
@@ -804,7 +807,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::has)
{{
// 1. Let O be the this value, implementation-checked against A with identifier "has" and type "method".
- auto* this_impl = TRY(impl_from(vm));
+ auto* this_impl = TRY(impl_from(vm, u"has"sv, HTML::SecurityCheckType::Method));
// 3. Let valueType be the value type specified in the setlike declaration.
// 4. Let valueArg be the first argument passed to this function, or undefined if not supplied.
@@ -827,7 +830,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::add)
{{
// 1. Let O be the this value, implementation-checked against A with identifier "add" and type "method".
- auto* this_impl = TRY(impl_from(vm));
+ auto* this_impl = TRY(impl_from(vm, u"add"sv, HTML::SecurityCheckType::Method));
// 3. Let valueType be the value type specified in the setlike declaration.
// 4. Let valueArg be the first argument passed to this function, or undefined if not supplied.
@@ -853,7 +856,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::delete_)
{{
// 1. Let O be the this value, implementation-checked against A with identifier "delete" and type "method".
- auto* this_impl = TRY(impl_from(vm));
+ auto* this_impl = TRY(impl_from(vm, u"delete"sv, HTML::SecurityCheckType::Method));
// 3. Let valueType be the value type specified in the setlike declaration.
// 4. Let valueArg be the first argument passed to this function, or undefined if not supplied.
@@ -881,7 +884,7 @@ JS_DEFINE_NATIVE_FUNCTION({interface.prototype_class}::clear)
{{
// 1. Let O be the this value, implementation-checked against A with identifier "clear" and type "method".
- auto* this_impl = TRY(impl_from(vm));
+ auto* this_impl = TRY(impl_from(vm, u"clear"sv, HTML::SecurityCheckType::Method));
// 3. Empty set.
// NOTE: Note: The set is preserved because there may be existing iterators, currently suspended, iterating over it.
diff --git a/Meta/Generators/libweb_bindings/named_and_indexed_properties.py b/Meta/Generators/libweb_bindings/named_and_indexed_properties.py
index dccc78cc04e..6549e499b6d 100644
--- a/Meta/Generators/libweb_bindings/named_and_indexed_properties.py
+++ b/Meta/Generators/libweb_bindings/named_and_indexed_properties.py
@@ -15,6 +15,7 @@ from Generators.libweb_bindings.cpp_types import implementation_header_for_inter
from Generators.libweb_bindings.extended_attributes import wrap_with_ce_reactions
from Generators.libweb_bindings.includes import GeneratedIncludes
from Generators.libweb_bindings.realms import member_realm_expr
+from Generators.libweb_bindings.security_checks import implementation_check
from Generators.libweb_bindings.to_idl_value import to_idl_value
from Generators.libweb_bindings.to_js_value import to_javascript_value
from Generators.libweb_bindings.wrappers import interface_and_inherited_interfaces
@@ -801,7 +802,7 @@ def write_indexed_property_getter(
{{
[[maybe_unused]] auto& realm = *vm.current_realm();
auto this_value = vm.this_value();
- [[maybe_unused]] auto* idl_object = TRY(impl_from(vm, this_value));
+ [[maybe_unused]] auto* idl_object = TRY({implementation_check("this_value", operation.name, "method")});
[[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();
if (vm.argument_count() < 1)
@@ -845,7 +846,7 @@ def write_named_property_getter(
{{
[[maybe_unused]] auto& realm = *vm.current_realm();
auto this_value = vm.this_value();
- [[maybe_unused]] auto* idl_object = TRY(impl_from(vm, this_value));
+ [[maybe_unused]] auto* idl_object = TRY({implementation_check("this_value", operation.name, "method")});
[[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();
if (vm.argument_count() < 1)
@@ -914,7 +915,7 @@ def write_named_property_operation(
{{
[[maybe_unused]] auto& realm = *vm.current_realm();
auto this_value = vm.this_value();
- [[maybe_unused]] auto* idl_object = TRY(impl_from(vm, this_value));
+ [[maybe_unused]] auto* idl_object = TRY({implementation_check("this_value", operation.name, "method")});
[[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();
"""
)
diff --git a/Meta/Generators/libweb_bindings/operations.py b/Meta/Generators/libweb_bindings/operations.py
index 2cc07adbc8d..e5b52689daf 100644
--- a/Meta/Generators/libweb_bindings/operations.py
+++ b/Meta/Generators/libweb_bindings/operations.py
@@ -21,6 +21,7 @@ from Generators.libweb_bindings.glue_headers import bindings_glue_header_for_int
from Generators.libweb_bindings.includes import GeneratedIncludes
from Generators.libweb_bindings.realms import member_passes_realm_to_implementation
from Generators.libweb_bindings.realms import member_realm_expr
+from Generators.libweb_bindings.security_checks import implementation_check
from Generators.libweb_bindings.security_checks import interface_needs_security_check
from Generators.libweb_bindings.security_checks import on_the_window
from Generators.libweb_bindings.security_checks import perform_a_security_check
@@ -408,7 +409,7 @@ def write_stringifier(
"""
)
out.write(
- f""" auto* idl_object = TRY(impl_from(vm, this_value));
+ f""" auto* idl_object = TRY({implementation_check("this_value", "toString", "method")});
[[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();
auto R = TRY(WebIDL::throw_dom_exception_if_needed(vm, realm, [&] {{ return {stringifier_call}; }}));
return {to_javascript_value(stringifier_type, "R", includes, context, "this_object_realm")};
@@ -485,7 +486,7 @@ def write_operation(
"""
)
- impl_from_this_value = "TRY(impl_from(vm, this_value))"
+ impl_from_this_value = f"TRY({implementation_check('this_value', operation.name, 'method')})"
this_object_realm = "this_value.as_object().shape().realm()"
if on_remote_window:
out.write(f" {the_remote_window(includes, 'this_value')}\n")
@@ -781,7 +782,7 @@ def write_default_to_json_operation(
auto this_value = vm.this_value();
if (this_value.is_nullish())
this_value = &realm.global_object();
- [[maybe_unused]] auto* idl_object = TRY(impl_from(vm, this_value));
+ [[maybe_unused]] auto* idl_object = TRY({implementation_check("this_value", operation.name, "method")});
[[maybe_unused]] auto& this_object_realm = this_value.as_object().shape().realm();
// 4. Let result be OrdinaryObjectCreate(%Object.prototype%).
diff --git a/Meta/Generators/libweb_bindings/rust_bindings.py b/Meta/Generators/libweb_bindings/rust_bindings.py
index 4ceb149bbbf..ad2106a397d 100644
--- a/Meta/Generators/libweb_bindings/rust_bindings.py
+++ b/Meta/Generators/libweb_bindings/rust_bindings.py
@@ -1080,10 +1080,9 @@ def write_rust_async_iterator(out: TextIO, context: GenerationContext, interface
/// https://webidl.spec.whatwg.org/#es-asynchronous-iterable
fn {async_iterator.function}(vm: &Vm) -> ThrowCompletionOr<Value> {{
// 1. Let jsValue be ? ToObject(this value).
- // 2. If jsValue is a platform object, then perform a security check, passing jsValue, "%Symbol.asyncIterator%",
- // and "method".
+ // 2. If jsValue is a platform object, then perform a security check, passing jsValue, "values", and "method".
// 3. If jsValue does not implement definition, then throw a TypeError.
- let (implementation, mut cx) = this_implementation(vm)?;
+ let (implementation, mut cx) = this_implementation(vm, "values", SecurityCheckType::Method)?;
// 4. Let idlArgs be the result of converting arguments for an asynchronous iterator method given arguments.
"""
@@ -1139,7 +1138,7 @@ RUST_BINDINGS_IMPORTS = """ #![allow(unused_imports)]
define_attribute, define_cached_attribute, define_constants, define_indexed_properties_iterator,
define_interface_object_properties, define_operation, define_to_string_tag, define_unimplemented_property,
define_value_iterator_properties, entry_point_arguments, implementation_if, implementation_of,
- prototype_from_new_target, realm_is_secure_context, realm_is_window, set_dictionary_member,
+ SecurityCheckType, prototype_from_new_target, realm_is_secure_context, realm_is_window, set_dictionary_member,
set_interface_prototype_object_prototype, this_object, to_interface,
};
use crate::bindings::async_iterable::{
@@ -1278,18 +1277,18 @@ def write_rust_interface(
call = f"Implementation::{attribute.getter_method}(&implementation, &mut cx)"
if attribute.attribute.inherit:
call = inherited_attribute_getter_call(context, interface, attribute)
- this_check = "this_implementation(vm)?"
+ this_check = f'this_implementation(vm, "{name}", SecurityCheckType::Getter)?'
if is_promise_type(attribute.attribute.type) and not attribute.attribute.type.nullable:
# https://webidl.spec.whatwg.org/#dfn-attribute-getter
- this_check = """match this_implementation(vm) {
+ this_check = f"""match this_implementation(vm, "{name}", SecurityCheckType::Getter) {{
Ok(this) => this,
// If the attribute's type is a promise type, a this value that does not implement the interface rejects
// a new promise.
- Err(throw) => {
+ Err(throw) => {{
let realm = vm.current_realm().expect("a native function runs in a realm");
return Ok(Value::from_object(create_rejected_promise(vm, realm, throw.value()).promise()));
- }
- }"""
+ }}
+ }}"""
receiver = "(implementation, mut cx)"
caller_realm_context = ""
if "NeedsCallerRealm" in attribute.attribute.extended_attributes:
@@ -1665,7 +1664,7 @@ def write_default_to_json(out: TextIO, context: GenerationContext, interface: In
out.write(
f"""
fn {function}(vm: &Vm) -> ThrowCompletionOr<Value> {{
- this_implementation(vm)?;
+ this_implementation(vm, "toJSON", SecurityCheckType::Method)?;
let realm = vm.current_realm().expect("a native function runs in a realm");
let cx = CallContext::new(vm, realm);
// 4. Let result be OrdinaryObjectCreate(%Object.prototype%).
@@ -1989,7 +1988,7 @@ def write_rust_stringifier(out: TextIO, function: str, method: str) -> None:
out.write(
f"""
fn {function}(vm: &Vm) -> ThrowCompletionOr<Value> {{
- let (implementation, mut cx) = this_implementation(vm)?;
+ let (implementation, mut cx) = this_implementation(vm, "toString", SecurityCheckType::Method)?;
let result = Implementation::{method}(&implementation, &mut cx)
.map_err(|exception| exception.throw_in_current_realm(cx.vm()))?;
result.to_js(&cx)
@@ -2065,8 +2064,12 @@ def write_this_implementation(out: TextIO, context: GenerationContext, interface
out.write(
"""
/// The object that an attribute or an operation runs on, and the context it runs in.
- fn this_implementation(vm: &Vm) -> ThrowCompletionOr<(Ref<Implementation>, CallContext<'_>)> {
- let (object, realm) = this_object(vm, Implementation::wrapper_class(), Implementation::NAME)?;
+ fn this_implementation<'vm>(
+ vm: &'vm Vm,
+ identifier: &str,
+ check_type: SecurityCheckType,
+ ) -> ThrowCompletionOr<(Ref<Implementation>, CallContext<'vm>)> {
+ let (object, realm) = this_object(vm, Implementation::wrapper_class(), Implementation::NAME, identifier, check_type)?;
Ok((implementation_of(object), CallContext::new(vm, realm)))
}
"""
@@ -2128,8 +2131,12 @@ def write_this_implementation(out: TextIO, context: GenerationContext, interface
}}
/// The object that an attribute or an operation runs on, and the context it runs in.
- fn this_implementation(vm: &Vm) -> ThrowCompletionOr<(Receiver, CallContext<'_>)> {{
- let (object, realm) = this_object(vm, Implementation::wrapper_class(), Implementation::NAME)?;
+ fn this_implementation<'vm>(
+ vm: &'vm Vm,
+ identifier: &str,
+ check_type: SecurityCheckType,
+ ) -> ThrowCompletionOr<(Receiver, CallContext<'vm>)> {{
+ let (object, realm) = this_object(vm, Implementation::wrapper_class(), Implementation::NAME, identifier, check_type)?;
Ok((receiver_of(object), CallContext::new(vm, realm)))
}}
"""
@@ -2143,7 +2150,7 @@ def write_rust_event_handler_attribute(out: TextIO, attribute: RustAttribute) ->
out.write(
f"""
pub(super) fn {attribute.getter_function}(vm: &Vm) -> ThrowCompletionOr<Value> {{
- let (implementation, _) = this_implementation(vm)?;
+ let (implementation, _) = this_implementation(vm, "{attribute.attribute.name}", SecurityCheckType::Getter)?;
let object: &Implementation = &implementation;
Ok(event_handler_attribute(object, "{attribute.event_type}"))
}}
@@ -2154,7 +2161,7 @@ def write_rust_event_handler_attribute(out: TextIO, attribute: RustAttribute) ->
f"""
fn {attribute.setter_function}(vm: &Vm) -> ThrowCompletionOr<Value> {{
let value = vm.argument(0);
- let (implementation, mut cx) = this_implementation(vm)?;
+ let (implementation, mut cx) = this_implementation(vm, "{attribute.attribute.name}", SecurityCheckType::Setter)?;
Implementation::{attribute.setter_method}(&implementation, &mut cx, value);
Ok(Value::UNDEFINED)
}}
@@ -2165,7 +2172,7 @@ def write_rust_event_handler_attribute(out: TextIO, attribute: RustAttribute) ->
f"""
fn {attribute.setter_function}(vm: &Vm) -> ThrowCompletionOr<Value> {{
let value = vm.argument(0);
- let (implementation, _) = this_implementation(vm)?;
+ let (implementation, _) = this_implementation(vm, "{attribute.attribute.name}", SecurityCheckType::Setter)?;
let object: &Implementation = &implementation;
set_event_handler_attribute(object, "{attribute.event_type}", value);
Ok(Value::UNDEFINED)
@@ -2202,7 +2209,7 @@ def write_css_property_accessors(out: TextIO) -> None:
out.write(
"""
fn property_getter(vm: &Vm, property: &crate::css::css_style_properties::CSSPropertyAccessor) -> ThrowCompletionOr<Value> {
- let (implementation, mut cx) = this_implementation(vm)?;
+ let (implementation, mut cx) = this_implementation(vm, property.property_name(), SecurityCheckType::Getter)?;
let result = Implementation::property_value(&implementation, &mut cx, property)
.map_err(|exception| exception.throw_in_current_realm(cx.vm()))?;
result.to_js(&cx)
@@ -2210,7 +2217,7 @@ def write_css_property_accessors(out: TextIO) -> None:
fn property_setter(vm: &Vm, property: &crate::css::css_style_properties::CSSPropertyAccessor) -> ThrowCompletionOr<Value> {
let value = vm.argument(0);
- let (implementation, mut cx) = this_implementation(vm)?;
+ let (implementation, mut cx) = this_implementation(vm, property.property_name(), SecurityCheckType::Setter)?;
let idl_value = to_dom_string_treating_null_as_empty(vm, value)?;
with_custom_element_reactions(|| Implementation::set_property_value(&implementation, &mut cx, property, idl_value))
.map_err(|exception| exception.throw_in_current_realm(cx.vm()))?;
@@ -2257,7 +2264,7 @@ def write_rust_attribute_setter(
f"""
fn {attribute.setter_function}(vm: &Vm) -> ThrowCompletionOr<Value> {{
let value = vm.argument(0);
- let {receiver} = this_implementation(vm)?;
+ let {receiver} = this_implementation(vm, "{attribute.attribute.name}", SecurityCheckType::Setter)?;
{caller_realm_context} {conversion}
{call}
.map_err(|exception| exception.throw_in_current_realm(cx.vm()))?;
@@ -2274,7 +2281,7 @@ def write_rust_put_forwards_setter(out: TextIO, attribute: RustAttribute) -> Non
f"""
fn {attribute.setter_function}(vm: &Vm) -> ThrowCompletionOr<Value> {{
let value = vm.argument(0);
- let (object, _) = this_object(vm, Implementation::wrapper_class(), Implementation::NAME)?;
+ let (object, _) = this_object(vm, Implementation::wrapper_class(), Implementation::NAME, "{attribute.attribute.name}", SecurityCheckType::Setter)?;
let receiver = object.get(vm, &PropertyKey::from_utf8("{attribute.attribute.name}"))?;
if !receiver.is_object() {{
return vm.throw_completion(ErrorKind::TypeError, ErrorType::NotAnObject, &[&"{attribute.attribute.name}"]);
@@ -2300,9 +2307,14 @@ def write_rust_operation(
what = f"{interface.name}.{name}()"
steps = StringIO()
if "NeedsCallerRealm" in operation.extended_attributes:
- steps.write(f" let (implementation, _) = this_implementation(vm)?;\n{CALLER_REALM_CONTEXT}")
+ steps.write(
+ f' let (implementation, _) = this_implementation(vm, "{operation.name}", SecurityCheckType::Method)?;\n'
+ f"{CALLER_REALM_CONTEXT}"
+ )
else:
- steps.write(" let (implementation, mut cx) = this_implementation(vm)?;\n")
+ steps.write(
+ f' let (implementation, mut cx) = this_implementation(vm, "{operation.name}", SecurityCheckType::Method)?;\n'
+ )
write_argument_count_check(steps, name, overload.length)
write_parameter_conversions(steps, what, operation.parameters, context)
arguments = "".join(f", {rust_local_name(parameter.name)}" for parameter in operation.parameters)
diff --git a/Meta/Generators/libweb_bindings/security_checks.py b/Meta/Generators/libweb_bindings/security_checks.py
index 5e75c86a3ec..2c91107da04 100644
--- a/Meta/Generators/libweb_bindings/security_checks.py
+++ b/Meta/Generators/libweb_bindings/security_checks.py
@@ -13,8 +13,8 @@ SecurityCheckType = Literal["method", "getter", "setter"]
def interface_needs_security_check(context: GenerationContext, interface: Interface) -> bool:
- # NOTE: The HTML Standard's security check returns early for any platform object that is not a Window or Location
- # object, so it only needs to be performed for members of interfaces that those objects implement.
+ # NB: Only a Window or Location object can fail the security check, so other interfaces' impl_from() performs it
+ # only once their implementation check fails.
for platform_interface_name in ("Window", "Location"):
platform_interface = context.interfaces.get(platform_interface_name)
if platform_interface is None:
@@ -27,6 +27,12 @@ def interface_needs_security_check(context: GenerationContext, interface: Interf
return False
+# https://webidl.spec.whatwg.org/#implementation-check-an-object
+def implementation_check(js_value: Optional[str], identifier: str, type_: SecurityCheckType) -> str:
+ js_value_argument = f"{js_value}, " if js_value else ""
+ return f'impl_from(vm, {js_value_argument}u"{identifier}"sv, HTML::SecurityCheckType::{type_.capitalize()})'
+
+
# https://webidl.spec.whatwg.org/#dfn-perform-a-security-check
def perform_a_security_check(
includes: GeneratedIncludes,
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index 364f1fede61..4bad52eaab9 100644
--- a/Tests/LibWeb/TestConfig.ini
+++ b/Tests/LibWeb/TestConfig.ini
@@ -5,6 +5,7 @@ Text/input/PDF/jbig2-image.html
[LoadFromHttpServer]
; A data: iframe stays in this process only under an http: page.
Text/input/HTML/cross-origin-rejected-promise-realm.html
+Text/input/HTML/cross-origin-receiver-security-check.html
Text/input/HTML/dynamic-function-foreign-prototype-realm.html
Text/input/wpt-import/web-locks/acquire.https.any.worker.html
Text/input/wpt-import/web-locks/signal.https.any.worker.html
diff --git a/Tests/LibWeb/Text/expected/HTML/cross-origin-receiver-security-check.txt b/Tests/LibWeb/Text/expected/HTML/cross-origin-receiver-security-check.txt
new file mode 100644
index 00000000000..e0c97ef91d3
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/cross-origin-receiver-security-check.txt
@@ -0,0 +1,17 @@
+same-process frame: true
+Window to URLSearchParams entries: SecurityError, caller realm: true
+Location to URLSearchParams entries: SecurityError, caller realm: true
+Window to URLSearchParams iterator next: SecurityError, caller realm: true
+Location to URLSearchParams iterator next: SecurityError, caller realm: true
+Window to Node textContent getter: SecurityError, caller realm: true
+Location to Node textContent getter: SecurityError, caller realm: true
+Window to Node textContent setter: SecurityError, caller realm: true
+Location to Node textContent setter: SecurityError, caller realm: true
+Window to EventCounts entries: SecurityError, caller realm: true
+Location to EventCounts entries: SecurityError, caller realm: true
+Window to Highlight has: SecurityError, caller realm: true
+Location to Highlight has: SecurityError, caller realm: true
+Window to Blob size getter: SecurityError, caller realm: true
+Location to Blob size getter: SecurityError, caller realm: true
+Window to WebSocket send: SecurityError, caller realm: true
+Location to WebSocket send: SecurityError, caller realm: true
diff --git a/Tests/LibWeb/Text/expected/HTML/cross-origin-rejected-promise-realm.txt b/Tests/LibWeb/Text/expected/HTML/cross-origin-rejected-promise-realm.txt
index 4c89a407b6a..8fa14a431b7 100644
--- a/Tests/LibWeb/Text/expected/HTML/cross-origin-rejected-promise-realm.txt
+++ b/Tests/LibWeb/Text/expected/HTML/cross-origin-rejected-promise-realm.txt
@@ -1,8 +1,8 @@
cross-origin frame: true
same-process frame: true
-Blob.prototype.text: true true
-FontFace.prototype.load: true true
-FontFace.prototype.loaded: true true
-FontFaceSet.prototype.ready: true true
-ReadableStream async iterator next: true true
-ReadableStream async iterator return: true true
+Blob.prototype.text: true, rejected with SecurityError, caller realm: true
+FontFace.prototype.load: true, rejected with SecurityError, caller realm: true
+FontFace.prototype.loaded: true, rejected with SecurityError, caller realm: true
+FontFaceSet.prototype.ready: true, rejected with SecurityError, caller realm: true
+ReadableStream async iterator next: true, rejected with SecurityError, caller realm: true
+ReadableStream async iterator return: true, rejected with SecurityError, caller realm: true
diff --git a/Tests/LibWeb/Text/input/HTML/cross-origin-receiver-security-check.html b/Tests/LibWeb/Text/input/HTML/cross-origin-receiver-security-check.html
new file mode 100644
index 00000000000..4d92b103473
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/cross-origin-receiver-security-check.html
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<script>
+ asyncTest(async done => {
+ const iframe = document.createElement("iframe");
+ iframe.src = "data:text/html,<!DOCTYPE html>";
+ await new Promise(resolve => {
+ iframe.onload = resolve;
+ document.body.append(iframe);
+ });
+ const crossOriginWindow = iframe.contentWindow;
+ println(`same-process frame: ${remoteFrameCount() === 0}`);
+
+ function thrown(f) {
+ try {
+ f();
+ return "no exception";
+ } catch (e) {
+ return `${e.name}, caller realm: ${e instanceof Object}`;
+ }
+ }
+
+ const blobSize = Object.getOwnPropertyDescriptor(Blob.prototype, "size").get;
+ const textContent = Object.getOwnPropertyDescriptor(Node.prototype, "textContent");
+ const iteratorNext = Object.getPrototypeOf(new URLSearchParams().entries()).next;
+ const members = {
+ "URLSearchParams entries": receiver => URLSearchParams.prototype.entries.call(receiver),
+ "URLSearchParams iterator next": receiver => iteratorNext.call(receiver),
+ "Node textContent getter": receiver => textContent.get.call(receiver),
+ "Node textContent setter": receiver => textContent.set.call(receiver, ""),
+ "EventCounts entries": receiver => EventCounts.prototype.entries.call(receiver),
+ "Highlight has": receiver => Highlight.prototype.has.call(receiver, new Range()),
+ "Blob size getter": receiver => blobSize.call(receiver),
+ "WebSocket send": receiver => WebSocket.prototype.send.call(receiver, ""),
+ };
+ for (const [name, member] of Object.entries(members)) {
+ println(`Window to ${name}: ${thrown(() => member(crossOriginWindow))}`);
+ println(`Location to ${name}: ${thrown(() => member(crossOriginWindow.location))}`);
+ }
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/HTML/cross-origin-rejected-promise-realm.html b/Tests/LibWeb/Text/input/HTML/cross-origin-rejected-promise-realm.html
index f499cfd24b0..3d86f004f8d 100644
--- a/Tests/LibWeb/Text/input/HTML/cross-origin-rejected-promise-realm.html
+++ b/Tests/LibWeb/Text/input/HTML/cross-origin-rejected-promise-realm.html
@@ -28,13 +28,13 @@
for (const [name, member] of Object.entries(members)) {
const promise = member.call(crossOriginWindow);
const inCurrentRealm = promise.constructor === Promise && promise.constructor.constructor === Function;
- let rejectedWithTypeError = false;
+ let reason = "fulfilled";
try {
await promise;
} catch (e) {
- rejectedWithTypeError = e instanceof TypeError;
+ reason = `${e.name}, caller realm: ${e instanceof Object}`;
}
- println(`${name}: ${inCurrentRealm} ${rejectedWithTypeError}`);
+ println(`${name}: ${inCurrentRealm}, rejected with ${reason}`);
}
done();
};