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

Added mixed content check for *.onion origins. #15436

Merged
merged 7 commits into from
Nov 10, 2022
Merged

Added mixed content check for *.onion origins. #15436

merged 7 commits into from
Nov 10, 2022

Conversation

boocmp
Copy link
Contributor

@boocmp boocmp commented Oct 12, 2022

Resolves brave/brave-browser#25939

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
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • 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:

// Treat .onions as https://
// onion -> https: not blocked
// onion -> http: blocked
return IsMixedContent("https", resource_url);
Copy link
Member

Choose a reason for hiding this comment

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

url::kHttpsScheme

}
{
content::WebContentsConsoleObserver console_observer(contents);
ASSERT_FALSE(content::ExecJs(contents, "fetch('https://example.onion')"));
Copy link
Member

@diracdeltas diracdeltas Oct 12, 2022

Choose a reason for hiding this comment

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

could you also add a test that images like <img src="http://example.com/favicon.jpg"> are blocked but not if it's example.onion?

Copy link
Member

Choose a reason for hiding this comment

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

actually this probably needs an example URL that doesn't support https at all (http://example.com can be upgraded to HTTPS). so something like <img src="http://http.badssl.com/favicon.ico">`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this test I'm using embedded_test_server() it supports http only.

Copy link
Member

Choose a reason for hiding this comment

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

i originally wrote https but fixed it - now these URLs are all http. or do you mean if http://http.badssl.com/favicon.ico redirects to HTTPS, it wouldn't work for the test server for some reason?


if (!security_origin->Host().EndsWith(kOnion))
return absl::nullopt;

Copy link
Member

Choose a reason for hiding this comment

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

please also check here that security_origin scheme is either http or https.

Copy link
Member

@diracdeltas diracdeltas Oct 12, 2022

Choose a reason for hiding this comment

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

(mixed content checking should only happen if scheme is http/https)

if (!security_origin->Host().EndsWith(kOnion))
return absl::nullopt;

if (resource_url.Host().EndsWith(kOnion)) {
Copy link
Member

Choose a reason for hiding this comment

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

should also check here if resource_url scheme is http or https.

actually i would just recommend a separate method isOnion or something, which checks that:

  1. hostname ends with .onion
  2. scheme is http or https

since the same check must be applied to both security_origin and resource_url

@diracdeltas
Copy link
Member

diracdeltas commented Oct 12, 2022

suggested test plan for qa:

  1. go to http://xao2lxsmia2edq2n5zxg6uahx6xox2t7bfjw6b5vdzsxi7ezmqob6qid.onion/ in tor window
  2. open devtools, enter fetch("https://www.example.com"). In the Network tab, you can see the request to https://www.example.com is not blocked.
  3. repeat step 2 but change https to http; it should be blocked
  4. go to https://brave4u7jddbv7cyviptqjc7jusxh72uik7zt6adtckl5f4nwy2v72qd.onion/index.html. repeat steps 2-3
  5. visit https://mixed.badssl.com/ and verify that it shows warning messages in the console about an insecure resource being requested (but was upgraded)
  6. go to https://mixed-favicon.badssl.com/ and verify it shows error message in the console about favicon being blocked
  7. verify https://mixed-form.badssl.com/ also shows a console warning
  8. verify https://mixed-script.badssl.com/ shows up with a grey background and has an error message in the console
  9. verify https://very.badssl.com/ shows both warnings and errors in the console

@kdenhartog
Copy link
Member

Looks like this one would close brave/brave-browser#25939 and brave/brave-browser#1135 from what I'm seeing

@diracdeltas
Copy link
Member

i don't think it would close brave/brave-browser#1135 since there's more to secure origins than just mixed content (geolocation allowed, etc.)

@boocmp boocmp force-pushed the issues/1135 branch 2 times, most recently from 730b03e to 352b6e4 Compare October 13, 2022 09:03
@kdenhartog
Copy link
Member

Thank you for the correction, I wasn't aware of that aspect of secure origins so seems like I've got some new "known unknowns" to read up on.

@boocmp boocmp force-pushed the issues/1135 branch 2 times, most recently from 3185d94 to 4fdae91 Compare October 13, 2022 14:59
}
{
content::WebContentsConsoleObserver console_observer(contents);
ASSERT_FALSE(content::ExecJs(contents, "fetch('http://example.onion')"));
Copy link
Member

@diracdeltas diracdeltas Oct 13, 2022

Choose a reason for hiding this comment

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

also should change this to an onion site that sends access-control-allow-origin: *, ex: http://static01.nyt2sl3njavkomjxqe2e5nz6bsqv56yqbwkvhpmfn5jwh4pyccmjibad.onion/ads/tpc-check.html

@fmarier
Copy link
Member

fmarier commented Oct 14, 2022

I created two test pages to confirm that the Tor Browser behaves as we expected (it does):

To run this test, I had to customize the following in Tor Browser:

  • dom.security.https_only_mode=false
  • security.mixed_content.block_display_content=true

@diracdeltas
Copy link
Member

@fmarier awesome! did you test the mixed content autoupgrade case? (i.e., secure page embeds an HTTP image that supports HTTPS. in chrome it should autoupgrade the request to HTTPS. you can try with this URL: http://mixed.badssl.com/image.jpg.)

i'm guessing tor browser doesn't do the autoupgrade, but might be nice to have in brave.

@fmarier
Copy link
Member

fmarier commented Oct 26, 2022

i'm guessing tor browser doesn't do the autoupgrade, but might be nice to have in brave.

The Tor Browser is actually running with HTTPS-only mode now (like Firefox private browsing I believe). I had to explicitly disable that feature in order to see the behavior of the mixed content blocker :)

@arthuredelstein
Copy link
Collaborator

arthuredelstein commented Oct 27, 2022

i'm guessing tor browser doesn't do the autoupgrade, but might be nice to have in brave.

The Tor Browser is actually running with HTTPS-only mode now (like Firefox private browsing I believe). I had to explicitly disable that feature in order to see the behavior of the mixed content blocker :)

HTTPS-Only Mode (HOM) in Tor Windows only enforces HTTPS on top-level (non-onion) domains, so it's a good idea to make sure that, when HOM is enabled, the mixed-content blocker blocks the loading of insecure (HTTP, non-onion images) on http://[address].onion pages.

(FWIW, Firefox private browsing actually runs HTTPS-by-Default, which is somewhat weaker than HTTPS-Only Mode.)

@diracdeltas
Copy link
Member

this is pretty much good to go for me except i think this test page should not have the <meta> policy: https://github.com/brave/brave-core/pull/15436/files#r994963774

any other concerns @fmarier @arthuredelstein ?

@arthuredelstein
Copy link
Collaborator

Looks good to me. Thanks @boocmp !

}
{
content::WebContentsConsoleObserver console_observer(contents);
const GURL resource_url =
Copy link
Member

Choose a reason for hiding this comment

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

This line seems unnecessary since we're not using resource_url in this block.


// We are hiding IsMixedContent(const String& origin_protocol, const KURL&)
// because we want to enforce mixed content checks on .onion origins.
// Publically available protocol-only overload of this method allows to skip
Copy link
Member

Choose a reason for hiding this comment

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

typo: "Publicly"

@boocmp
Copy link
Contributor Author

boocmp commented Oct 31, 2022

this is pretty much good to go for me except i think this test page should not have the <meta> policy: https://github.com/brave/brave-core/pull/15436/files#r994963774

I don't know how to configure embedded http test server to support "upgrade-insecure-requests", The client request contains "upgrade-insecure-requests: 1" header, but without meta tag it doesn't work. It works only on embedded https server.

@diracdeltas
Copy link
Member

this is pretty much good to go for me except i think this test page should not have the <meta> policy: https://github.com/brave/brave-core/pull/15436/files#r994963774

I don't know how to configure embedded http test server to support "upgrade-insecure-requests", The client request contains "upgrade-insecure-requests: 1" header, but without meta tag it doesn't work. It works only on embedded https server.

oh i see, the problem is that the test server is HTTP.

assuming there is no way to run an HTTPS test server, this is fine as-is assuming @fmarier has a test case for QA with autoupgrading mixed content.

@diracdeltas
Copy link
Member

should be ok to merge?

{
content::WebContentsConsoleObserver console_observer(contents);
ASSERT_FALSE(content::ExecJs(contents, "fetch('https://example.com')"));
EXPECT_TRUE(console_observer.messages().empty());
Copy link
Member

@goodov goodov Nov 8, 2022

Choose a reason for hiding this comment

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

this observer doesn't wait for messages. Does this line check anything at all?

@@ -98,6 +100,11 @@ class BraveContentBrowserClientTest : public InProcessBrowserTest {
"brave_webtorrent.html?chrome://settings");
}

void SetUpCommandLine(base::CommandLine* command_line) override {
InProcessBrowserTest::SetUpCommandLine(command_line);
command_line->AppendSwitch("ignore-certificate-errors");
Copy link
Member

Choose a reason for hiding this comment

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

please replace this with content::ContentMockCertVerifier.
see for details: https://bravesoftware.slack.com/archives/C7VLGSR55/p1636702893335800

@boocmp boocmp merged commit c5cdfbb into master Nov 10, 2022
@boocmp boocmp deleted the issues/1135 branch November 10, 2022 07:23
@github-actions github-actions bot added this to the 1.47.x - Nightly milestone Nov 10, 2022
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] block mixed content on .onion sites
6 participants