Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1179)

Side by Side Diff: chrome/browser/ssl/security_state_tab_helper.cc

Issue 2917873004: Implement 'Not secure' warning for non-secure pages in Incognito mode (Closed)
Patch Set: Ensure sensitive fields trigger warnings outside of Incognito Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ssl/security_state_tab_helper.h" 5 #include "chrome/browser/ssl/security_state_tab_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 13 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
14 #include "chrome/browser/safe_browsing/ui_manager.h" 14 #include "chrome/browser/safe_browsing/ui_manager.h"
15 #include "components/prefs/pref_service.h" 15 #include "components/prefs/pref_service.h"
16 #include "components/security_state/content/content_utils.h" 16 #include "components/security_state/content/content_utils.h"
17 #include "components/ssl_config/ssl_config_prefs.h" 17 #include "components/ssl_config/ssl_config_prefs.h"
18 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/navigation_entry.h" 19 #include "content/public/browser/navigation_entry.h"
19 #include "content/public/browser/navigation_handle.h" 20 #include "content/public/browser/navigation_handle.h"
20 #include "content/public/browser/render_frame_host.h" 21 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
22 #include "content/public/common/origin_util.h" 23 #include "content/public/common/origin_util.h"
23 #include "net/base/net_errors.h" 24 #include "net/base/net_errors.h"
24 #include "net/cert/x509_certificate.h" 25 #include "net/cert/x509_certificate.h"
25 #include "net/ssl/ssl_cipher_suite_names.h" 26 #include "net/ssl/ssl_cipher_suite_names.h"
26 #include "net/ssl/ssl_connection_status_flags.h" 27 #include "net/ssl/ssl_connection_status_flags.h"
27 #include "third_party/boringssl/src/include/openssl/ssl.h" 28 #include "third_party/boringssl/src/include/openssl/ssl.h"
28 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
29 30
30 #if defined(OS_CHROMEOS) 31 #if defined(OS_CHROMEOS)
31 #include "chrome/browser/chromeos/policy/policy_cert_service.h" 32 #include "chrome/browser/chromeos/policy/policy_cert_service.h"
32 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" 33 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
33 #endif // defined(OS_CHROMEOS) 34 #endif // defined(OS_CHROMEOS)
34 35
35 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SecurityStateTabHelper); 36 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SecurityStateTabHelper);
36 37
37 using safe_browsing::SafeBrowsingUIManager; 38 using safe_browsing::SafeBrowsingUIManager;
38 39
39 SecurityStateTabHelper::SecurityStateTabHelper( 40 SecurityStateTabHelper::SecurityStateTabHelper(
40 content::WebContents* web_contents) 41 content::WebContents* web_contents)
41 : content::WebContentsObserver(web_contents), 42 : content::WebContentsObserver(web_contents),
43 logged_incognito_warning_on_current_navigation_(false),
42 logged_http_warning_on_current_navigation_(false) {} 44 logged_http_warning_on_current_navigation_(false) {}
43 45
44 SecurityStateTabHelper::~SecurityStateTabHelper() {} 46 SecurityStateTabHelper::~SecurityStateTabHelper() {}
45 47
46 void SecurityStateTabHelper::GetSecurityInfo( 48 void SecurityStateTabHelper::GetSecurityInfo(
47 security_state::SecurityInfo* result) const { 49 security_state::SecurityInfo* result) const {
48 security_state::GetSecurityInfo(GetVisibleSecurityState(), 50 security_state::GetSecurityInfo(GetVisibleSecurityState(),
49 UsedPolicyInstalledCertificate(), 51 UsedPolicyInstalledCertificate(),
50 base::Bind(&content::IsOriginSecure), result); 52 base::Bind(&content::IsOriginSecure), result);
51 } 53 }
52 54
53 void SecurityStateTabHelper::VisibleSecurityStateChanged() { 55 void SecurityStateTabHelper::VisibleSecurityStateChanged() {
54 if (logged_http_warning_on_current_navigation_) 56 if (logged_incognito_warning_on_current_navigation_ &&
57 logged_http_warning_on_current_navigation_) {
55 return; 58 return;
59 }
56 60
57 security_state::SecurityInfo security_info; 61 security_state::SecurityInfo security_info;
58 GetSecurityInfo(&security_info); 62 GetSecurityInfo(&security_info);
59 if (!security_info.displayed_password_field_on_http && 63
60 !security_info.displayed_credit_card_field_on_http) { 64 if (!logged_incognito_warning_on_current_navigation_ &&
65 security_info.is_incognito &&
66 security_info.security_level == security_state::HTTP_SHOW_WARNING) {
67 logged_incognito_warning_on_current_navigation_ = true;
68
69 web_contents()->GetMainFrame()->AddMessageToConsole(
70 content::CONSOLE_MESSAGE_LEVEL_WARNING,
71 "This page was loaded non-securely in an incognito mode browser. A "
72 "warning has been added to the URL bar. For more information, see "
73 "https://goo.gl/y8SRRv.");
74 }
75
76 if (logged_http_warning_on_current_navigation_ ||
77 (!security_info.displayed_password_field_on_http &&
78 !security_info.displayed_credit_card_field_on_http)) {
61 return; 79 return;
62 } 80 }
63 81
64 DCHECK(time_of_http_warning_on_current_navigation_.is_null()); 82 DCHECK(time_of_http_warning_on_current_navigation_.is_null());
65 time_of_http_warning_on_current_navigation_ = base::Time::Now(); 83 time_of_http_warning_on_current_navigation_ = base::Time::Now();
66 84
67 logged_http_warning_on_current_navigation_ = true; 85 logged_http_warning_on_current_navigation_ = true;
68 web_contents()->GetMainFrame()->AddMessageToConsole( 86 web_contents()->GetMainFrame()->AddMessageToConsole(
69 content::CONSOLE_MESSAGE_LEVEL_WARNING, 87 content::CONSOLE_MESSAGE_LEVEL_WARNING,
70 "This page includes a password or credit card input in a non-secure " 88 "This page includes a password or credit card input in a non-secure "
(...skipping 14 matching lines...) Expand all
85 } 103 }
86 if (security_info.displayed_password_field_on_http) { 104 if (security_info.displayed_password_field_on_http) {
87 UMA_HISTOGRAM_BOOLEAN( 105 UMA_HISTOGRAM_BOOLEAN(
88 "Security.HTTPBad.UserWarnedAboutSensitiveInput.Password", 106 "Security.HTTPBad.UserWarnedAboutSensitiveInput.Password",
89 warning_is_user_visible); 107 warning_is_user_visible);
90 } 108 }
91 } 109 }
92 110
93 void SecurityStateTabHelper::DidStartNavigation( 111 void SecurityStateTabHelper::DidStartNavigation(
94 content::NavigationHandle* navigation_handle) { 112 content::NavigationHandle* navigation_handle) {
95 if (time_of_http_warning_on_current_navigation_.is_null() || 113 if (!navigation_handle->IsInMainFrame() ||
96 !navigation_handle->IsInMainFrame() ||
97 navigation_handle->IsSameDocument()) { 114 navigation_handle->IsSameDocument()) {
98 return; 115 return;
99 } 116 }
117
118 logged_incognito_warning_on_current_navigation_ = false;
119
120 if (time_of_http_warning_on_current_navigation_.is_null())
121 return;
100 // Record how quickly a user leaves a site after encountering an 122 // Record how quickly a user leaves a site after encountering an
101 // HTTP-bad warning. A navigation here only counts if it is a 123 // HTTP-bad warning. A navigation here only counts if it is a
102 // main-frame, not-same-page navigation, since it aims to measure how 124 // main-frame, not-same-page navigation, since it aims to measure how
103 // quickly a user leaves a site after seeing the HTTP warning. 125 // quickly a user leaves a site after seeing the HTTP warning.
104 UMA_HISTOGRAM_LONG_TIMES( 126 UMA_HISTOGRAM_LONG_TIMES(
105 "Security.HTTPBad.NavigationStartedAfterUserWarnedAboutSensitiveInput", 127 "Security.HTTPBad.NavigationStartedAfterUserWarnedAboutSensitiveInput",
106 base::Time::Now() - time_of_http_warning_on_current_navigation_); 128 base::Time::Now() - time_of_http_warning_on_current_navigation_);
107 // After recording the histogram, clear the time of the warning. A 129 // After recording the histogram, clear the time of the warning. A
108 // timing histogram will not be recorded again on this page, because 130 // timing histogram will not be recorded again on this page, because
109 // the time is only set the first time the HTTP-bad warning is shown 131 // the time is only set the first time the HTTP-bad warning is shown
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 214 }
193 215
194 std::unique_ptr<security_state::VisibleSecurityState> 216 std::unique_ptr<security_state::VisibleSecurityState>
195 SecurityStateTabHelper::GetVisibleSecurityState() const { 217 SecurityStateTabHelper::GetVisibleSecurityState() const {
196 auto state = security_state::GetVisibleSecurityState(web_contents()); 218 auto state = security_state::GetVisibleSecurityState(web_contents());
197 219
198 // Malware status might already be known even if connection security 220 // Malware status might already be known even if connection security
199 // information is still being initialized, thus no need to check for that. 221 // information is still being initialized, thus no need to check for that.
200 state->malicious_content_status = GetMaliciousContentStatus(); 222 state->malicious_content_status = GetMaliciousContentStatus();
201 223
224 if (!state->certificate &&
225 security_state::IsHttpWarningForIncognitoEnabled()) {
226 content::BrowserContext* context = web_contents()->GetBrowserContext();
227 if (context->IsOffTheRecord() &&
228 !Profile::FromBrowserContext(context)->IsGuestSession()) {
229 state->is_incognito = true;
230 }
231 }
202 return state; 232 return state;
203 } 233 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698