Skip to content

Commit

Permalink
Make url for "client" referrer mandatory
Browse files Browse the repository at this point in the history
  • Loading branch information
MDeiml committed Jun 17, 2020
1 parent 37394a8 commit fa18cf6
Show file tree
Hide file tree
Showing 38 changed files with 410 additions and 213 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions components/constellation/constellation.rs
Expand Up @@ -136,7 +136,7 @@ use msg::constellation_msg::{
TopLevelBrowsingContextId,
};
use net_traits::pub_domains::reg_host;
use net_traits::request::RequestBuilder;
use net_traits::request::{Referrer, RequestBuilder};
use net_traits::storage_thread::{StorageThreadMsg, StorageType};
use net_traits::{self, FetchResponseMsg, IpcSend, ResourceThreads};
use profile_traits::mem;
Expand Down Expand Up @@ -1544,7 +1544,13 @@ where
// If there is already a pending page (self.pending_changes), it will not be overridden;
// However, if the id is not encompassed by another change, it will be.
FromCompositorMsg::LoadUrl(top_level_browsing_context_id, url) => {
let load_data = LoadData::new(LoadOrigin::Constellation, url, None, None, None);
let load_data = LoadData::new(
LoadOrigin::Constellation,
url,
None,
Referrer::NoReferrer,
None,
);
let ctx_id = BrowsingContextId::from(top_level_browsing_context_id);
let pipeline_id = match self.browsing_contexts.get(&ctx_id) {
Some(ctx) => ctx.pipeline_id,
Expand Down Expand Up @@ -2888,7 +2894,13 @@ where
warn!("creating replacement pipeline for about:failure");

let new_pipeline_id = PipelineId::new();
let load_data = LoadData::new(LoadOrigin::Constellation, failure_url, None, None, None);
let load_data = LoadData::new(
LoadOrigin::Constellation,
failure_url,
None,
Referrer::NoReferrer,
None,
);
let sandbox = IFrameSandboxState::IFrameSandboxed;
let is_private = false;
self.new_pipeline(
Expand Down Expand Up @@ -2998,7 +3010,13 @@ where
);
self.embedder_proxy.send(msg);
let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id);
let load_data = LoadData::new(LoadOrigin::Constellation, url, None, None, None);
let load_data = LoadData::new(
LoadOrigin::Constellation,
url,
None,
Referrer::NoReferrer,
None,
);
let sandbox = IFrameSandboxState::IFrameUnsandboxed;
let is_private = false;
let is_visible = true;
Expand Down
3 changes: 2 additions & 1 deletion components/constellation/network_listener.rs
Expand Up @@ -116,7 +116,8 @@ impl NetworkListener {
self.request_builder.referrer = metadata
.referrer
.clone()
.map(|referrer_url| Referrer::ReferrerUrl(referrer_url));
.map(|referrer_url| Referrer::ReferrerUrl(referrer_url))
.unwrap_or(Referrer::NoReferrer);
self.request_builder.referrer_policy = metadata.referrer_policy;

let headers = if let Some(ref headers) = metadata.headers {
Expand Down
7 changes: 5 additions & 2 deletions components/gfx/font_cache_thread.rs
Expand Up @@ -14,7 +14,7 @@ use crate::platform::font_template::FontTemplateData;
use app_units::Au;
use gfx_traits::{FontData, WebrenderApi};
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use net_traits::request::{Destination, RequestBuilder};
use net_traits::request::{Destination, Referrer, RequestBuilder};
use net_traits::{fetch_async, CoreResourceThread, FetchResponseMsg};
use servo_atoms::Atom;
use servo_url::ServoUrl;
Expand Down Expand Up @@ -235,7 +235,10 @@ impl FontCache {
None => return,
};

let request = RequestBuilder::new(url.clone()).destination(Destination::Font);
// FIXME:
// This shouldn't use NoReferrer, but the current documents url
let request = RequestBuilder::new(url.clone(), Referrer::NoReferrer)
.destination(Destination::Font);

let channel_to_self = self.channel_to_self.clone();
let bytes = Mutex::new(Vec::new());
Expand Down
8 changes: 1 addition & 7 deletions components/net/fetch/methods.rs
Expand Up @@ -239,13 +239,7 @@ pub fn main_fetch(
{
let referrer_url = match mem::replace(&mut request.referrer, Referrer::NoReferrer) {
Referrer::NoReferrer => None,
Referrer::Client => {
// FIXME(#14507): We should never get this value here; it should
// already have been handled in the script thread.
request.headers.remove(header::REFERER);
None
},
Referrer::ReferrerUrl(url) => {
Referrer::ReferrerUrl(url) | Referrer::Client(url) => {
request.headers.remove(header::REFERER);
let current_url = request.current_url();
determine_request_referrer(
Expand Down
12 changes: 3 additions & 9 deletions components/net/http_loader.rs
Expand Up @@ -1141,7 +1141,8 @@ fn http_network_or_cache_fetch(
// Step 5.9
match http_request.referrer {
Referrer::NoReferrer => (),
Referrer::ReferrerUrl(ref http_request_referrer) => {
Referrer::ReferrerUrl(ref http_request_referrer) |
Referrer::Client(ref http_request_referrer) => {
if let Ok(referer) = http_request_referrer.to_string().parse::<Referer>() {
http_request.headers.typed_insert(referer);
} else {
Expand All @@ -1151,12 +1152,6 @@ fn http_network_or_cache_fetch(
error!("Failed to parse {} as referer", http_request_referrer);
}
},
Referrer::Client =>
// it should be impossible for referrer to be anything else during fetching
// https://fetch.spec.whatwg.org/#concept-request-referrer
{
unreachable!()
},
};

// Step 5.10
Expand Down Expand Up @@ -1938,7 +1933,7 @@ fn cors_preflight_fetch(
context: &FetchContext,
) -> Response {
// Step 1
let mut preflight = RequestBuilder::new(request.current_url())
let mut preflight = RequestBuilder::new(request.current_url(), request.referrer.clone())
.method(Method::OPTIONS)
.origin(match &request.origin {
Origin::Client => {
Expand All @@ -1949,7 +1944,6 @@ fn cors_preflight_fetch(
.pipeline_id(request.pipeline_id)
.initiator(request.initiator.clone())
.destination(request.destination.clone())
.referrer(Some(request.referrer.clone()))
.referrer_policy(request.referrer_policy)
.build();

Expand Down
10 changes: 8 additions & 2 deletions components/net/tests/data_loader.rs
Expand Up @@ -6,7 +6,7 @@ use crate::fetch;
use headers::{ContentType, HeaderMapExt};
use hyper_serde::Serde;
use mime::{self, Mime};
use net_traits::request::{Origin, Request};
use net_traits::request::{Origin, Referrer, Request};
use net_traits::response::{HttpsState, ResponseBody};
use net_traits::{FetchMetadata, FilteredMetadata, NetworkError};
use servo_url::ServoUrl;
Expand All @@ -21,7 +21,13 @@ fn assert_parse(
) {
let url = ServoUrl::parse(url).unwrap();
let origin = Origin::Origin(url.origin());
let mut request = Request::new(url, Some(origin), None, HttpsState::None);
let mut request = Request::new(
url,
Some(origin),
Referrer::NoReferrer,
None,
HttpsState::None,
);

let response = fetch(&mut request, None);

Expand Down

0 comments on commit fa18cf6

Please sign in to comment.