Implement referrer policy for dom worker construction (#34192)

Signed-off-by: Shane Handley <shanehandley@fastmail.com>
This commit is contained in:
shanehandley 2024-11-09 12:16:35 +11:00 committed by GitHub
parent 6c1cd56e52
commit da462d0fcd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
60 changed files with 25 additions and 381 deletions

View file

@ -50,7 +50,7 @@ use net_traits::request::{Referrer, RequestBuilder};
use net_traits::response::HttpsState;
use net_traits::{
fetch_async, CoreResourceMsg, CoreResourceThread, FetchResponseListener, IpcSend,
ResourceThreads,
ReferrerPolicy, ResourceThreads,
};
use profile_traits::{ipc as profile_ipc, mem as profile_mem, time as profile_time};
use script_traits::serializable::{BlobData, BlobImpl, FileBlob};
@ -2418,6 +2418,21 @@ impl GlobalScope {
unreachable!();
}
/// Get the Referrer Policy for this global scope.
pub fn get_referrer_policy(&self) -> Option<ReferrerPolicy> {
if let Some(window) = self.downcast::<Window>() {
let document = window.Document();
return document.get_referrer_policy();
}
if let Some(worker) = self.downcast::<WorkerGlobalScope>() {
let policy_container = worker.policy_container().to_owned();
return Some(policy_container.referrer_policy);
}
unreachable!();
}
/// Determine the Referrer for a request whose Referrer is "client"
pub fn get_referrer(&self) -> Referrer {
// Step 3 of https://w3c.github.io/webappsec-referrer-policy/#determine-requests-referrer

View file

@ -118,7 +118,7 @@ impl ServiceWorkerRegistration {
Referrer::ReferrerUrl(url) => Some(url),
_ => None,
},
referrer_policy: Some(global.policy_container().referrer_policy),
referrer_policy: global.get_referrer_policy(),
pipeline_id: global.pipeline_id(),
};

View file

@ -13,6 +13,7 @@ use ipc_channel::ipc;
use js::jsapi::{Heap, JSObject};
use js::jsval::UndefinedValue;
use js::rust::{CustomAutoRooter, CustomAutoRooterGuard, HandleObject, HandleValue};
use net_traits::request::Referrer;
use script_traits::{StructuredSerializedData, WorkerScriptLoadOrigin};
use uuid::Uuid;
@ -178,8 +179,12 @@ impl WorkerMethods for Worker {
let worker_ref = Trusted::new(&*worker);
let worker_load_origin = WorkerScriptLoadOrigin {
referrer_url: None,
referrer_policy: None,
referrer_url: match global.get_referrer() {
Referrer::Client(url) => Some(url),
Referrer::ReferrerUrl(url) => Some(url),
_ => None,
},
referrer_policy: global.get_referrer_policy(),
pipeline_id: global.pipeline_id(),
};

View file

@ -174,14 +174,6 @@ pub struct XMLHttpRequest {
impl XMLHttpRequest {
fn new_inherited(global: &GlobalScope) -> XMLHttpRequest {
//TODO - update this when referrer policy implemented for workers
let referrer_policy = if let Some(window) = global.downcast::<Window>() {
let document = window.Document();
document.get_referrer_policy()
} else {
None
};
XMLHttpRequest {
eventtarget: XMLHttpRequestEventTarget::new_inherited(),
ready_state: Cell::new(XMLHttpRequestState::Unsent),
@ -213,7 +205,7 @@ impl XMLHttpRequest {
generation_id: Cell::new(GenerationId(0)),
response_status: Cell::new(Ok(())),
referrer: global.get_referrer(),
referrer_policy,
referrer_policy: global.get_referrer_policy(),
canceller: DomRefCell::new(Default::default()),
}
}

View file

@ -1,7 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects omitted for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects omitted for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects origin for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects origin for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects origin for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects origin for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects omitted for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects omitted for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects omitted for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects omitted for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects origin for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects origin for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects origin for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects origin for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects omitted for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects omitted for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects origin for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects origin for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects origin for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects origin for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects omitted for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects omitted for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects omitted for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects omitted for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects origin for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects origin for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects origin for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects origin for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects omitted for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects omitted for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects origin for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects origin for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects origin for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects origin for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects omitted for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects omitted for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects omitted for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects omitted for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects origin for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects origin for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects origin for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects origin for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects omitted for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects omitted for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects origin for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects origin for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects origin for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects origin for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects omitted for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,7 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects omitted for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects omitted for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects omitted for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects omitted for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects origin for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects origin for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-classic.http.html]
[Referrer Policy: Expects origin for worker-classic to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-classic to same-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,6 +0,0 @@
[worker-module.http.html]
[Referrer Policy: Expects origin for worker-module to same-http origin and keep-origin redirection from http context.]
expected: FAIL
[Referrer Policy: Expects origin for worker-module to same-http origin and no-redirect redirection from http context.]
expected: FAIL