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

Side by Side Diff: components/autofill/content/renderer/password_form_conversion_utils.cc

Issue 2874803002: Prevent autofilling credit card security number fields with passwords. (Closed)
Patch Set: Created 3 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/autofill/content/renderer/password_form_conversion_utils.h" 5 #include "components/autofill/content/renderer/password_form_conversion_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
11 11
12 #include "base/i18n/case_conversion.h" 12 #include "base/i18n/case_conversion.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
18 #include "base/strings/string_split.h" 18 #include "base/strings/string_split.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "components/autofill/content/renderer/form_autofill_util.h" 21 #include "components/autofill/content/renderer/form_autofill_util.h"
22 #include "components/autofill/core/common/autofill_regex_constants.h"
23 #include "components/autofill/core/common/autofill_regexes.h"
22 #include "components/autofill/core/common/autofill_util.h" 24 #include "components/autofill/core/common/autofill_util.h"
23 #include "components/autofill/core/common/password_form.h" 25 #include "components/autofill/core/common/password_form.h"
24 #include "components/autofill/core/common/password_form_field_prediction_map.h" 26 #include "components/autofill/core/common/password_form_field_prediction_map.h"
25 #include "google_apis/gaia/gaia_urls.h" 27 #include "google_apis/gaia/gaia_urls.h"
26 #include "third_party/WebKit/public/platform/WebString.h" 28 #include "third_party/WebKit/public/platform/WebString.h"
27 #include "third_party/WebKit/public/platform/WebVector.h" 29 #include "third_party/WebKit/public/platform/WebVector.h"
28 #include "third_party/WebKit/public/web/WebDocument.h" 30 #include "third_party/WebKit/public/web/WebDocument.h"
29 #include "third_party/WebKit/public/web/WebFormControlElement.h" 31 #include "third_party/WebKit/public/web/WebFormControlElement.h"
30 #include "third_party/WebKit/public/web/WebFrame.h" 32 #include "third_party/WebKit/public/web/WebFrame.h"
31 #include "third_party/WebKit/public/web/WebInputElement.h" 33 #include "third_party/WebKit/public/web/WebInputElement.h"
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 size_t number_of_non_empty_text_non_password_fields = 0; 424 size_t number_of_non_empty_text_non_password_fields = 0;
423 for (size_t i = 0; i < form.control_elements.size(); ++i) { 425 for (size_t i = 0; i < form.control_elements.size(); ++i) {
424 WebFormControlElement control_element = form.control_elements[i]; 426 WebFormControlElement control_element = form.control_elements[i];
425 427
426 WebInputElement* input_element = ToWebInputElement(&control_element); 428 WebInputElement* input_element = ToWebInputElement(&control_element);
427 if (!input_element || !input_element->IsEnabled()) 429 if (!input_element || !input_element->IsEnabled())
428 continue; 430 continue;
429 431
430 if (HasCreditCardAutocompleteAttributes(*input_element)) 432 if (HasCreditCardAutocompleteAttributes(*input_element))
431 continue; 433 continue;
434 if (IsCreditCardVerificationField(*input_element))
435 continue;
432 436
433 bool element_is_invisible = !form_util::IsWebElementVisible(*input_element); 437 bool element_is_invisible = !form_util::IsWebElementVisible(*input_element);
434 if (input_element->IsTextField()) { 438 if (input_element->IsTextField()) {
435 if (input_element->IsPasswordField()) { 439 if (input_element->IsPasswordField()) {
436 if (element_is_invisible && ignore_invisible_passwords) 440 if (element_is_invisible && ignore_invisible_passwords)
437 continue; 441 continue;
438 layout_sequence.push_back('P'); 442 layout_sequence.push_back('P');
439 } else { 443 } else {
440 if (FieldHasNonscriptModifiedValue(field_value_and_properties_map, 444 if (FieldHasNonscriptModifiedValue(field_value_and_properties_map,
441 *input_element)) 445 *input_element))
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 autocomplete_value_lowercase, base::kWhitespaceASCII, 763 autocomplete_value_lowercase, base::kWhitespaceASCII,
760 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { 764 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
761 if (base::StartsWith(token, kAutocompleteCreditCardPrefix, 765 if (base::StartsWith(token, kAutocompleteCreditCardPrefix,
762 base::CompareCase::SENSITIVE)) { 766 base::CompareCase::SENSITIVE)) {
763 return true; 767 return true;
764 } 768 }
765 } 769 }
766 return false; 770 return false;
767 } 771 }
768 772
773 bool IsCreditCardVerificationField(const blink::WebInputElement& field) {
Mathieu 2017/05/11 12:54:03 IsCreditCardVerificationAndPasswordField?
pkalinnikov 2017/05/11 14:03:07 I think it looks better without "And". WDYT?
Mathieu 2017/05/11 15:40:08 The logic of this function is "returns true if the
pkalinnikov 2017/05/12 08:42:05 Done in patch#2.
774 if (!field.IsPasswordField())
775 return false;
776
777 static const base::string16 kCardCvcReCached = base::UTF8ToUTF16(kCardCvcRe);
dvadym 2017/05/11 11:46:53 Probably it makes sense to use another regexps for
Mathieu 2017/05/11 12:54:03 We've really only seen this problem with CVC field
dvadym 2017/05/11 14:27:51 I didn't see any other type for password fields. B
Mathieu 2017/05/11 15:40:08 Text fields that would be type=password and contai
dvadym 2017/05/11 15:50:18 I mean type=text, i.e. to expand this function to
778
779 return MatchesPattern(field.GetAttribute("id").Utf16(), kCardCvcReCached) ||
Mathieu 2017/05/11 12:54:04 I'm pretty sure this will cache the patterns, so i
pkalinnikov 2017/05/11 14:03:07 Can you elaborate on what you mean by "this will c
Mathieu 2017/05/11 15:40:08 you can do UTF8ToUTF16(kCardCvcRe), no? That's wha
pkalinnikov 2017/05/12 08:42:05 Well, I do the same. But instead of storing the va
Mathieu 2017/05/12 12:24:44 Can you file a bug for the general behavior you de
pkalinnikov 2017/05/12 14:48:21 Will do.
780 MatchesPattern(field.GetAttribute("name").Utf16(), kCardCvcReCached);
781 }
782
769 } // namespace autofill 783 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698