From 0a499ef779b92a4f28e21d1410f70e56979a7403 Mon Sep 17 00:00:00 2001 From: Liam Brady Date: Tue, 7 Jan 2025 13:02:30 -0800 Subject: [PATCH] Allow setting automatic beacon data from cross-origin subframes. Cross-origin fenced frames/URN iframes can send automatic reporting beacons, but currently require data included in these beacons to be pre-registered via an API call accessible only to a document that is same-origin to the fenced frame config's mapped URL. This poses a problem for cross-origin subframes within the same entity (e.g., an ad frame and a payment subframe from the same company) that need to include dynamic data, like click information, in the beacon. The current workaround involves cumbersome postMessage communication and introduces potential timing issues, highlighting the need for a more practical solution for cross-origin subframes to set their own beacon data. This CL relaxes that restriction and lets cross-origin documents set automatic beacon data as well as use it. This is subject to the same kinds of opt ins as other cross-origin FFAR features. Namely, the root frame must opt in via the "Allow-Fenced-Frame-Automatic-Beacons" header, and the cross-origin subframe setting the data must opt in via the 'crossOriginExposed' parameter in the call to setReportEvent...(). See: https://github.com/WICG/fenced-frame/issues/185 Change-Id: Iea922e737fa870f2edf0c24aa81927535f779d8b Bug: 382500834 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6074470 Reviewed-by: Andrew Verge Reviewed-by: Dominic Farolino Commit-Queue: Liam Brady Reviewed-by: Arthur Sonzogni Cr-Commit-Position: refs/heads/main@{#1403202} --- ...-data-cross-origin-ancestor.sub.https.html | 53 ++++++++++++++++ ...acon-data-cross-origin-subframe.https.html | 26 +++++--- ...-beacon-data-multiple-ancestors.https.html | 62 +++++++++++++++++++ ...atic-beacon-data-set-by-sibling.https.html | 59 ++++++++++++++++++ .../resources/automatic-beacon-helper.js | 3 +- 5 files changed, 191 insertions(+), 12 deletions(-) create mode 100644 fenced-frame/automatic-beacon-data-cross-origin-ancestor.sub.https.html create mode 100644 fenced-frame/automatic-beacon-data-multiple-ancestors.https.html create mode 100644 fenced-frame/automatic-beacon-data-set-by-sibling.https.html diff --git a/fenced-frame/automatic-beacon-data-cross-origin-ancestor.sub.https.html b/fenced-frame/automatic-beacon-data-cross-origin-ancestor.sub.https.html new file mode 100644 index 00000000000000..e66d2adddb01a8 --- /dev/null +++ b/fenced-frame/automatic-beacon-data-cross-origin-ancestor.sub.https.html @@ -0,0 +1,53 @@ + +Test window.fence.setReportEventDataForAutomaticBeacons + + + + + + + + + + + + + + diff --git a/fenced-frame/automatic-beacon-data-cross-origin-subframe.https.html b/fenced-frame/automatic-beacon-data-cross-origin-subframe.https.html index d97bf370dc9a76..2082de1b784fa0 100644 --- a/fenced-frame/automatic-beacon-data-cross-origin-subframe.https.html +++ b/fenced-frame/automatic-beacon-data-cross-origin-subframe.https.html @@ -30,22 +30,28 @@ origin: get_host_info().HTTPS_REMOTE_ORIGIN, headers: [['Allow-Fenced-Frame-Automatic-Beacons', 'true']] }); - return setupAutomaticBeacon(iframe, [beacon], - "resources/close.html", NavigationTrigger.Click, + await setupAutomaticBeacon(iframe, [beacon], + "resources/close.html", NavigationTrigger.ClickOnce, "_blank"); + return iframe.execute(() => { + // Test that automatic beacon data is set correctly in the subframe. Data + // that is not cross-origin exposed should not be able to be set in a + // cross-origin subframe, even if the same frame that sets the data + // triggers the report. + window.fence.setReportEventDataForAutomaticBeacons({ + eventType: "reserved.top_navigation_start", + eventData: "This should not be the data", + destination: ["buyer"], + crossOriginExposed: false + }); + }); }, [beacon]); await multiClick(10, 10, fencedframe.element) - // An automatic beacon should be sent, but no data should be attached to it, - // as it shouldn't have been able to be set from a cross-origin subframe. - await verifyBeaconData(beacon.eventType, "", + await verifyBeaconData(beacon.eventType, beacon.eventData, get_host_info().HTTPS_REMOTE_ORIGIN); - - // Leaving this fenced frame around for subsequent tests can lead to - // flakiness. - document.body.removeChild(fencedframe.element); -}, 'A cross origin subframe cannot set automatic beacon data.'); +}, 'A cross origin subframe can set automatic beacon data.'); diff --git a/fenced-frame/automatic-beacon-data-multiple-ancestors.https.html b/fenced-frame/automatic-beacon-data-multiple-ancestors.https.html new file mode 100644 index 00000000000000..5fd85805bbc527 --- /dev/null +++ b/fenced-frame/automatic-beacon-data-multiple-ancestors.https.html @@ -0,0 +1,62 @@ + +Test window.fence.setReportEventDataForAutomaticBeacons + + + + + + + + + + + + + + diff --git a/fenced-frame/automatic-beacon-data-set-by-sibling.https.html b/fenced-frame/automatic-beacon-data-set-by-sibling.https.html new file mode 100644 index 00000000000000..94e35577c9f4e5 --- /dev/null +++ b/fenced-frame/automatic-beacon-data-set-by-sibling.https.html @@ -0,0 +1,59 @@ + +Test window.fence.setReportEventDataForAutomaticBeacons + + + + + + + + + + + + + + diff --git a/fenced-frame/resources/automatic-beacon-helper.js b/fenced-frame/resources/automatic-beacon-helper.js index 36c10c904edf84..9b343db826e8a9 100644 --- a/fenced-frame/resources/automatic-beacon-helper.js +++ b/fenced-frame/resources/automatic-beacon-helper.js @@ -60,8 +60,7 @@ async function setupAutomaticBeacon( window.fence.setReportEventDataForAutomaticBeacons(beacon_event); }); // Add a cross-origin iframe that will perform the top-level - // navigation. Do not set the 'Allow-Fenced-Frame-Automatic-Beacons' - // header to true. + // navigation. const iframe = await attachIFrameContext({ origin: get_host_info().HTTPS_REMOTE_ORIGIN, headers: [[