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

Strip referrer and origin headers in xorigin requests from a .onion #10760

Merged
merged 3 commits into from
Nov 19, 2021

Conversation

fmarier
Copy link
Member

@fmarier fmarier commented Oct 29, 2021

Resolves brave/brave-browser#18071

Security report: https://hackerone.com/reports/1337624

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

  1. Open http://ixrdj3iwwhkuau5tby5jh3a536a2rdhpbdbu6ldhng43r47kim7a3lid.onion/referrer/onion.html in a Tor window
  2. Open the Network tab of the devtools.
  3. Follow the instructions on that test page.

@fmarier fmarier requested review from mariospr and iefremov October 29, 2021 03:32
@fmarier fmarier self-assigned this Oct 29, 2021
@fmarier fmarier requested review from a team as code owners October 29, 2021 03:32
@fmarier
Copy link
Member Author

fmarier commented Oct 29, 2021

The extra patches are unfortunate, but I could not find a way to get our existing hooks to cover all of the test cases in my test page.

Note that I am planning to upstream (at least) the referrer patch into the Referrer Policy spec and then Chromium, given that the .onion scheme has been formally described in RFC 7686.

@fmarier fmarier changed the title Strip referrer and origin in xorigin requests from a .onion Strip referrer and origin headers in xorigin requests from a .onion Oct 29, 2021
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#define BRAVE_COMPUTE_REFERRER_FOR_POLICY \
Copy link
Contributor

Choose a reason for hiding this comment

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

why don't we do this in MaybeChangeReferrer in brave_shields_util.cc?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because it doesn't cover all cases,sadly. That was my first attempt, but none of our existing hooks were even called in the case of a redirected CORS request for example (test case #6 on my test page).

Changing this function also takes care of the Origin header in most cases (though not the CORS ones).

Copy link
Contributor

Choose a reason for hiding this comment

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

if it doesn't cover all cases, do we have a problem with the referrer capping that we do in MaybeChangeReferrer?..

Copy link
Member Author

Choose a reason for hiding this comment

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

We might, I haven't gotten around to testing that yet.

@fmarier fmarier force-pushed the referrer-onion-18071 branch from 4ef37e0 to e04ea51 Compare October 30, 2021 00:10
@fmarier fmarier requested a review from a team as a code owner October 30, 2021 00:10
@fmarier fmarier force-pushed the referrer-onion-18071 branch from e04ea51 to 3253526 Compare October 30, 2021 00:14
url::Origin::Create(request_.url))) { \
request_.headers.SetHeader(net::HttpRequestHeaders::kOrigin, \
url::Origin().Serialize()); \
} else /* NOLINT */
Copy link
Member Author

Choose a reason for hiding this comment

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

Needed, otherwise the linter complains about a missing brace.

@fmarier fmarier force-pushed the referrer-onion-18071 branch from 3253526 to 088cbb9 Compare October 30, 2021 00:34
@fmarier fmarier force-pushed the referrer-onion-18071 branch from 088cbb9 to ffa2c9b Compare November 1, 2021 18:32
@fmarier fmarier requested a review from iefremov November 1, 2021 18:33
@iefremov
Copy link
Contributor

iefremov commented Nov 3, 2021

If the fix is not super urgent we should invest into a browsertest, the url loader patch looks pretty fragile

@fmarier fmarier force-pushed the referrer-onion-18071 branch 2 times, most recently from 15bf75c to fe3b682 Compare November 9, 2021 02:51
@fmarier fmarier force-pushed the referrer-onion-18071 branch from fe3b682 to 0f3e7cd Compare November 16, 2021 07:56
@fmarier fmarier requested a review from iefremov November 16, 2021 08:04
@fmarier
Copy link
Member Author

fmarier commented Nov 16, 2021

@iefremov I have added a browsertest which covers all of the test cases I have manually tested. Could you please review again?

@fmarier fmarier force-pushed the referrer-onion-18071 branch from 0f3e7cd to 030bf22 Compare November 19, 2021 00:02
@fmarier fmarier force-pushed the referrer-onion-18071 branch from 030bf22 to 5e415ed Compare November 19, 2021 00:03
@fmarier fmarier merged commit 38b8fc1 into master Nov 19, 2021
@fmarier fmarier deleted the referrer-onion-18071 branch November 19, 2021 01:56
@fmarier fmarier added this to the 1.34.x - Nightly milestone Nov 19, 2021
brave-builds pushed a commit that referenced this pull request Nov 19, 2021
@kjozwiak
Copy link
Member

Verification PASSED on Win 11 x64 using the following build:

Brave | 1.34.38 Chromium: 96.0.4664.45 (Official Build) nightly (64-bit)
-- | --
Revision | 76e4c1bb2ab4671b8beba3444e61c0f17584b2fc-refs/branch-heads/4664@{#947}
OS | Windows 11 Version 21H2 (Build 22000.348)

Sub-resources

Same-origin

Test Case #1

onion16_1.png - was loaded with the full Referer header and the origin of this page in the Origin header.
  • Origin: http://ixrdj3iwwhkuau5tby5jh3a536a2rdhpbdbu6ldhng43r47kim7a3lid.onion
  • Referer: http://ixrdj3iwwhkuau5tby5jh3a536a2rdhpbdbu6ldhng43r47kim7a3lid.onion/referrer/onion.html

1

Test Case #2

onion16_2.png - was loaded with a full Referer header and without an Origin header.
  • Referer: http://ixrdj3iwwhkuau5tby5jh3a536a2rdhpbdbu6ldhng43r47kim7a3lid.onion/referrer/onion.html

2

Test Case #3

onion16_3.png - was loaded with a full Referer header and the origin of this page in the Origin header.
  • Origin: http://ixrdj3iwwhkuau5tby5jh3a536a2rdhpbdbu6ldhng43r47kim7a3lid.onion
  • Referer: http://ixrdj3iwwhkuau5tby5jh3a536a2rdhpbdbu6ldhng43r47kim7a3lid.onion/referrer/onion.html

3

Cross-origin

Test Case #1

onion16_4.png - was loaded without a Referer header and with a value of null in the Origin header.
  • origin: null

1

Test Case #2

onion16_5.png - was loaded without Referer or Origin headers.

2

Test Case #3

onion16_6.png - was loaded without a Referer header and a value of null in the Origin header.

3

Navigations

Same-origin

The Referer header should be present (full URL of this page) in this example:

Test Case #1 - after a same-origin GET navigation

1

Test Case #2 - after a same-origin GET navigation ending up in a redirect

2

The Referer and Origin headers should be present (full URL, and same hostname as this page, respectively) in all of these examples:

Test Case #1 - after a same-origin POST navigation

1

Test Case #2 - after a POST navigation ending up in a redirect

2

Cross-origin

Neither the Referer not the Origin header should be present in these examples:

Test Case #1 - after a cross-origin GET navigation

1

Test Case #2 - after a same-origin GET navigation ending up in a cross-origin redirect

2

Test Case #3 - after a cross-origin GET navigation ending up in a same-origin redirect

3

The Referer header should not be present and the Origin header should be null in all of these examples:

Test Case #1 - after a cross-origin POST navigation

1

Test Case #2 - after a same-origin POST navigation ending up in a cross-origin redirect

2

Test Case #3 - after a cross-origin POST navigation ending up in a same-origin redirect

3

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.

[hackerone] Strip referrer and origin in cross-origin requests from a .onion origin
4 participants