The design language that makes your AI harness better at design.
JavaScript
Consent wall probe reads controls, media and frames in shadow roots
Paul Bakaus34652290d650
diff --git a/crates/browser/src/consent.rs b/crates/browser/src/consent.rsindex c316e631d..2abb57560 100644--- a/crates/browser/src/consent.rs+++ b/crates/browser/src/consent.rs@@ -286,7 +286,13 @@ pub fn probe_fragment() -> String {// at all; one inside it is, all but its shadow-root text.const inBody = !!document.body && document.body.contains(el);consentShadowChars += inBody ? Math.max(0, all - (el.innerText || '').replace(/\s+/g, ' ').trim().length) : all;- for (const f of el.querySelectorAll('iframe')) {{+ // A manager that draws its message in a frame inside its own shadow+ // root holds that frame out of `querySelectorAll`'s reach.+ const frames = [...el.querySelectorAll('iframe')];+ for (const n of [el, ...el.querySelectorAll('*')]) {{+ if (n.shadowRoot) frames.push(...n.shadowRoot.querySelectorAll('iframe'));+ }}+ for (const f of frames) {{if (!boxShows(f)) continue;const r = f.getBoundingClientRect();if (r.width * r.height >= {media_px}) consentFrames++;@@ -310,21 +316,32 @@ pub fn probe_fragment() -> String {}} catch (e) {{}}return n;}};+ // The page's open shadow roots, outside the managers: their form+ // controls and media are the page's as much as their text is.+ const pageShadows = [];if (consentRoots.length && document.body) {{const hosts = document.body.querySelectorAll('*');for (let i = 0; i < hosts.length && i < 30000; i++) {{const host = hosts[i];if (!host.shadowRoot || consentRoots.some(r => r.contains(host))) continue;+ pageShadows.push(host.shadowRoot);for (const child of host.shadowRoot.children) consentPageShadowChars += shadowText(child);}}}}if (consentRoots.length) {{const inside = el => consentRoots.some(r => r.contains(el));- for (const el of q({controls})) {{+ const all = sel => {{+ const out = q(sel);+ for (const root of pageShadows) {{+ try {{ out.push(...root.querySelectorAll(sel)); }} catch (e) {{}}+ }}+ return out;+ }};+ for (const el of all({controls})) {{if (consentOutside >= 20) break;if (!inside(el) && boxShows(el)) consentOutside++;}}- for (const el of q({media})) {{+ for (const el of all({media})) {{if (consentOutside >= 20) break;if (inside(el) || !boxShows(el)) continue;const r = el.getBoundingClientRect();diff --git a/crates/browser/tests/consent_hiding.rs b/crates/browser/tests/consent_hiding.rsindex 2cc07c560..9fb51e4db 100644--- a/crates/browser/tests/consent_hiding.rs+++ b/crates/browser/tests/consent_hiding.rs@@ -378,3 +378,22 @@ fn a_wall_under_a_visibility_hidden_root_is_refused() {let err = engine.detect_url(&url, &ScanOptions::default()).expect_err("a visible dialog under a hidden root is a wall");assert!(err.message.starts_with("the page is a consent wall, not the site (consent manager OneTrust, "), "{}", err.message);}++#[test]+fn a_web_component_form_under_a_banner_is_scanned() {+ let Some(engine) = engine() else { return };+ let port = serve();+ let url = format!("http://127.0.0.1:{port}/shadow-form-page.html");+ engine+ .detect_url_scan(&url, &ScanOptions::default())+ .expect("a form in the page's own shadow root is the page");+}++#[test]+fn a_frame_in_the_managers_shadow_root_is_a_wall() {+ let Some(engine) = engine() else { return };+ let port = serve();+ let url = format!("http://127.0.0.1:{port}/shadow-frame-wall.html");+ let err = engine.detect_url(&url, &ScanOptions::default()).expect_err("a framed consent wall must not scan");+ assert!(err.message.starts_with("the page is a consent wall, not the site (consent manager Sourcepoint, "), "{}", err.message);+}diff --git a/tests/fixtures/consent/shadow-form-page.html b/tests/fixtures/consent/shadow-form-page.htmlnew file mode 100644index 000000000..1cf00a613--- /dev/null+++ b/tests/fixtures/consent/shadow-form-page.html@@ -0,0 +1,30 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Consent hiding: a web-component sign-in form under a banner</title>+ <style>+ /* A sign-in page whose form lives in an open shadow root, under a+ light-DOM OneTrust dialog that holds nearly all of the page's text.+ The form is the page's content outside the manager, so the page is+ scanned, not refused as a consent wall. Pinned by+ crates/browser/tests/consent_hiding.rs. */+ body { font: 16px/1.5 system-ui, sans-serif; margin: 0; background: #fff; }+ #onetrust-pc-sdk { position: fixed; top: 80px; left: 50%; width: 640px; margin-left: -320px; padding: 32px; background: #fff; }+ </style>+</head>+<body>+ <x-login></x-login>+ <div id="onetrust-consent-sdk">+ <div id="onetrust-pc-sdk" role="dialog" aria-label="Privacy preferences">+ <h2>Your privacy choices</h2>+ <p>We and our partners store and access information on your device, such as cookies, and process personal data such as unique identifiers and browsing data, to personalise content and advertising and to measure its performance.</p>+ </div>+ </div>+ <script>+ const root = document.querySelector('x-login').attachShadow({ mode: 'open' });+ root.innerHTML = '<form style="display:block;padding:24px"><label>Email <input type="email" name="email"></label> <button type="submit">Sign in</button></form>';+ </script>+</body>+</html>diff --git a/tests/fixtures/consent/shadow-frame-wall.html b/tests/fixtures/consent/shadow-frame-wall.htmlnew file mode 100644index 000000000..801ef6a84--- /dev/null+++ b/tests/fixtures/consent/shadow-frame-wall.html@@ -0,0 +1,23 @@+<!DOCTYPE html>+<html lang="en">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <title>Consent hiding: a framed message inside the manager's shadow root</title>+ <style>+ /* A page that is only a Sourcepoint-shaped message, drawn in an iframe+ that sits in the manager container's own shadow root. The frame is+ still the manager's content, so the page is refused as a consent wall.+ Pinned by crates/browser/tests/consent_hiding.rs. */+ body { font: 16px/1.5 system-ui, sans-serif; margin: 0; background: #f3f4f6; }+ #sp_message_container_1234 { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }+ </style>+</head>+<body>+ <div id="sp_message_container_1234"></div>+ <script>+ const root = document.getElementById('sp_message_container_1234').attachShadow({ mode: 'open' });+ root.innerHTML = '<iframe title="Privacy message" style="width:640px;height:400px;border:0;background:#fff" srcdoc="<p>We and our partners use cookies to personalise content and ads.</p><button>Accept</button>"></iframe>';+ </script>+</body>+</html>