Skip to content

armgit / moli

Public Imported from GitHub
0

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

feat(credentials): expose the secure CredentialsContainer interface

ldm0631d4704ca90
diff --git a/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/metadata.rs b/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/metadata.rs
index 9d11c5264..a8598c8f2 100644
--- a/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/metadata.rs
+++ b/moli-renderer-v8/src/context_bootstrap/exposed_interfaces/metadata.rs
@@ -108,6 +108,7 @@ const SECURE_CONTEXT_ONLY_INTERFACE_NAMES: &[&str] = &[
"AuthenticatorResponse",
"PublicKeyCredential",
"Credential",
+ "CredentialsContainer",
"MIDIPort",
"MIDIAccess",
"MIDIInput",
diff --git a/moli-renderer-v8/src/context_bootstrap/specs/registry.rs b/moli-renderer-v8/src/context_bootstrap/specs/registry.rs
index 1b47f41b2..e3ff77e95 100644
--- a/moli-renderer-v8/src/context_bootstrap/specs/registry.rs
+++ b/moli-renderer-v8/src/context_bootstrap/specs/registry.rs
@@ -24,6 +24,10 @@ const CONSTRUCTOR_SPECS_BEFORE_STREAMS: &[ConstructorSpec] = &[
interface: web_api_interfaces::Credential::DESCRIPTOR,
kind: ConstructorKind::Illegal,
},
+ ConstructorSpec {
+ interface: web_api_interfaces::CredentialsContainer::DESCRIPTOR,
+ kind: ConstructorKind::Illegal,
+ },
ConstructorSpec {
interface: web_api_interfaces::ModelContext::DESCRIPTOR,
kind: ConstructorKind::Illegal,
diff --git a/moli-renderer-v8/src/script_vm/tests/credential_interface_exposure_interfaces.rs b/moli-renderer-v8/src/script_vm/tests/credential_interface_exposure_interfaces.rs
new file mode 100644
index 000000000..3ba2017e1
--- /dev/null
+++ b/moli-renderer-v8/src/script_vm/tests/credential_interface_exposure_interfaces.rs
@@ -0,0 +1,43 @@
+use super::*;
+
+#[test]
+fn credential_interface_exposure_interfaces_have_realm_local_constructors_and_exposure() {
+ for url in [
+ "https://interface-exposure.test/",
+ "http://interface-exposure.test/",
+ ] {
+ let mut vm = new_storage_test_vm(url);
+ assert_eq!(vm.eval(r#"
+(() => {
+ const assert = (ok, message) => { if (!ok) throw Error(message); };
+ const names = ["AuthenticatorAssertionResponse", "AuthenticatorAttestationResponse", "AuthenticatorResponse", "PublicKeyCredential", "Credential", "CredentialsContainer"];
+ const parents = {"AuthenticatorAssertionResponse": "AuthenticatorResponse", "AuthenticatorAttestationResponse": "AuthenticatorResponse", "AuthenticatorResponse": null, "PublicKeyCredential": "Credential", "Credential": null, "CredentialsContainer": null};
+ if (!document.documentElement) document.appendChild(document.createElement('html'));
+ if (!document.body) document.documentElement.appendChild(document.createElement('body'));
+ const child = document.createElement('iframe');
+ document.body.appendChild(child);
+ const other = child.contentWindow;
+ for (const realm of [window, other]) {
+ for (const name of names) {
+ if (!isSecureContext) {
+ assert(!(name in realm), name + ' unavailable outside secure contexts');
+ continue;
+ }
+ const C = realm[name];
+ assert(typeof C === 'function' && C.name === name && C.length === 0, name + ' constructor');
+ assert(C.prototype.constructor === C, name + ' prototype identity');
+ assert(Object.getPrototypeOf(C.prototype) === (parents[name] ? realm[parents[name]].prototype : realm.Object.prototype), name + ' prototype inheritance');
+ assert(realm[name] === C, name + ' stable lazy materialization');
+ for (const invoke of [() => C(), () => new C(), () => Reflect.construct(C, [], function Subclass() {})]) {
+ let error;
+ try { invoke(); } catch (caught) { error = caught; }
+ assert(error instanceof realm.TypeError, name + ' rejects construction in callee realm');
+ }
+ assert(C !== (realm === window ? other[name] : window[name]), name + ' distinct realm constructors');
+ }
+ }
+ return 'passed';
+})()
+"#).unwrap(), "passed", "{url}");
+ }
+}
diff --git a/moli-renderer-v8/src/script_vm/tests/mod.rs b/moli-renderer-v8/src/script_vm/tests/mod.rs
index 00e4e198f..2c69d62fb 100644
--- a/moli-renderer-v8/src/script_vm/tests/mod.rs
+++ b/moli-renderer-v8/src/script_vm/tests/mod.rs
@@ -2141,6 +2141,7 @@ mod canvas_paths;
mod canvas_transform_snapshots;
mod canvas_webgl;
mod child_dynamic_inline_scripts;
+mod credential_interface_exposure_interfaces;
mod credential_interfaces;
mod device_events;
diff --git a/moli-renderer-v8/src/web_api_interfaces.rs b/moli-renderer-v8/src/web_api_interfaces.rs
index a00bdc13c..dfcccc729 100644
--- a/moli-renderer-v8/src/web_api_interfaces.rs
+++ b/moli-renderer-v8/src/web_api_interfaces.rs
@@ -25,6 +25,7 @@ interfaces! {
AuthenticatorResponse;
PublicKeyCredential: Credential;
Credential;
+ CredentialsContainer;
AbortController;
AbortSignal: EventTarget;
AbstractRange;