Commit 26fb902e authored by Mustafa Emre Acer's avatar Mustafa Emre Acer Committed by Commit Bot

Lookalikes: Handle WillProcessResponse instead of WillStartRequest

This CL is effectively a revert of crrev.com/c/1526806.

That commit changed the implementation of the lookalike
URL navigation throttle to observe WillStartRequest() instead of
WillProcessResponse. As a result, the throttle was no longer able to
see the redirect chain and did not have a way of allowing certain safe
redirects such as elespañol[.]com to elespanol[.]com.

This CL goes back to using WillProcesResponse(). Doing this gives
WillRedirectRequest() a chance to run and lets the throttle observe
the redirect chain. Follow up CLs will allow safe redirects.

Bug: 986404
Change-Id: I9b41b9b2c29e12120a0ecb2af6c50d283e915458
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1713445Reviewed-by: default avatarJoe DeBlasio <jdeblasio@chromium.org>
Commit-Queue: Mustafa Emre Acer <meacer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680260}
parent 7347cc4b
...@@ -264,12 +264,25 @@ ThrottleCheckResult LookalikeUrlNavigationThrottle::HandleThrottleRequest( ...@@ -264,12 +264,25 @@ ThrottleCheckResult LookalikeUrlNavigationThrottle::HandleThrottleRequest(
return PerformChecks(url, navigated_domain, service->GetLatestEngagedSites()); return PerformChecks(url, navigated_domain, service->GetLatestEngagedSites());
} }
ThrottleCheckResult LookalikeUrlNavigationThrottle::WillStartRequest() { ThrottleCheckResult LookalikeUrlNavigationThrottle::WillProcessResponse() {
if (navigation_handle()->GetNetErrorCode() != net::OK) {
return content::NavigationThrottle::PROCEED;
}
return HandleThrottleRequest(navigation_handle()->GetURL()); return HandleThrottleRequest(navigation_handle()->GetURL());
} }
ThrottleCheckResult LookalikeUrlNavigationThrottle::WillRedirectRequest() { ThrottleCheckResult LookalikeUrlNavigationThrottle::WillRedirectRequest() {
return HandleThrottleRequest(navigation_handle()->GetURL()); const std::vector<GURL>& chain = navigation_handle()->GetRedirectChain();
// WillRedirectRequest is called after a redirect occurs, so the end of the
// chain is the URL that was redirected to. We need to check the preceding URL
// that caused the redirection. The final URL in the chain is checked either:
// - after the next redirection (when there is a longer chain), or
// - by WillProcessResponse (before content is rendered).
if (chain.size() < 2) {
return content::NavigationThrottle::PROCEED;
}
return HandleThrottleRequest(chain[chain.size() - 2]);
} }
const char* LookalikeUrlNavigationThrottle::GetNameForLogging() { const char* LookalikeUrlNavigationThrottle::GetNameForLogging() {
......
...@@ -58,7 +58,7 @@ class LookalikeUrlNavigationThrottle : public content::NavigationThrottle { ...@@ -58,7 +58,7 @@ class LookalikeUrlNavigationThrottle : public content::NavigationThrottle {
~LookalikeUrlNavigationThrottle() override; ~LookalikeUrlNavigationThrottle() override;
// content::NavigationThrottle: // content::NavigationThrottle:
ThrottleCheckResult WillStartRequest() override; ThrottleCheckResult WillProcessResponse() override;
ThrottleCheckResult WillRedirectRequest() override; ThrottleCheckResult WillRedirectRequest() override;
const char* GetNameForLogging() override; const char* GetNameForLogging() override;
......
...@@ -590,7 +590,7 @@ IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest, ...@@ -590,7 +590,7 @@ IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest,
CheckNoUkm(); CheckNoUkm();
} }
// Test that the heuristics are triggered even with net errors. // Test that the heuristics are not triggered even with net errors.
IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest, IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest,
NetError_SiteEngagement_Interstitial) { NetError_SiteEngagement_Interstitial) {
// Create a test server that returns invalid responses. // Create a test server that returns invalid responses.
...@@ -603,10 +603,8 @@ IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest, ...@@ -603,10 +603,8 @@ IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest,
// Advance clock to force a fetch of new engaged sites list. // Advance clock to force a fetch of new engaged sites list.
test_clock()->Advance(base::TimeDelta::FromHours(1)); test_clock()->Advance(base::TimeDelta::FromHours(1));
TestMetricsRecordedAndMaybeInterstitialShown( TestInterstitialNotShown(
browser(), custom_test_server.GetURL("sité1.com", "/title1.html"), browser(), custom_test_server.GetURL("sité1.com", "/title1.html"));
custom_test_server.GetURL("site1.com", "/"),
NavigationSuggestionEvent::kMatchSiteEngagement);
} }
// Same as NetError_SiteEngagement_Interstitial, but triggered by a top domain. // Same as NetError_SiteEngagement_Interstitial, but triggered by a top domain.
...@@ -617,61 +615,8 @@ IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest, ...@@ -617,61 +615,8 @@ IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest,
custom_test_server.RegisterRequestHandler( custom_test_server.RegisterRequestHandler(
base::BindRepeating(&NetworkErrorResponseHandler)); base::BindRepeating(&NetworkErrorResponseHandler));
ASSERT_TRUE(custom_test_server.Start()); ASSERT_TRUE(custom_test_server.Start());
TestInterstitialNotShown(browser(),
TestMetricsRecordedAndMaybeInterstitialShown( custom_test_server.GetURL("googlé.com", "/"));
browser(), GetURL("googlé.com"), GetURLWithoutPath("google.com"),
NavigationSuggestionEvent::kMatchTopSite);
}
// Verify that, after dismissing a lookalike warning when enabled, the user
// sees a net error when applicable.
IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest,
NetError_SiteEngagement_NetErrorAfterDismiss) {
// Create a test server that returns invalid responses.
net::EmbeddedTestServer custom_test_server;
custom_test_server.RegisterRequestHandler(
base::BindRepeating(&NetworkErrorResponseHandler));
ASSERT_TRUE(custom_test_server.Start());
SetEngagementScore(browser(), GURL("http://site1.com"), kHighEngagement);
// Advance clock to force a fetch of new engaged sites list.
test_clock()->Advance(base::TimeDelta::FromHours(1));
NavigateToURLSync(browser(),
custom_test_server.GetURL("sité1.com", "/title1.html"));
if (ui_enabled()) {
SendInterstitialCommandSync(browser(),
SecurityInterstitialCommand::CMD_PROCEED);
}
EXPECT_GE(ui_test_utils::FindInPage(
browser()->tab_strip_model()->GetActiveWebContents(),
base::ASCIIToUTF16("ERR_EMPTY_RESPONSE"), true, true, nullptr,
nullptr),
1);
}
// Same as NetError_SiteEngagement_NetErrorAfterDismiss, but navigates to a top
// domain instead.
IN_PROC_BROWSER_TEST_P(LookalikeUrlNavigationThrottleBrowserTest,
NetError_TopDomain_NetErrorAfterDismiss) {
// Create a test server that returns invalid responses.
net::EmbeddedTestServer custom_test_server;
custom_test_server.RegisterRequestHandler(
base::BindRepeating(&NetworkErrorResponseHandler));
ASSERT_TRUE(custom_test_server.Start());
NavigateToURLSync(browser(),
custom_test_server.GetURL("googlé.com", "/title1.html"));
if (ShouldExpectInterstitial(NavigationSuggestionEvent::kMatchTopSite)) {
SendInterstitialCommandSync(browser(),
SecurityInterstitialCommand::CMD_PROCEED);
}
EXPECT_GE(ui_test_utils::FindInPage(
browser()->tab_strip_model()->GetActiveWebContents(),
base::ASCIIToUTF16("ERR_EMPTY_RESPONSE"), true, true, nullptr,
nullptr),
1);
} }
// Navigate to a domain whose visual representation looks like a domain with a // Navigate to a domain whose visual representation looks like a domain with a
...@@ -1045,7 +990,7 @@ IN_PROC_BROWSER_TEST_F(LookalikeUrlInterstitialPageBrowserTest, ...@@ -1045,7 +990,7 @@ IN_PROC_BROWSER_TEST_F(LookalikeUrlInterstitialPageBrowserTest,
LoadAndCheckInterstitialAt(browser(), kNavigatedUrl); LoadAndCheckInterstitialAt(browser(), kNavigatedUrl);
} }
// Verify reloading the page does not result in dismissing an interstitial. // Verify reloading the page results in dismissing an interstitial.
// Regression test for crbug/941886. // Regression test for crbug/941886.
IN_PROC_BROWSER_TEST_F(LookalikeUrlInterstitialPageBrowserTest, IN_PROC_BROWSER_TEST_F(LookalikeUrlInterstitialPageBrowserTest,
RefreshDoesntDismiss) { RefreshDoesntDismiss) {
...@@ -1063,7 +1008,7 @@ IN_PROC_BROWSER_TEST_F(LookalikeUrlInterstitialPageBrowserTest, ...@@ -1063,7 +1008,7 @@ IN_PROC_BROWSER_TEST_F(LookalikeUrlInterstitialPageBrowserTest,
chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB);
navigation_observer.Wait(); navigation_observer.Wait();
EXPECT_EQ(LookalikeUrlInterstitialPage::kTypeForTesting, EXPECT_EQ(nullptr, GetInterstitialType(web_contents));
GetInterstitialType(web_contents)); EXPECT_TRUE(IsUrlShowing(browser()));
EXPECT_FALSE(IsUrlShowing(browser())); EXPECT_EQ(GetURL("example.com"), web_contents->GetURL());
} }
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