Skip to content

Allow only IPNS and domain names in rewards #9375

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

Merged
merged 2 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions chromium_src/net/base/lookup_string_in_fixed_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ int LookupSuffixInReversedSet(const unsigned char* graph,
*suffix_length = strlen(decentralized_dns::kEthDomain) - 1;
return kDafsaFound;
}
if (base::EndsWith(host, decentralized_dns::kDNSForEthDomain)) {
*suffix_length = strlen(decentralized_dns::kDNSForEthDomain) - 1;
return kDafsaFound;
}

return LookupSuffixInReversedSet_ChromiumImpl(graph, length, include_private,
host, suffix_length);
Expand Down
40 changes: 21 additions & 19 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -651,18 +651,25 @@ void RewardsServiceImpl::OnLoad(SessionID tab_id, const GURL& url) {
return;
}

auto origin = url.GetOrigin();
const std::string baseDomain =
GetDomainAndRegistry(origin.host(), INCLUDE_PRIVATE_REGISTRIES);

auto origin = url.GetOrigin().host();
std::string baseDomain =
GetDomainAndRegistry(url.host(), INCLUDE_PRIVATE_REGISTRIES);
#if BUILDFLAG(IPFS_ENABLED)
if (baseDomain.empty()) {
baseDomain = ipfs::GetRegistryDomainFromIPNS(url);
if (!baseDomain.empty()) {
origin = baseDomain;
}
}
#endif
if (baseDomain == "")
return;

const std::string publisher_url = origin.scheme() + "://" + baseDomain + "/";
const std::string publisher_url = url.scheme() + "://" + baseDomain + "/";

ledger::type::VisitDataPtr data = ledger::type::VisitData::New();
data->tld = data->name = baseDomain;
data->domain = origin.host(),
data->domain = origin;
data->path = url.path();
data->tab_id = tab_id.id();
data->url = publisher_url;
Expand Down Expand Up @@ -1767,21 +1774,16 @@ void RewardsServiceImpl::GetPublisherActivityFromUrl(
return;
}

auto origin = parsed_url.GetOrigin();
auto origin = parsed_url.GetOrigin().spec();
std::string baseDomain =
GetDomainAndRegistry(origin.host(), INCLUDE_PRIVATE_REGISTRIES);
GetDomainAndRegistry(parsed_url.host(), INCLUDE_PRIVATE_REGISTRIES);
std::string path = parsed_url.PathForRequest();
#if BUILDFLAG(IPFS_ENABLED)
if (parsed_url.SchemeIs(ipfs::kIPNSScheme)) {
std::string cid;
if (!ipfs::ParseCIDAndPathFromIPFSUrl(parsed_url, &cid, &path) ||
cid.empty())
return;
origin = GURL(parsed_url.scheme() + "://" + cid);
baseDomain = cid;
} else if (parsed_url.SchemeIs(ipfs::kIPFSScheme)) {
OnPanelPublisherInfo(ledger::type::Result::NOT_FOUND, nullptr, windowId);
return;
if (baseDomain.empty()) {
baseDomain = ipfs::GetRegistryDomainFromIPNS(parsed_url);
if (!baseDomain.empty()) {
origin = parsed_url.scheme() + "://" + baseDomain + "/";
}
}
#endif
if (baseDomain == "") {
Expand All @@ -1800,7 +1802,7 @@ void RewardsServiceImpl::GetPublisherActivityFromUrl(
ledger::type::VisitDataPtr visit_data = ledger::type::VisitData::New();
visit_data->domain = visit_data->name = baseDomain;
visit_data->path = path;
visit_data->url = origin.spec();
visit_data->url = origin;
visit_data->favicon_url = favicon_url;

bat_ledger_->GetPublisherActivityFromUrl(
Expand Down
12 changes: 12 additions & 0 deletions components/ipfs/ipfs_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "brave/components/ipfs/pref_names.h"
#include "components/base32/base32.h"
#include "components/prefs/pref_service.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/base/url_util.h"
#include "third_party/re2/src/re2/re2.h"
#include "url/gurl.h"
Expand Down Expand Up @@ -388,4 +389,15 @@ GURL ContentHashToCIDv1URL(const std::string& contenthash) {
return GURL(scheme + "://" + cidv1);
}

std::string GetRegistryDomainFromIPNS(const GURL& url) {
if (!url.SchemeIs(ipfs::kIPNSScheme))
return std::string();
std::string cid;
std::string ipfs_path;
if (!ipfs::ParseCIDAndPathFromIPFSUrl(url, &cid, &ipfs_path) || cid.empty())
return std::string();
return GetDomainAndRegistry(
cid, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
}

} // namespace ipfs
1 change: 1 addition & 0 deletions components/ipfs/ipfs_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ bool ParsePeerConnectionString(const std::string& value,
GURL ContentHashToCIDv1URL(const std::string& contenthash);
bool IsAPIGateway(const GURL& url, version_info::Channel channel);
bool IsIpfsResolveMethodDisabled(PrefService* prefs);
std::string GetRegistryDomainFromIPNS(const GURL& url);
} // namespace ipfs

#endif // BRAVE_COMPONENTS_IPFS_IPFS_UTILS_H_
15 changes: 15 additions & 0 deletions components/ipfs/ipfs_utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -657,3 +657,18 @@ TEST_F(IpfsUtilsUnitTest, IsAPIGatewayTest) {
ASSERT_FALSE(ipfs::IsAPIGateway(GURL("https://brave.com"), channel));
ASSERT_FALSE(ipfs::IsAPIGateway(GURL(), channel));
}

TEST_F(IpfsUtilsUnitTest, IPNSRegistryDomain) {
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("http://google.com")), "");
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("https://google.com")), "");
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("ipfs://bafy")), "");
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("ipfs://QmfdSDf")), "");
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("ipns://QmfdSDf/path")), "");
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("ipns://bafyff/path")), "");
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("ipns://brantly.eth.link")),
"brantly.eth.link");
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("ipns://brantly.eth/path")),
"brantly.eth");
EXPECT_EQ(ipfs::GetRegistryDomainFromIPNS(GURL("ipns://blah.google.com")),
"google.com");
}
1 change: 1 addition & 0 deletions net/decentralized_dns/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ constexpr char kUnstoppableDomainsDoHResolver[] =
"https://resolver.unstoppable.io/dns-query{?brave_UD}";

constexpr char kEthDomain[] = ".eth";
constexpr char kDNSForEthDomain[] = ".eth.link";
constexpr char kENSDoHResolver[] =
"https://resolver.cloudflare-eth.com/dns-query{?brave_ENS}";

Expand Down