Skip to content

Commit

Permalink
WIP: Fix referrer handling of redirected navigations (fixes brave/bra…
Browse files Browse the repository at this point in the history
…ve-browser#7933)

This appears to be in the wrong hook. It's not clear it's even
needed.
  • Loading branch information
fmarier committed Sep 19, 2020
1 parent 0a6800d commit aae6562
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion browser/brave_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ void BraveContentBrowserClient::MaybeHideReferrer(
content::Referrer new_referrer;
if (brave_shields::MaybeChangeReferrer(
allow_referrers, shields_up, (*referrer)->url, document_url, request_url,
policy,
GURL() /* redirect_source */, policy, // TODO: pass the right redirect_source
&new_referrer)) {
(*referrer)->url = new_referrer.url;
(*referrer)->policy = new_referrer.policy;
Expand Down
1 change: 1 addition & 0 deletions browser/net/brave_site_hacks_network_delegate_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ bool ApplyPotentialReferrerBlock(std::shared_ptr<BraveRequestInfo> ctx) {
if (brave_shields::MaybeChangeReferrer(
ctx->allow_referrers, ctx->allow_brave_shields, GURL(ctx->referrer),
ctx->tab_origin, ctx->request_url,
ctx->internal_redirect ? GURL() : ctx->redirect_source,
blink::ReferrerUtils::NetToMojoReferrerPolicy(ctx->referrer_policy),
&new_referrer)) {
ctx->new_referrer = new_referrer.url;
Expand Down
6 changes: 6 additions & 0 deletions components/brave_shields/browser/brave_shields_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ bool MaybeChangeReferrer(
const GURL& current_referrer,
const GURL& tab_origin,
const GURL& target_url,
const GURL& redirect_source,
network::mojom::ReferrerPolicy policy,
Referrer* output_referrer) {
DCHECK(output_referrer);
Expand All @@ -448,6 +449,11 @@ bool MaybeChangeReferrer(
const url::Origin original_referrer = url::Origin::Create(current_referrer);
const url::Origin target_origin = url::Origin::Create(target_url);

if (redirect_source.is_valid()) {
return !net::registry_controlled_domains::SameDomainOrHost(redirect_source, target_url,
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
}

if (original_referrer.IsSameOriginWith(target_origin)) {
// Do nothing for same-origin requests. This check also prevents us from
// sending referrer from HTTPS to HTTP.
Expand Down
1 change: 1 addition & 0 deletions components/brave_shields/browser/brave_shields_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ bool MaybeChangeReferrer(
const GURL& current_referrer,
const GURL& tab_origin,
const GURL& target_url,
const GURL& redirect_source,
network::mojom::ReferrerPolicy policy,
content::Referrer* output_referrer);

Expand Down

0 comments on commit aae6562

Please sign in to comment.