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

Check if IPFS resolution is enabled before redirect URL requests. #7307

Merged
merged 2 commits into from
Dec 4, 2020

Conversation

yrliou
Copy link
Member

@yrliou yrliou commented Dec 2, 2020

This commit makes per_profile as True for IPFS policy, so we could move IPFS checks to component utils to be used in the IPFS network delegate helper.

Resolves brave/brave-browser#12978

Submitter Checklist:

  • There is a ticket for my issue.
  • Used Github auto-closing keywords in the commit message.
  • 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).
  • Requested a security/privacy review as needed.

Reviewer Checklist:

  • 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. Set IPFS resolve method to Gateway in settings.
  2. Visit ipfs://QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR in a private window, the scheme should not load.
  3. Visit ipfs://QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR in a guest window, the scheme should not load
  4. Set IPFS resolve method to disabled in settings
  5. Visit ipfs://QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR, the scheme should not load.

@yrliou yrliou self-assigned this Dec 2, 2020
@yrliou yrliou force-pushed the ipfs_add_redirect_check branch from 8ebd28a to b782b10 Compare December 2, 2020 01:02
@yrliou yrliou marked this pull request as ready for review December 2, 2020 01:15
@yrliou yrliou requested a review from iefremov as a code owner December 2, 2020 01:15
@yrliou yrliou requested a review from bbondy December 2, 2020 01:16
@yrliou yrliou force-pushed the ipfs_add_redirect_check branch 5 times, most recently from 0652e73 to 18e39dd Compare December 2, 2020 17:32
@@ -131,11 +131,12 @@ TEST_F(IpfsNavigationThrottleUnitTest, DeferUntilIpfsProcessLaunched) {
"/ip4/101.101.101.101/tcp/4001/p2p/"
"QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"};

ipfs_service(profile())->SetSkipGetConnectedPeersCallbackForTest(true);
auto* service = ipfs_service(profile());
ASSERT_TRUE(service != nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

ASSERT_TRUE(service)

@@ -78,6 +78,7 @@ struct BraveRequestInfo {
bool allow_http_upgradable_resource = false;
bool allow_referrers = false;
bool is_webtorrent_disabled = false;
bool resolve_ipfs_enabled = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

just a random thought - it seems that after all we should just save browser_context here

Copy link
Member Author

@yrliou yrliou Dec 3, 2020

Choose a reason for hiding this comment

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

That was actually my first thought, I prefer that way so ipfs details could be wrapped inside ipfs's helper and not in the general url_context. I'm changing it to save browser_context directly here.

@@ -71,7 +35,7 @@ IpfsServiceFactory* IpfsServiceFactory::GetInstance() {
// static
IpfsService* IpfsServiceFactory::GetForContext(
content::BrowserContext* context) {
if (!IsIpfsEnabled(context))
if (!brave::IsRegularProfile(context) || !IsIpfsEnabled(context))
Copy link
Contributor

Choose a reason for hiding this comment

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

curious, why this is needed. In theory, if you don't override GetBrowserContextToUse, default GetBrowserContextToUse will return nullptr for anything off-the-record and the service will not be instantiated. So removing this check and also removing GetBrowserContextToUse should do the trick

Copy link
Member Author

Choose a reason for hiding this comment

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

GetBrowserContextToUse override is not needed actually, removed.
brave::IsRegularProfile(context) checks IsGuestSession() also and is currently used by several of our service factories, we don't want to create instance for the regular guest profile (which is created when switching to guest happens, tho only the incognito profile of it will be used for browsing).

Copy link
Contributor

@iefremov iefremov Dec 4, 2020

Choose a reason for hiding this comment

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

I'm wondering whether brave::IsRegularProfile is needed at all, beacuse both Tor and Guest profiles are off-the-record. IMO we should erase it from the codebase in favor of BrowserContext::IsOffTheRecord, wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

This way, it seems like there is no sense in using here

@@ -12,6 +12,7 @@
#include "brave/components/ipfs/features.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

pls check for unused headers

@@ -138,6 +139,8 @@ std::shared_ptr<brave::BraveRequestInfo> BraveRequestInfo::MakeCTX(
ctx->upload_data = GetUploadData(request);

#if BUILDFLAG(IPFS_ENABLED)
ctx->resolve_ipfs_enabled =
Copy link
Contributor

Choose a reason for hiding this comment

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

mb it should be resolve_ipfs_DISabled , to avoid negation here and in the helper

@yrliou yrliou force-pushed the ipfs_add_redirect_check branch 2 times, most recently from 9101151 to c49aa38 Compare December 3, 2020 21:54
This commit makes per_profile as True for IPFS policy, so we could move IPFS
checks to component utils to be used in the IPFS network delegate helper.
- Save browser context in BraveRequestInfo.
- Remove GetBrowserContextToUse override in IpfsServiceFactory.
- Remove unused headers.
@yrliou yrliou force-pushed the ipfs_add_redirect_check branch from c49aa38 to d9d3733 Compare December 3, 2020 22:22
@yrliou
Copy link
Member Author

yrliou commented Dec 4, 2020

iOS test failure is irrelevant, windows fail at known test-install failure, 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
3 participants