Commit 77a3bfab authored by mattm@chromium.org's avatar mattm@chromium.org

SafeBrowsing DownloadProtectionService: only check final URL against whitelist.

BUG=none

Review URL: https://codereview.chromium.org/166223004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251545 0039d316-1c4b-4281-b951-d872f2087c98
parent 4b46522f
...@@ -570,21 +570,10 @@ class DownloadProtectionService::CheckClientDownloadRequest ...@@ -570,21 +570,10 @@ class DownloadProtectionService::CheckClientDownloadRequest
if (!database_manager_.get()) { if (!database_manager_.get()) {
reason = REASON_SB_DISABLED; reason = REASON_SB_DISABLED;
} else { } else {
for (size_t i = 0; i < url_chain_.size(); ++i) { const GURL& url = url_chain_.back();
const GURL& url = url_chain_[i]; if (url.is_valid() && database_manager_->MatchDownloadWhitelistUrl(url)) {
if (url.is_valid() && VLOG(2) << url << " is on the download whitelist.";
database_manager_->MatchDownloadWhitelistUrl(url)) { reason = REASON_WHITELISTED_URL;
VLOG(2) << url << " is on the download whitelist.";
reason = REASON_WHITELISTED_URL;
break;
}
}
if (referrer_url_.is_valid() && reason == REASON_MAX &&
database_manager_->MatchDownloadWhitelistUrl(
referrer_url_)) {
VLOG(2) << "Referrer url " << referrer_url_
<< " is on the download whitelist.";
reason = REASON_WHITELISTED_REFERRER;
} }
if (reason != REASON_MAX || signature_info_.trusted()) { if (reason != REASON_MAX || signature_info_.trusted()) {
UMA_HISTOGRAM_COUNTS("SBClientDownload.SignedOrWhitelistedDownload", 1); UMA_HISTOGRAM_COUNTS("SBClientDownload.SignedOrWhitelistedDownload", 1);
......
...@@ -138,6 +138,8 @@ class DownloadProtectionService { ...@@ -138,6 +138,8 @@ class DownloadProtectionService {
private: private:
class CheckClientDownloadRequest; // Per-request state class CheckClientDownloadRequest; // Per-request state
friend class DownloadProtectionServiceTest; friend class DownloadProtectionServiceTest;
FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest,
CheckClientDownloadWhitelistedUrl);
FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest,
CheckClientDownloadValidateRequest); CheckClientDownloadValidateRequest);
FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest, FRIEND_TEST_ALL_PREFIXES(DownloadProtectionServiceTest,
......
...@@ -357,38 +357,85 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) { ...@@ -357,38 +357,85 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) {
} }
TEST_F(DownloadProtectionServiceTest, CheckClientDownloadWhitelistedUrl) { TEST_F(DownloadProtectionServiceTest, CheckClientDownloadWhitelistedUrl) {
// Response to any requests will be DANGEROUS.
ClientDownloadResponse response;
response.set_verdict(ClientDownloadResponse::DANGEROUS);
net::FakeURLFetcherFactory factory(NULL);
factory.SetFakeResponse(
DownloadProtectionService::GetDownloadRequestUrl(),
response.SerializeAsString(),
net::HTTP_OK, net::URLRequestStatus::SUCCESS);
std::string hash = "hash";
base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp"));
base::FilePath a_exe(FILE_PATH_LITERAL("a.exe")); base::FilePath a_exe(FILE_PATH_LITERAL("a.exe"));
std::vector<GURL> url_chain; std::vector<GURL> url_chain;
url_chain.push_back(GURL("http://www.evil.com/bla.exe")); GURL referrer;
url_chain.push_back(GURL("http://www.google.com/a.exe"));
GURL referrer("http://www.google.com/");
content::MockDownloadItem item; content::MockDownloadItem item;
EXPECT_CALL(item, AddObserver(_)).Times(2); EXPECT_CALL(item, AddObserver(_)).Times(4);
EXPECT_CALL(item, RemoveObserver(_)).Times(2); EXPECT_CALL(item, RemoveObserver(_)).Times(4);
EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp)); EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp));
EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe)); EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe));
EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(""));
EXPECT_CALL(*signature_util_.get(), CheckSignature(a_tmp, _)).Times(4);
// We should not get whilelist checks for other URLs than specified below.
EXPECT_CALL(*sb_service_->mock_database_manager(), EXPECT_CALL(*sb_service_->mock_database_manager(),
MatchDownloadWhitelistUrl(_)) MatchDownloadWhitelistUrl(_)).Times(0);
EXPECT_CALL(*sb_service_->mock_database_manager(),
MatchDownloadWhitelistUrl(GURL("http://www.evil.com/bla.exe")))
.WillRepeatedly(Return(false)); .WillRepeatedly(Return(false));
EXPECT_CALL(*sb_service_->mock_database_manager(), EXPECT_CALL(*sb_service_->mock_database_manager(),
MatchDownloadWhitelistUrl(GURL("http://www.google.com/a.exe"))) MatchDownloadWhitelistUrl(GURL("http://www.google.com/a.exe")))
.WillRepeatedly(Return(true)); .WillRepeatedly(Return(true));
EXPECT_CALL(*signature_util_.get(), CheckSignature(a_tmp, _)).Times(2);
// With no referrer and just the bad url, should be marked DANGEROUS.
url_chain.push_back(GURL("http://www.evil.com/bla.exe"));
download_service_->CheckClientDownload( download_service_->CheckClientDownload(
&item, &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this))); base::Unretained(this)));
MessageLoop::current()->Run(); MessageLoop::current()->Run();
#if defined(OS_WIN)
EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
#else
EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
#endif
// Check that the referrer is matched against the whitelist. // Check that the referrer is not matched against the whitelist.
url_chain.pop_back(); referrer = GURL("http://www.google.com/");
referrer = GURL("http://www.google.com/a.exe"); download_service_->CheckClientDownload(
&item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
MessageLoop::current()->Run();
#if defined(OS_WIN)
EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
#else
EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
#endif
// Redirect from a site shouldn't be checked either.
url_chain.insert(url_chain.begin(), GURL("http://www.google.com/redirect"));
download_service_->CheckClientDownload(
&item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
MessageLoop::current()->Run();
#if defined(OS_WIN)
EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
#else
EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
#endif
// Only if the final url is whitelisted should it be SAFE.
url_chain.push_back(GURL("http://www.google.com/a.exe"));
download_service_->CheckClientDownload( download_service_->CheckClientDownload(
&item, &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
......
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