Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8696: Change referrer blocking in Brave #5613

Merged
merged 5 commits into from
Jun 15, 2020
Merged

8696: Change referrer blocking in Brave #5613

merged 5 commits into from
Jun 15, 2020

Conversation

iefremov
Copy link
Contributor

@iefremov iefremov commented May 21, 2020

Resolves brave/brave-browser#8696

Submitter Checklist:

Test Plan:

Manual test pages:

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

@iefremov iefremov requested review from jumde and pes10k May 21, 2020 15:14
@@ -61,6 +61,8 @@ IN_PROC_BROWSER_TEST_F(BraveMainDelegateBrowserTest, EnabledFeatures) {
const base::Feature* enabled_features[] = {
&omnibox::kSimplifyHttpsIndicator,
&password_manager::features::kPasswordImport,
&features::kReducedReferrerGranularity,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This switches us to strict-origin-when-cross-origin

@@ -61,6 +61,8 @@ IN_PROC_BROWSER_TEST_F(BraveMainDelegateBrowserTest, EnabledFeatures) {
const base::Feature* enabled_features[] = {
&omnibox::kSimplifyHttpsIndicator,
&password_manager::features::kPasswordImport,
&features::kReducedReferrerGranularity,
&network::features::kCapReferrerToOriginOnCrossOrigin,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This satisfies the following

Requested policy of no-referrer, same-origin, or strict-origin?
If yes, change effective policy to the requested policy.

@iefremov iefremov requested a review from bbondy May 21, 2020 15:23
EXPECT_EQ(ExecScriptGetStr(create_image_script(), contents()),
image_url().spec());
EXPECT_EQ(GetLastReferrer(image_url()), iframe_url().GetOrigin().spec());
// Same-site sub-resources within the page get the page origin as referrer.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fmarier There is some confusion, since the the spec defines "same-site" as equal domains. This way, navigations to subdomains are not same-site, so we probably should rewrite these comments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean same-origin?

Because I'm using "same-site" here as defined in the Fetch spec since our policy is specifically looser (for webcompat reasons).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, sorry, you are correct!

@fmarier fmarier self-requested a review May 26, 2020 01:29
@bbondy bbondy requested a review from bridiver May 26, 2020 18:08
Copy link
Member

@fmarier fmarier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the side effects of relaxing the restrictions and leaning more heavily on the built-in referrer policy code is that we're actually become more strict in some cases because for sub-resources, we're moving away from "same-site" comparisons toward "same-origin" comparisons.

Therefore, I think it makes sense to change the existing "same-site" sub-resource tests to be all based on "same-origin". There's no point in testing the "same-site" case if it's the same as the "cross-origin" case.

For navigations, there is a difference and we should ideally test all three possible cases:

  • same-origin navigations: full referrer
  • same-site navigations: origin only
  • cross-origin navigations: no referrer

referrer = kReferrer.Clone();
client()->MaybeHideReferrer(browser()->profile(),
kRequestUrl, kDocumentUrl, false,
&referrer);
EXPECT_EQ(referrer->url, kRequestUrl.GetOrigin());
EXPECT_EQ(referrer->url, kDocumentUrl);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be the origin only in this case, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iframes are not handled by this method, this is only needed to fix document.referrer in main frames

Copy link
Member

@fmarier fmarier Jun 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by this test case. Is the comment wrong? Is this not a cross-origin iframe navigation?

If it is, then I don't think it should be getting the full referrer info like the same-origin top-level navigation test case just before it.

Is this DefaultBehaviour test not testing the default Brave behaviour?

EXPECT_EQ(GetLastReferrer(same_site_url()), url().spec());
EXPECT_EQ(ExecScriptGetStr(kReferrerScript, child_frame()),
url().GetOrigin().spec());
EXPECT_EQ(GetLastReferrer(same_site_url()), url().GetOrigin().spec());

// Cross-site iframe navigations get their referrer spoofed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not spoofed anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

EXPECT_EQ(
ExecScriptGetStr(create_image_script(cross_site_image_url()), contents()),
cross_site_image_url().spec());
EXPECT_EQ(GetLastReferrer(cross_site_image_url()), url().spec());
EXPECT_EQ(GetLastReferrer(cross_site_image_url()), url().GetOrigin().spec());

// A cross-origin iframe navigation gets the URL of the first one as
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"gets the ORIGIN of the first one"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@fmarier
Copy link
Member

fmarier commented May 27, 2020

One of the key differences between our implementation and what Chrome is planning on shipping is that we not only default to strict-origin-when-cross-origin, but we also ignore pages that request a looser policy.

We should add some browsertests to make sure that a referrer policy specified by the page cannot override ours.

Also, these two tests will need to be updated for the new behavior and ideally enabled (see brave/brave-browser#7933):

  • DISABLED_BlockReferrerByDefaultRedirects
  • DISABLED_BlockReferrerRedirects

@fmarier
Copy link
Member

fmarier commented May 27, 2020

Does the implementation also cover this case?

Requested policy of origin?
If yes, change effective policy to strict-origin

@iefremov
Copy link
Contributor Author

I think I've found a solution for proper referrer masking during redirects, will push it here soon (instead of a separate PR).

@iefremov
Copy link
Contributor Author

iefremov commented Jun 2, 2020

@fmarier I've updated the existing case and I think addressed #5613 (review)

@iefremov
Copy link
Contributor Author

iefremov commented Jun 2, 2020

I've decided to postpone fixing redirects, since it will take some time and can be done as a follow-up.

We should add some browsertests to make sure that a referrer policy specified by the page cannot override ours.

I think I can port some existing chromium tests in the next commit

iefremov added 4 commits June 12, 2020 23:12
Previously we used to spoof referrers for iframe and subresource
fetches and this has been causing some webcompat problems.

This PR removes this machinery, makes
'strict-origin-when-cross-origin' the default policy, prevents
this policy from downgrading and keeps referrer removal for
top-level navigations.
I had to restore referrer blocking in site hacks, because
it is needed for subresource queries (this does not help
us with redirects though).
@iefremov iefremov requested a review from fmarier June 12, 2020 16:13
return false;
}

// TODO(iefremov): Get rid of the whitelist once our webcompat is OK.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that will also get rid of the layering violation for g_brave_browser_process so I won't worry about it here

@iefremov iefremov added this to the 1.12.x - Nightly milestone Jun 15, 2020
@iefremov iefremov self-assigned this Jun 15, 2020
@iefremov iefremov dismissed fmarier’s stale review June 15, 2020 08:50

concerns addressed and discussed in DM

@iefremov
Copy link
Contributor Author

CI failure on MacOS seems unrelated, merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change sub-resource referrer policy to report 3p origin
3 participants