Skip to content

Commit

Permalink
Merge pull request #5877 from brave/change-farbling-origin-lookup
Browse files Browse the repository at this point in the history
climb frame tree to determine top level eTLD+1 when generating farble seed
  • Loading branch information
pes10k authored Jun 17, 2020
2 parents d15e9ad + 63d585b commit ee1270d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions chromium_src/third_party/blink/renderer/core/dom/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "base/strings/string_number_conversions.h"
#include "brave/third_party/blink/renderer/brave_farbling_constants.h"
#include "crypto/hmac.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "third_party/blink/public/platform/web_content_settings_client.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
Expand All @@ -18,10 +17,22 @@
#include "third_party/blink/renderer/platform/graphics/static_bitmap_image.h"
#include "third_party/blink/renderer/platform/graphics/unaccelerated_static_bitmap_image.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/network/network_utils.h"
#include "third_party/blink/renderer/platform/supplementable.h"

namespace {

// Returns the eTLD+1 for the top level frame the document is in.
//
// Returns the eTLD+1 (effective registrable domain) for the top level
// frame that the given document is in. This includes frames that
// are disconnect, remote or local to the top level frame.
std::string TopETLDPlusOneForDoc(const Document& doc) {
const auto host = doc.TopFrameOrigin()->Host();
return blink::network_utils::GetDomainAndRegistry(host,
blink::network_utils::kIncludePrivateRegistries).Utf8();
}

const uint64_t zero = 0;

inline uint64_t lfsr_next(uint64_t v) {
Expand Down Expand Up @@ -65,10 +76,7 @@ const size_t kLettersForRandomStringsLength = 64;

BraveSessionCache::BraveSessionCache(Document& document)
: Supplement<Document>(document) {
base::StringPiece host =
base::StringPiece(document.TopFrameOrigin()->ToUrlOrigin().host());
std::string domain = net::registry_controlled_domains::GetDomainAndRegistry(
host, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
const std::string domain = TopETLDPlusOneForDoc(document);
farbling_enabled_ = !domain.empty();
if (farbling_enabled_) {
base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
Expand Down

0 comments on commit ee1270d

Please sign in to comment.