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

Side by Side Diff: components/security_state/core/security_state.cc

Issue 2917873004: Implement 'Not secure' warning for non-secure pages in Incognito mode (Closed)
Patch Set: Move console log to Navigation completion 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 "components/security_state/core/security_state.h" 5 #include "components/security_state/core/security_state.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string>
8 9
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/metrics/field_trial.h" 11 #include "base/metrics/field_trial.h"
11 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
12 #include "components/security_state/core/switches.h" 13 #include "components/security_state/core/switches.h"
13 #include "net/ssl/ssl_cipher_suite_names.h" 14 #include "net/ssl/ssl_cipher_suite_names.h"
14 #include "net/ssl/ssl_connection_status_flags.h" 15 #include "net/ssl/ssl_connection_status_flags.h"
15 16
16 namespace security_state { 17 namespace security_state {
17 18
18 namespace { 19 namespace {
19 20
20 // These values are written to logs. New enum values can be added, but existing 21 // These values are written to logs. New enum values can be added, but existing
21 // enums must never be renumbered or deleted and reused. 22 // enums must never be renumbered or deleted and reused.
22 enum MarkHttpStatus { 23 enum MarkHttpStatus {
23 NEUTRAL = 0, // Deprecated 24 NEUTRAL = 0, // Deprecated
24 NON_SECURE = 1, 25 NON_SECURE = 1,
25 HTTP_SHOW_WARNING_ON_SENSITIVE_FIELDS = 2, 26 HTTP_SHOW_WARNING_ON_SENSITIVE_FIELDS = 2,
26 NON_SECURE_AFTER_EDITING = 3, 27 NON_SECURE_AFTER_EDITING = 3,
27 NON_SECURE_WHILE_INCOGNITO = 4, 28 NON_SECURE_WHILE_INCOGNITO = 4,
28 NON_SECURE_WHILE_INCOGNITO_OR_EDITING = 5, 29 NON_SECURE_WHILE_INCOGNITO_OR_EDITING = 5,
29 LAST_STATUS 30 LAST_STATUS
30 }; 31 };
31 32
32 // If |switch_or_field_trial_group| corresponds to a valid 33 // If |switch_or_field_trial_group| corresponds to a valid
33 // MarkHttpAs group, sets |*level| and |*histogram_status| to the 34 // MarkHttpAs setting, sets |*level| and |*histogram_status| to the
34 // appropriate values and returns true. Otherwise, returns false. 35 // appropriate values and returns true. Otherwise, returns false.
35 bool GetSecurityLevelAndHistogramValueForNonSecureFieldTrial( 36 bool GetSecurityLevelAndHistogramValueForNonSecureFieldTrial(
36 std::string switch_or_field_trial_group, 37 std::string switch_or_field_trial_group,
37 bool displayed_sensitive_input_on_http, 38 bool displayed_sensitive_input_on_http,
39 bool is_incognito,
38 SecurityLevel* level, 40 SecurityLevel* level,
39 MarkHttpStatus* histogram_status) { 41 MarkHttpStatus* histogram_status) {
40 if (switch_or_field_trial_group != switches::kMarkHttpAsDangerous) 42 if (switch_or_field_trial_group ==
41 return false; 43 switches::kMarkHttpAsNonSecureWhileIncognito) {
42 *level = DANGEROUS; 44 *histogram_status = NON_SECURE_WHILE_INCOGNITO;
43 *histogram_status = NON_SECURE; 45 *level = (is_incognito || displayed_sensitive_input_on_http)
44 return true; 46 ? security_state::HTTP_SHOW_WARNING
47 : NONE;
48 return true;
49 }
50 if (switch_or_field_trial_group ==
51 switches::kMarkHttpAsNonSecureWhileIncognitoOrEditing) {
52 *histogram_status = NON_SECURE_WHILE_INCOGNITO_OR_EDITING;
53 *level = (is_incognito || displayed_sensitive_input_on_http)
54 ? security_state::HTTP_SHOW_WARNING
55 : NONE;
56 return true;
57 }
58 if (switch_or_field_trial_group == switches::kMarkHttpAsDangerous) {
59 *histogram_status = NON_SECURE;
60 *level = DANGEROUS;
61 return true;
62 }
63
64 return false;
45 } 65 }
46 66
47 SecurityLevel GetSecurityLevelForNonSecureFieldTrial( 67 SecurityLevel GetSecurityLevelForNonSecureFieldTrial(
48 bool displayed_sensitive_input_on_http) { 68 bool displayed_sensitive_input_on_http,
69 bool is_incognito) {
49 std::string choice = 70 std::string choice =
50 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 71 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
51 switches::kMarkHttpAs); 72 switches::kMarkHttpAs);
52 std::string group = base::FieldTrialList::FindFullName("MarkNonSecureAs"); 73 std::string group = base::FieldTrialList::FindFullName("MarkNonSecureAs");
53 74
54 const char kEnumeration[] = "SSL.MarkHttpAsStatus"; 75 const char kEnumeration[] = "SSL.MarkHttpAsStatus";
55 76
56 SecurityLevel level = NONE; 77 SecurityLevel level = NONE;
57 MarkHttpStatus status; 78 MarkHttpStatus status;
58 79
59 // If the command-line switch is set, then it takes precedence over 80 // If the command-line switch is set, then it takes precedence over
60 // the field trial group. 81 // the field trial group.
61 if (!GetSecurityLevelAndHistogramValueForNonSecureFieldTrial( 82 if (!GetSecurityLevelAndHistogramValueForNonSecureFieldTrial(
62 choice, displayed_sensitive_input_on_http, &level, &status)) { 83 choice, displayed_sensitive_input_on_http, is_incognito, &level,
84 &status)) {
63 if (!GetSecurityLevelAndHistogramValueForNonSecureFieldTrial( 85 if (!GetSecurityLevelAndHistogramValueForNonSecureFieldTrial(
64 group, displayed_sensitive_input_on_http, &level, &status)) { 86 group, displayed_sensitive_input_on_http, is_incognito, &level,
87 &status)) {
65 status = HTTP_SHOW_WARNING_ON_SENSITIVE_FIELDS; 88 status = HTTP_SHOW_WARNING_ON_SENSITIVE_FIELDS;
66 level = displayed_sensitive_input_on_http 89 level = displayed_sensitive_input_on_http
67 ? security_state::HTTP_SHOW_WARNING 90 ? security_state::HTTP_SHOW_WARNING
68 : NONE; 91 : NONE;
69 } 92 }
70 } 93 }
71 94
72 UMA_HISTOGRAM_ENUMERATION(kEnumeration, status, LAST_STATUS); 95 UMA_HISTOGRAM_ENUMERATION(kEnumeration, status, LAST_STATUS);
73 return level; 96 return level;
74 } 97 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 144
122 // Choose the appropriate security level for requests to HTTP and remaining 145 // Choose the appropriate security level for requests to HTTP and remaining
123 // pseudo URLs (blob:, filesystem:). filesystem: is a standard scheme so does 146 // pseudo URLs (blob:, filesystem:). filesystem: is a standard scheme so does
124 // not need to be explicitly listed here. 147 // not need to be explicitly listed here.
125 // TODO(meacer): Remove special case for blob (crbug.com/684751). 148 // TODO(meacer): Remove special case for blob (crbug.com/684751).
126 if (!is_cryptographic_with_certificate) { 149 if (!is_cryptographic_with_certificate) {
127 if (!is_origin_secure_callback.Run(url) && 150 if (!is_origin_secure_callback.Run(url) &&
128 (url.IsStandard() || url.SchemeIs(url::kBlobScheme))) { 151 (url.IsStandard() || url.SchemeIs(url::kBlobScheme))) {
129 return GetSecurityLevelForNonSecureFieldTrial( 152 return GetSecurityLevelForNonSecureFieldTrial(
130 visible_security_state.displayed_password_field_on_http || 153 visible_security_state.displayed_password_field_on_http ||
131 visible_security_state.displayed_credit_card_field_on_http); 154 visible_security_state.displayed_credit_card_field_on_http,
155 visible_security_state.is_incognito);
132 } 156 }
133 return NONE; 157 return NONE;
134 } 158 }
135 159
136 // Downgrade the security level for active insecure subresources. 160 // Downgrade the security level for active insecure subresources.
137 if (mixed_content_status == CONTENT_STATUS_RAN || 161 if (mixed_content_status == CONTENT_STATUS_RAN ||
138 mixed_content_status == CONTENT_STATUS_DISPLAYED_AND_RAN || 162 mixed_content_status == CONTENT_STATUS_DISPLAYED_AND_RAN ||
139 content_with_cert_errors_status == CONTENT_STATUS_RAN || 163 content_with_cert_errors_status == CONTENT_STATUS_RAN ||
140 content_with_cert_errors_status == CONTENT_STATUS_DISPLAYED_AND_RAN) { 164 content_with_cert_errors_status == CONTENT_STATUS_DISPLAYED_AND_RAN) {
141 return kRanInsecureContentLevel; 165 return kRanInsecureContentLevel;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 security_info->displayed_password_field_on_http = 247 security_info->displayed_password_field_on_http =
224 visible_security_state.displayed_password_field_on_http; 248 visible_security_state.displayed_password_field_on_http;
225 security_info->displayed_credit_card_field_on_http = 249 security_info->displayed_credit_card_field_on_http =
226 visible_security_state.displayed_credit_card_field_on_http; 250 visible_security_state.displayed_credit_card_field_on_http;
227 if (visible_security_state.certificate) { 251 if (visible_security_state.certificate) {
228 security_info->cert_missing_subject_alt_name = 252 security_info->cert_missing_subject_alt_name =
229 !visible_security_state.certificate->GetSubjectAltName(nullptr, 253 !visible_security_state.certificate->GetSubjectAltName(nullptr,
230 nullptr); 254 nullptr);
231 } 255 }
232 256
257 security_info->is_incognito = visible_security_state.is_incognito;
258
233 security_info->contained_mixed_form = 259 security_info->contained_mixed_form =
234 visible_security_state.contained_mixed_form; 260 visible_security_state.contained_mixed_form;
235 261
236 security_info->security_level = GetSecurityLevelForRequest( 262 security_info->security_level = GetSecurityLevelForRequest(
237 visible_security_state, used_policy_installed_certificate, 263 visible_security_state, used_policy_installed_certificate,
238 is_origin_secure_callback, security_info->sha1_in_chain, 264 is_origin_secure_callback, security_info->sha1_in_chain,
239 security_info->mixed_content_status, 265 security_info->mixed_content_status,
240 security_info->content_with_cert_errors_status); 266 security_info->content_with_cert_errors_status);
241 } 267 }
242 268
243 } // namespace 269 } // namespace
244 270
271 bool IsHttpWarningForIncognitoEnabled() {
272 std::string choice =
273 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
274 switches::kMarkHttpAs);
275 std::string group = base::FieldTrialList::FindFullName("MarkNonSecureAs");
276 SecurityLevel level = NONE;
277 MarkHttpStatus status;
278
279 // If the command-line switch is set, then it takes precedence over
280 // the field trial group.
281 if (!GetSecurityLevelAndHistogramValueForNonSecureFieldTrial(
282 choice, false, true, &level, &status)) {
283 if (!GetSecurityLevelAndHistogramValueForNonSecureFieldTrial(
284 group, false, true, &level, &status)) {
285 return false;
286 }
287 }
288
289 return (status == NON_SECURE_WHILE_INCOGNITO ||
290 status == NON_SECURE_WHILE_INCOGNITO_OR_EDITING);
291 }
292
245 const base::Feature kHttpFormWarningFeature{"HttpFormWarning", 293 const base::Feature kHttpFormWarningFeature{"HttpFormWarning",
246 base::FEATURE_DISABLED_BY_DEFAULT}; 294 base::FEATURE_DISABLED_BY_DEFAULT};
247 295
248 SecurityInfo::SecurityInfo() 296 SecurityInfo::SecurityInfo()
249 : security_level(NONE), 297 : security_level(NONE),
250 malicious_content_status(MALICIOUS_CONTENT_STATUS_NONE), 298 malicious_content_status(MALICIOUS_CONTENT_STATUS_NONE),
251 sha1_in_chain(false), 299 sha1_in_chain(false),
252 mixed_content_status(CONTENT_STATUS_NONE), 300 mixed_content_status(CONTENT_STATUS_NONE),
253 content_with_cert_errors_status(CONTENT_STATUS_NONE), 301 content_with_cert_errors_status(CONTENT_STATUS_NONE),
254 scheme_is_cryptographic(false), 302 scheme_is_cryptographic(false),
255 cert_status(0), 303 cert_status(0),
256 security_bits(-1), 304 security_bits(-1),
257 connection_status(0), 305 connection_status(0),
258 key_exchange_group(0), 306 key_exchange_group(0),
259 obsolete_ssl_status(net::OBSOLETE_SSL_NONE), 307 obsolete_ssl_status(net::OBSOLETE_SSL_NONE),
260 pkp_bypassed(false), 308 pkp_bypassed(false),
261 displayed_password_field_on_http(false), 309 displayed_password_field_on_http(false),
262 displayed_credit_card_field_on_http(false), 310 displayed_credit_card_field_on_http(false),
263 contained_mixed_form(false), 311 contained_mixed_form(false),
264 cert_missing_subject_alt_name(false) {} 312 cert_missing_subject_alt_name(false),
313 is_incognito(false) {}
265 314
266 SecurityInfo::~SecurityInfo() {} 315 SecurityInfo::~SecurityInfo() {}
267 316
268 void GetSecurityInfo( 317 void GetSecurityInfo(
269 std::unique_ptr<VisibleSecurityState> visible_security_state, 318 std::unique_ptr<VisibleSecurityState> visible_security_state,
270 bool used_policy_installed_certificate, 319 bool used_policy_installed_certificate,
271 IsOriginSecureCallback is_origin_secure_callback, 320 IsOriginSecureCallback is_origin_secure_callback,
272 SecurityInfo* result) { 321 SecurityInfo* result) {
273 SecurityInfoForRequest(*visible_security_state, 322 SecurityInfoForRequest(*visible_security_state,
274 used_policy_installed_certificate, 323 used_policy_installed_certificate,
(...skipping 11 matching lines...) Expand all
286 connection_status(0), 335 connection_status(0),
287 key_exchange_group(0), 336 key_exchange_group(0),
288 security_bits(-1), 337 security_bits(-1),
289 displayed_mixed_content(false), 338 displayed_mixed_content(false),
290 contained_mixed_form(false), 339 contained_mixed_form(false),
291 ran_mixed_content(false), 340 ran_mixed_content(false),
292 displayed_content_with_cert_errors(false), 341 displayed_content_with_cert_errors(false),
293 ran_content_with_cert_errors(false), 342 ran_content_with_cert_errors(false),
294 pkp_bypassed(false), 343 pkp_bypassed(false),
295 displayed_password_field_on_http(false), 344 displayed_password_field_on_http(false),
296 displayed_credit_card_field_on_http(false) {} 345 displayed_credit_card_field_on_http(false),
346 is_incognito(false) {}
297 347
298 VisibleSecurityState::~VisibleSecurityState() {} 348 VisibleSecurityState::~VisibleSecurityState() {}
299 349
300 bool VisibleSecurityState::operator==(const VisibleSecurityState& other) const { 350 bool VisibleSecurityState::operator==(const VisibleSecurityState& other) const {
301 return (url == other.url && 351 return (url == other.url &&
302 malicious_content_status == other.malicious_content_status && 352 malicious_content_status == other.malicious_content_status &&
303 !!certificate == !!other.certificate && 353 !!certificate == !!other.certificate &&
304 (certificate ? certificate->Equals(other.certificate.get()) : true) && 354 (certificate ? certificate->Equals(other.certificate.get()) : true) &&
305 connection_status == other.connection_status && 355 connection_status == other.connection_status &&
306 key_exchange_group == other.key_exchange_group && 356 key_exchange_group == other.key_exchange_group &&
307 security_bits == other.security_bits && 357 security_bits == other.security_bits &&
308 displayed_mixed_content == other.displayed_mixed_content && 358 displayed_mixed_content == other.displayed_mixed_content &&
309 ran_mixed_content == other.ran_mixed_content && 359 ran_mixed_content == other.ran_mixed_content &&
310 displayed_content_with_cert_errors == 360 displayed_content_with_cert_errors ==
311 other.displayed_content_with_cert_errors && 361 other.displayed_content_with_cert_errors &&
312 ran_content_with_cert_errors == other.ran_content_with_cert_errors && 362 ran_content_with_cert_errors == other.ran_content_with_cert_errors &&
313 pkp_bypassed == other.pkp_bypassed && 363 pkp_bypassed == other.pkp_bypassed &&
314 displayed_password_field_on_http == 364 displayed_password_field_on_http ==
315 other.displayed_password_field_on_http && 365 other.displayed_password_field_on_http &&
316 displayed_credit_card_field_on_http == 366 displayed_credit_card_field_on_http ==
317 other.displayed_credit_card_field_on_http && 367 other.displayed_credit_card_field_on_http &&
318 contained_mixed_form == other.contained_mixed_form); 368 contained_mixed_form == other.contained_mixed_form &&
369 is_incognito == other.is_incognito);
319 } 370 }
320 371
321 } // namespace security_state 372 } // namespace security_state
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698