Commit b9059764 authored by Carlos IL's avatar Carlos IL Committed by Commit Bot

Omnibox no longer shows secure for view-source urls

Added is_view_source boolean to VisibleSecurityState.
GetSecurityLevelForRequest now checks that flag and returns 'NONE' for
pages that would return SECURE or EV_SECURE without the flag.
Added tests that validate the new behavior

Bug: 712482
Change-Id: Ic23c20ffdb92262987dae2119148932cb9d187a6
Reviewed-on: https://chromium-review.googlesource.com/773218
Commit-Queue: Carlos IL <carlosil@chromium.org>
Reviewed-by: default avatarEric Lawrence <elawrence@chromium.org>
Reviewed-by: default avatarEmily Stark <estark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517886}
parent 761d0bcb
......@@ -20,6 +20,7 @@
#include "content/public/browser/security_style_explanations.h"
#include "content/public/browser/ssl_status.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "net/base/net_errors.h"
#include "net/cert/x509_certificate.h"
#include "net/ssl/ssl_cipher_suite_names.h"
......@@ -362,13 +363,17 @@ std::unique_ptr<security_state::VisibleSecurityState> GetVisibleSecurityState(
content::NavigationEntry* entry =
web_contents->GetController().GetVisibleEntry();
state->is_error_page =
entry && (entry->GetPageType() == content::PAGE_TYPE_ERROR);
if (!entry || !entry->GetSSL().initialized)
if (!entry)
return state;
// Set fields that are not dependent on the connection info.
state->is_error_page = entry->GetPageType() == content::PAGE_TYPE_ERROR;
state->is_view_source =
entry->GetVirtualURL().SchemeIs(content::kViewSourceScheme);
state->url = entry->GetURL();
if (!entry->GetSSL().initialized)
return state;
state->connection_info_initialized = true;
state->url = entry->GetURL();
const content::SSLStatus& ssl = entry->GetSSL();
state->certificate = ssl.certificate;
state->cert_status = ssl.cert_status;
......
......@@ -185,6 +185,10 @@ SecurityLevel GetSecurityLevelForRequest(
return NONE;
}
if (visible_security_state.is_view_source) {
return NONE;
}
if ((visible_security_state.cert_status & net::CERT_STATUS_IS_EV) &&
visible_security_state.certificate) {
return EV_SECURE;
......@@ -320,7 +324,8 @@ VisibleSecurityState::VisibleSecurityState()
ran_content_with_cert_errors(false),
pkp_bypassed(false),
is_incognito(false),
is_error_page(false) {}
is_error_page(false),
is_view_source(false) {}
VisibleSecurityState::~VisibleSecurityState() {}
......
......@@ -189,6 +189,8 @@ struct VisibleSecurityState {
// True if the page was an error page.
// TODO(estark): this field is not populated on iOS. https://crbug.com/760647
bool is_error_page;
// True if the page is a view-source page.
bool is_view_source;
// Contains information about input events that may impact the security
// level of the page.
InsecureInputEventData insecure_input_events;
......
......@@ -57,7 +57,9 @@ class TestSecurityStateHelper {
ran_mixed_content_(false),
malicious_content_status_(MALICIOUS_CONTENT_STATUS_NONE),
is_incognito_(false),
is_error_page_(false) {}
is_error_page_(false),
is_view_source_(false) {}
virtual ~TestSecurityStateHelper() {}
void SetCertificate(scoped_refptr<net::X509Certificate> cert) {
......@@ -72,6 +74,9 @@ class TestSecurityStateHelper {
void AddCertStatus(net::CertStatus cert_status) {
cert_status_ |= cert_status;
}
void set_cert_status(net::CertStatus cert_status) {
cert_status_ = cert_status;
}
void set_displayed_mixed_content(bool displayed_mixed_content) {
displayed_mixed_content_ = displayed_mixed_content;
}
......@@ -95,6 +100,10 @@ class TestSecurityStateHelper {
void set_is_error_page(bool is_error_page) { is_error_page_ = is_error_page; }
void set_is_view_source(bool is_view_source) {
is_view_source_ = is_view_source;
}
void set_insecure_field_edit(bool insecure_field_edit) {
insecure_input_events_.insecure_field_edited = insecure_field_edit;
}
......@@ -115,6 +124,7 @@ class TestSecurityStateHelper {
state->malicious_content_status = malicious_content_status_;
state->is_incognito = is_incognito_;
state->is_error_page = is_error_page_;
state->is_view_source = is_view_source_;
state->insecure_input_events = insecure_input_events_;
return state;
}
......@@ -137,6 +147,7 @@ class TestSecurityStateHelper {
MaliciousContentStatus malicious_content_status_;
bool is_incognito_;
bool is_error_page_;
bool is_view_source_;
InsecureInputEventData insecure_input_events_;
};
......@@ -381,6 +392,32 @@ TEST(SecurityStateTest, PrivateUserDataNotSetOnPseudoUrls) {
}
}
// Tests that if |is_view_source| NONE is returned for a secure site.
TEST(SecurityStateTest, ViewSourceRemovesSecure) {
TestSecurityStateHelper helper;
SecurityInfo security_info;
helper.set_cert_status(0);
helper.GetSecurityInfo(&security_info);
EXPECT_EQ(SECURE, security_info.security_level);
helper.set_is_view_source(true);
helper.GetSecurityInfo(&security_info);
EXPECT_EQ(NONE, security_info.security_level);
}
// Tests that if |is_view_source|, DANGEROUS is still returned for a site
// flagged by SafeBrowsing.
TEST(SecurityStateTest, ViewSourceKeepsWarning) {
TestSecurityStateHelper helper;
helper.set_malicious_content_status(
MALICIOUS_CONTENT_STATUS_SOCIAL_ENGINEERING);
helper.set_is_view_source(true);
SecurityInfo security_info;
helper.GetSecurityInfo(&security_info);
EXPECT_EQ(MALICIOUS_CONTENT_STATUS_SOCIAL_ENGINEERING,
security_info.malicious_content_status);
EXPECT_EQ(DANGEROUS, security_info.security_level);
}
// Tests that |incognito_downgraded_security_level| is set only when the
// corresponding VisibleSecurityState flag is set and the HTTPBad Phase 2
// experiment is enabled.
......
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