From 3363e1a26102eed3083d72aaa7b769de8fd0844e Mon Sep 17 00:00:00 2001 From: shanehandley <1322294+shanehandley@users.noreply.github.com> Date: Mon, 9 Dec 2024 02:28:49 +1100 Subject: [PATCH] Add ReferrerPolicy IDL attribute to iframes (#34526) Signed-off-by: Shane Handley --- components/script/dom/htmliframeelement.rs | 31 ++++++++++++++-- .../dom/webidls/HTMLIFrameElement.webidl | 2 + .../meta/html/dom/idlharness.https.html.ini | 6 --- .../no-referrer/iframe-tag.http.html.ini | 37 ------------------- .../iframe-tag.http.html.ini | 30 --------------- .../req.attr/origin/iframe-tag.http.html.ini | 36 ------------------ .../same-origin/iframe-tag.http.html.ini | 24 ------------ .../iframe-tag.http.html.ini | 30 --------------- .../strict-origin/iframe-tag.http.html.ini | 36 ------------------ .../generic/iframe-src-change.html.ini | 3 -- 10 files changed, 29 insertions(+), 206 deletions(-) delete mode 100644 tests/wpt/meta/referrer-policy/gen/req.attr/no-referrer/iframe-tag.http.html.ini delete mode 100644 tests/wpt/meta/referrer-policy/gen/req.attr/origin-when-cross-origin/iframe-tag.http.html.ini delete mode 100644 tests/wpt/meta/referrer-policy/gen/req.attr/origin/iframe-tag.http.html.ini delete mode 100644 tests/wpt/meta/referrer-policy/gen/req.attr/same-origin/iframe-tag.http.html.ini delete mode 100644 tests/wpt/meta/referrer-policy/gen/req.attr/strict-origin-when-cross-origin/iframe-tag.http.html.ini delete mode 100644 tests/wpt/meta/referrer-policy/gen/req.attr/strict-origin/iframe-tag.http.html.ini delete mode 100644 tests/wpt/meta/referrer-policy/generic/iframe-src-change.html.ini diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index f6d555da1ad..904060df341 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -9,6 +9,7 @@ use bitflags::bitflags; use dom_struct::dom_struct; use html5ever::{local_name, namespace_url, ns, LocalName, Prefix}; use js::rust::HandleObject; +use net_traits::ReferrerPolicy; use profile_traits::ipc as ProfiledIpc; use script_traits::IFrameSandboxState::{IFrameSandboxed, IFrameUnsandboxed}; use script_traits::{ @@ -29,9 +30,11 @@ use crate::dom::bindings::refcounted::Trusted; use crate::dom::bindings::reflector::DomObject; use crate::dom::bindings::root::{DomRoot, LayoutDom, MutNullableDom}; use crate::dom::bindings::str::{DOMString, USVString}; -use crate::dom::document::Document; +use crate::dom::document::{determine_policy_for_token, Document}; use crate::dom::domtokenlist::DOMTokenList; -use crate::dom::element::{AttributeMutation, Element, LayoutElementHelpers}; +use crate::dom::element::{ + reflect_referrer_policy_attribute, AttributeMutation, Element, LayoutElementHelpers, +}; use crate::dom::eventtarget::EventTarget; use crate::dom::globalscope::GlobalScope; use crate::dom::htmlelement::HTMLElement; @@ -300,6 +303,19 @@ impl HTMLIFrameElement { // > `element`. let url = self.get_url(); + // Step 2.4: Let referrerPolicy be the current state of element's referrerpolicy content + // attribute. + let document = document_from_node(self); + let referrer_policy_token = self.ReferrerPolicy(); + + // Note: despite not being explicitly stated in the spec steps, this falls back to + // document's referrer policy here because it satisfies the expectations that when unset, + // the iframe should inherit the referrer policy of its parent + let referrer_policy = match determine_policy_for_token(referrer_policy_token.str()) { + ReferrerPolicy::EmptyString => document.get_referrer_policy(), + policy => policy, + }; + // TODO(#25748): // By spec, we return early if there's an ancestor browsing context // "whose active document's url, ignoring fragments, is equal". @@ -331,13 +347,12 @@ impl HTMLIFrameElement { None }; - let document = document_from_node(self); let load_data = LoadData::new( LoadOrigin::Script(document.origin().immutable().clone()), url, creator_pipeline_id, window.upcast::().get_referrer(), - document.get_referrer_policy(), + referrer_policy, Some(window.upcast::().is_secure_context()), ); @@ -610,6 +625,14 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement { Some(document) } + /// + fn ReferrerPolicy(&self) -> DOMString { + reflect_referrer_policy_attribute(self.upcast::()) + } + + // https://html.spec.whatwg.org/multipage/#attr-iframe-referrerpolicy + make_setter!(SetReferrerPolicy, "referrerpolicy"); + // https://html.spec.whatwg.org/multipage/#attr-iframe-allowfullscreen make_bool_getter!(AllowFullscreen, "allowfullscreen"); // https://html.spec.whatwg.org/multipage/#attr-iframe-allowfullscreen diff --git a/components/script/dom/webidls/HTMLIFrameElement.webidl b/components/script/dom/webidls/HTMLIFrameElement.webidl index 779e56f9ad8..8ba58a20f33 100644 --- a/components/script/dom/webidls/HTMLIFrameElement.webidl +++ b/components/script/dom/webidls/HTMLIFrameElement.webidl @@ -23,6 +23,8 @@ interface HTMLIFrameElement : HTMLElement { attribute boolean allowFullscreen; [CEReactions] attribute DOMString width; + [CEReactions] + attribute DOMString referrerPolicy; [CEReactions] attribute DOMString height; readonly attribute Document? contentDocument; diff --git a/tests/wpt/meta/html/dom/idlharness.https.html.ini b/tests/wpt/meta/html/dom/idlharness.https.html.ini index eedf2e1f139..84e63d5ebe3 100644 --- a/tests/wpt/meta/html/dom/idlharness.https.html.ini +++ b/tests/wpt/meta/html/dom/idlharness.https.html.ini @@ -6415,9 +6415,6 @@ [HTMLIFrameElement interface: attribute allow] expected: FAIL - [HTMLIFrameElement interface: attribute referrerPolicy] - expected: FAIL - [HTMLIFrameElement interface: attribute loading] expected: FAIL @@ -6445,9 +6442,6 @@ [HTMLIFrameElement interface: document.createElement("iframe") must inherit property "allow" with the proper type] expected: FAIL - [HTMLIFrameElement interface: document.createElement("iframe") must inherit property "referrerPolicy" with the proper type] - expected: FAIL - [HTMLIFrameElement interface: document.createElement("iframe") must inherit property "loading" with the proper type] expected: FAIL diff --git a/tests/wpt/meta/referrer-policy/gen/req.attr/no-referrer/iframe-tag.http.html.ini b/tests/wpt/meta/referrer-policy/gen/req.attr/no-referrer/iframe-tag.http.html.ini deleted file mode 100644 index 7408079db11..00000000000 --- a/tests/wpt/meta/referrer-policy/gen/req.attr/no-referrer/iframe-tag.http.html.ini +++ /dev/null @@ -1,37 +0,0 @@ -[iframe-tag.http.html] - [Referrer Policy: Expects omitted for iframe-tag to same-https origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to cross-http origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to same-http origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to same-https origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to cross-http origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to cross-http origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to same-http origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to cross-https origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to cross-https origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to same-https origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to cross-https origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to same-http origin and no-redirect redirection from http context.] - expected: FAIL - diff --git a/tests/wpt/meta/referrer-policy/gen/req.attr/origin-when-cross-origin/iframe-tag.http.html.ini b/tests/wpt/meta/referrer-policy/gen/req.attr/origin-when-cross-origin/iframe-tag.http.html.ini deleted file mode 100644 index 8c461943293..00000000000 --- a/tests/wpt/meta/referrer-policy/gen/req.attr/origin-when-cross-origin/iframe-tag.http.html.ini +++ /dev/null @@ -1,30 +0,0 @@ -[iframe-tag.http.html] - [Referrer Policy: Expects origin for iframe-tag to cross-http origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-http origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-http origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-https origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-https origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-https origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-http origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-https origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-https origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-https origin and swap-origin redirection from http context.] - expected: FAIL diff --git a/tests/wpt/meta/referrer-policy/gen/req.attr/origin/iframe-tag.http.html.ini b/tests/wpt/meta/referrer-policy/gen/req.attr/origin/iframe-tag.http.html.ini deleted file mode 100644 index c9fb6af9170..00000000000 --- a/tests/wpt/meta/referrer-policy/gen/req.attr/origin/iframe-tag.http.html.ini +++ /dev/null @@ -1,36 +0,0 @@ -[iframe-tag.http.html] - [Referrer Policy: Expects origin for iframe-tag to cross-http origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-http origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-http origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-https origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-https origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-https origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-http origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-http origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-http origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-https origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-https origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-https origin and swap-origin redirection from http context.] - expected: FAIL diff --git a/tests/wpt/meta/referrer-policy/gen/req.attr/same-origin/iframe-tag.http.html.ini b/tests/wpt/meta/referrer-policy/gen/req.attr/same-origin/iframe-tag.http.html.ini deleted file mode 100644 index da98c96c506..00000000000 --- a/tests/wpt/meta/referrer-policy/gen/req.attr/same-origin/iframe-tag.http.html.ini +++ /dev/null @@ -1,24 +0,0 @@ -[iframe-tag.http.html] - [Referrer Policy: Expects omitted for iframe-tag to cross-http origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to cross-http origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to cross-http origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to cross-https origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to cross-https origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to cross-https origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to same-http origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects omitted for iframe-tag to same-https origin and swap-origin redirection from http context.] - expected: FAIL diff --git a/tests/wpt/meta/referrer-policy/gen/req.attr/strict-origin-when-cross-origin/iframe-tag.http.html.ini b/tests/wpt/meta/referrer-policy/gen/req.attr/strict-origin-when-cross-origin/iframe-tag.http.html.ini deleted file mode 100644 index 8c461943293..00000000000 --- a/tests/wpt/meta/referrer-policy/gen/req.attr/strict-origin-when-cross-origin/iframe-tag.http.html.ini +++ /dev/null @@ -1,30 +0,0 @@ -[iframe-tag.http.html] - [Referrer Policy: Expects origin for iframe-tag to cross-http origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-http origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-http origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-https origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-https origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-https origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-http origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-https origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-https origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-https origin and swap-origin redirection from http context.] - expected: FAIL diff --git a/tests/wpt/meta/referrer-policy/gen/req.attr/strict-origin/iframe-tag.http.html.ini b/tests/wpt/meta/referrer-policy/gen/req.attr/strict-origin/iframe-tag.http.html.ini deleted file mode 100644 index c9fb6af9170..00000000000 --- a/tests/wpt/meta/referrer-policy/gen/req.attr/strict-origin/iframe-tag.http.html.ini +++ /dev/null @@ -1,36 +0,0 @@ -[iframe-tag.http.html] - [Referrer Policy: Expects origin for iframe-tag to cross-http origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-http origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-http origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-https origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-https origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to cross-https origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-http origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-http origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-http origin and swap-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-https origin and keep-origin redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-https origin and no-redirect redirection from http context.] - expected: FAIL - - [Referrer Policy: Expects origin for iframe-tag to same-https origin and swap-origin redirection from http context.] - expected: FAIL diff --git a/tests/wpt/meta/referrer-policy/generic/iframe-src-change.html.ini b/tests/wpt/meta/referrer-policy/generic/iframe-src-change.html.ini deleted file mode 100644 index 5734643c54f..00000000000 --- a/tests/wpt/meta/referrer-policy/generic/iframe-src-change.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[iframe-src-change.html] - [Checks that referrerpolicy is respected when an iframe's src changes.] - expected: FAIL