Skip to content
Permalink
Browse files Browse the repository at this point in the history
Merge pull request #14211 from brave/brave_24093
Block incorrect IPFS\IPNS urls.
  • Loading branch information
cypt4 committed Jul 19, 2022
2 parents df2446e + 498ade8 commit e733096
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions browser/net/ipfs_redirect_network_delegate_helper.cc
Expand Up @@ -59,7 +59,11 @@ int OnBeforeURLRequest_IPFSRedirectWork(
} else {
ctx->blocked_by = brave::kOtherBlocked;
}
} else if (has_ipfs_scheme) {
// Block incorrect url.
ctx->blocked_by = brave::kOtherBlocked;
}

return net::OK;
}

Expand Down
55 changes: 55 additions & 0 deletions browser/net/ipfs_redirect_network_delegate_helper_unittest.cc
Expand Up @@ -117,6 +117,61 @@ TEST_F(IPFSRedirectNetworkDelegateHelperTest,
EXPECT_EQ(brave_request_info->blocked_by, brave::kOtherBlocked);
}

TEST_F(IPFSRedirectNetworkDelegateHelperTest,
LoadDisabledWhenIPFS_WhenWrongIPFSUrl) {
profile()->GetPrefs()->SetInteger(
kIPFSResolveMethod, static_cast<int>(IPFSResolveMethodTypes::IPFS_LOCAL));

// IPFS Subframe
{
GURL url("ipfs://10.10.10.1");
auto brave_request_info = std::make_shared<brave::BraveRequestInfo>(url);
brave_request_info->resource_type = blink::mojom::ResourceType::kSubFrame;
brave_request_info->browser_context = profile();
int rc = ipfs::OnBeforeURLRequest_IPFSRedirectWork(
brave::ResponseCallback(), brave_request_info);
EXPECT_EQ(rc, net::OK);
ASSERT_EQ(brave_request_info->blocked_by, brave::kOtherBlocked);
}

// IPFS Mainframe
{
GURL url("ipfs://10.10.10.1");
auto brave_request_info = std::make_shared<brave::BraveRequestInfo>(url);
brave_request_info->resource_type = blink::mojom::ResourceType::kMainFrame;
brave_request_info->browser_context = profile();
int rc = ipfs::OnBeforeURLRequest_IPFSRedirectWork(
brave::ResponseCallback(), brave_request_info);
EXPECT_EQ(rc, net::OK);
ASSERT_EQ(brave_request_info->blocked_by, brave::kOtherBlocked);
}

// IPNS Subframe
{
GURL url("ipns://10.10.10.1");
auto brave_request_info = std::make_shared<brave::BraveRequestInfo>(url);
brave_request_info->resource_type = blink::mojom::ResourceType::kSubFrame;
brave_request_info->browser_context = profile();
int rc = ipfs::OnBeforeURLRequest_IPFSRedirectWork(
brave::ResponseCallback(), brave_request_info);
EXPECT_EQ(rc, net::OK);
ASSERT_EQ(brave_request_info->blocked_by, brave::kOtherBlocked);
}

// IPFS Mainframe
{
GURL url("ipns://10.10.10.1");
auto brave_request_info = std::make_shared<brave::BraveRequestInfo>(url);
brave_request_info->resource_type = blink::mojom::ResourceType::kMainFrame;
brave_request_info->browser_context = profile();
int rc = ipfs::OnBeforeURLRequest_IPFSRedirectWork(
brave::ResponseCallback(), brave_request_info);
EXPECT_EQ(rc, net::OK);
// It is correct ipns url.
ASSERT_EQ(brave_request_info->blocked_by, brave::kNotBlocked);
}
}

TEST_F(IPFSRedirectNetworkDelegateHelperTest,
SubFrameRequestDisabledWhen_NoContext) {
profile()->GetPrefs()->SetInteger(
Expand Down

0 comments on commit e733096

Please sign in to comment.