Commit c6575cd1 authored by Robert Ogden's avatar Robert Ogden Committed by Commit Bot

Blacklist media URLs via variations

Prevents navigations to media URLs (like an mp4 or jpg) from triggering
HTTPS Server Previews. This blacklist is a comma separated string that
is controlled via field trial.

Bug: 864637
Change-Id: Iff545d975c8c17aa433a95f57d8a01d86cf73279
Reviewed-on: https://chromium-review.googlesource.com/1187200Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Commit-Queue: Robert Ogden <robertogden@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585598}
parent 5b38d225
......@@ -80,18 +80,21 @@ class PreviewsBrowserTest : public InProcessBrowserTest {
// Set up https server with resource monitor.
https_server_.reset(
new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS));
https_server_->ServeFilesFromSourceDirectory("chrome/test/data/previews");
https_server_->ServeFilesFromSourceDirectory("chrome/test/data");
https_server_->RegisterRequestMonitor(base::BindRepeating(
&PreviewsBrowserTest::MonitorResourceRequest, base::Unretained(this)));
ASSERT_TRUE(https_server_->Start());
https_url_ = https_server_->GetURL("/noscript_test.html");
https_url_ = https_server_->GetURL("/previews/noscript_test.html");
ASSERT_TRUE(https_url_.SchemeIs(url::kHttpsScheme));
https_no_transform_url_ =
https_server_->GetURL("/noscript_test_with_no_transform_header.html");
https_no_transform_url_ = https_server_->GetURL(
"/previews/noscript_test_with_no_transform_header.html");
ASSERT_TRUE(https_no_transform_url_.SchemeIs(url::kHttpsScheme));
https_media_url_ = https_server_->GetURL("/image_decoding/droids.jpg");
ASSERT_TRUE(https_media_url_.SchemeIs(url::kHttpsScheme));
// Set up http server with resource monitor and redirect handler.
http_server_.reset(
new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTP));
......@@ -124,6 +127,7 @@ class PreviewsBrowserTest : public InProcessBrowserTest {
const GURL& https_url() const { return https_url_; }
const GURL& https_no_transform_url() const { return https_no_transform_url_; }
const GURL& https_media_url() const { return https_media_url_; }
const GURL& http_url() const { return http_url_; }
const GURL& redirect_url() const { return redirect_url_; }
const GURL& subframe_url() const { return subframe_url_; }
......@@ -159,6 +163,7 @@ class PreviewsBrowserTest : public InProcessBrowserTest {
std::unique_ptr<net::EmbeddedTestServer> http_server_;
GURL https_url_;
GURL https_no_transform_url_;
GURL https_media_url_;
GURL http_url_;
GURL redirect_url_;
GURL subframe_url_;
......@@ -380,7 +385,8 @@ class PreviewsLitePageServerBrowserTest : public PreviewsBrowserTest {
scoped_refptr<base::FieldTrial> trial =
base::FieldTrialList::CreateFieldTrial("TrialName1", "GroupName1");
std::map<std::string, std::string> feature_parameters = {
{"previews_host", previews_server().spec()}};
{"previews_host", previews_server().spec()},
{"blacklisted_path_suffixes", ".mp4,.jpg"}};
base::FieldTrialParamAssociator::GetInstance()->AssociateFieldTrialParams(
"TrialName1", "GroupName1", feature_parameters);
......@@ -523,6 +529,10 @@ IN_PROC_BROWSER_TEST_F(PreviewsLitePageServerBrowserTest,
ui_test_utils::NavigateToURL(browser(), https_lite_page_url(200));
VerifyPreviewLoaded();
// Verify the preview is not triggered when loading a media resource.
ui_test_utils::NavigateToURL(browser(), https_media_url());
VerifyPreviewNotLoaded();
// Verify the preview is not triggered for POST navigations.
std::string post_data = "helloworld";
NavigateParams params(browser(), https_url(), ui::PAGE_TRANSITION_LINK);
......
......@@ -85,7 +85,8 @@ PreviewsLitePageNavigationThrottle::~PreviewsLitePageNavigationThrottle() =
default;
bool PreviewsLitePageNavigationThrottle::IsEligibleForPreview() const {
if (!navigation_handle()->GetURL().SchemeIs(url::kHttpsScheme))
const GURL& url = navigation_handle()->GetURL();
if (!url.SchemeIs(url::kHttpsScheme))
return false;
if (navigation_handle()->IsPost())
......@@ -97,9 +98,18 @@ bool PreviewsLitePageNavigationThrottle::IsEligibleForPreview() const {
if (manager_->IsServerUnavailable())
return false;
if (IsPreviewsDomain(navigation_handle()->GetURL()))
if (IsPreviewsDomain(url))
return false;
std::vector<std::string> blacklisted_path_suffixes =
previews::params::LitePagePreviewsBlacklistedPathSuffixes();
for (std::string suffix : blacklisted_path_suffixes) {
if (base::EndsWith(url.path(), suffix,
base::CompareCase::INSENSITIVE_ASCII)) {
return false;
}
}
return true;
}
......
......@@ -135,6 +135,15 @@ base::TimeDelta LitePagePreviewsSingleBypassDuration() {
60 * 5));
}
std::vector<std::string> LitePagePreviewsBlacklistedPathSuffixes() {
const std::string csv = base::GetFieldTrialParamValueByFeature(
features::kLitePageServerPreviews, "blacklisted_path_suffixes");
if (csv == "")
return {};
return base::SplitString(csv, ",", base::TRIM_WHITESPACE,
base::SPLIT_WANT_NONEMPTY);
}
int PreviewServerLoadshedMaxSeconds() {
return base::GetFieldTrialParamByFeatureAsInt(
features::kLitePageServerPreviews, "loadshed_max_seconds",
......
......@@ -95,6 +95,10 @@ GURL GetLitePagePreviewsDomainURL();
// The duration of a single bypass for Lite Page Server Previews.
base::TimeDelta LitePagePreviewsSingleBypassDuration();
// A list of all path suffixes to blacklist from Lite Page Server Previews.
// Primarily used to prohibit URLs that look like media requests.
std::vector<std::string> LitePagePreviewsBlacklistedPathSuffixes();
// The maximum number of seconds to loadshed the Previews server for.
int PreviewServerLoadshedMaxSeconds();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment