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 and bsclifton committed Jun 18, 2020
1 parent 93a70d8 commit 1ab4d6a
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 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,19 +17,32 @@
#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();
}

} // namespace

namespace brave {

const char kBraveSessionToken[] = "brave_session_token";
const char BraveSessionCache::kSupplementName[] = "BraveSessionCache";

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 1ab4d6a

Please sign in to comment.