From 9e6c42511ec71a781516a26d84f2edcedffc30e3 Mon Sep 17 00:00:00 2001
From: brave-builds <45370463+brave-builds@users.noreply.github.com>
Date: Mon, 8 Jan 2024 00:41:22 +0100
Subject: [PATCH] Force the referrer to always be 'no-referrer' while in
speedreader mode. (uplift to 1.62.x) (#21497)
Uplift of #21481 (squashed) to beta
---
browser/speedreader/speedreader_browsertest.cc | 8 ++++++++
components/speedreader/speedreader_rewriter_service.cc | 1 +
2 files changed, 9 insertions(+)
diff --git a/browser/speedreader/speedreader_browsertest.cc b/browser/speedreader/speedreader_browsertest.cc
index c57c5b749690..ebac09ddc9ea 100644
--- a/browser/speedreader/speedreader_browsertest.cc
+++ b/browser/speedreader/speedreader_browsertest.cc
@@ -317,6 +317,9 @@ IN_PROC_BROWSER_TEST_F(SpeedReaderBrowserTest, SmokeTest) {
const std::string kGetFontsExists =
"!!(document.getElementById('atkinson_hyperligible_font') && "
"document.getElementById('open_dyslexic_font'))";
+ const std::string kCheckReferrer =
+ R"js(document.querySelector('meta[name="referrer"]')
+ .getAttribute('content') === 'no-referrer')js";
// Check that the document became much smaller and that non-empty speedreader
// style is injected.
@@ -328,6 +331,11 @@ IN_PROC_BROWSER_TEST_F(SpeedReaderBrowserTest, SmokeTest) {
content::EXECUTE_SCRIPT_DEFAULT_OPTIONS,
ISOLATED_WORLD_ID_BRAVE_INTERNAL)
.ExtractBool());
+ EXPECT_TRUE(content::EvalJs(ActiveWebContents(), kCheckReferrer,
+ content::EXECUTE_SCRIPT_DEFAULT_OPTIONS,
+ ISOLATED_WORLD_ID_BRAVE_INTERNAL)
+ .ExtractBool());
+
const auto speedreaded_length =
content::EvalJs(ActiveWebContents(), kGetContentLength,
content::EXECUTE_SCRIPT_DEFAULT_OPTIONS,
diff --git a/components/speedreader/speedreader_rewriter_service.cc b/components/speedreader/speedreader_rewriter_service.cc
index 3b00db75d852..b985c336cf2d 100644
--- a/components/speedreader/speedreader_rewriter_service.cc
+++ b/components/speedreader/speedreader_rewriter_service.cc
@@ -44,6 +44,7 @@ std::string WrapStylesheetWithCSP(const std::string& stylesheet,
};
constexpr const char kCSP[] = R"html(
+