OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/autofill/core/common/autofill_data_sanitizer.h" | |
6 | |
7 #include "components/autofill/core/common/form_data.h" | |
8 #include "components/autofill/core/common/form_field_data.h" | |
9 #include "components/autofill/core/common/password_form_fill_data.h" | |
10 #include "url/gurl.h" | |
11 | |
12 namespace autofill { | |
13 | |
14 // Constants to enforce data size caps, so as to avoid sending overly large | |
palmer
2013/12/20 19:53:36
Nit: Don't need to repeat these comments from the
Ilya Sherman
2013/12/20 23:54:52
Whoops, copy/pasta. Done.
| |
15 // messages over IPC: | |
16 | |
17 // The maximum string size supported by Autofill. | |
18 const size_t kMaxDataLength = 1024; | |
palmer
2013/12/20 19:53:36
If you find in the future that you need to increas
Ilya Sherman
2013/12/20 23:54:52
Ack.
| |
19 | |
20 // The maximum list size supported by Autofill. | |
21 const size_t kMaxListSize = 256; | |
22 | |
23 bool IsSanitizedString(const std::string& str) { | |
palmer
2013/12/20 19:53:36
FYI: "Sanitized" often means *transformed* in some
Ilya Sherman
2013/12/20 23:54:52
Done.
| |
24 return str.size() <= kMaxDataLength; | |
25 } | |
26 | |
27 bool IsSanitizedString16(const base::string16& str) { | |
28 return str.size() <= kMaxDataLength; | |
29 } | |
30 | |
31 bool IsSanitizedGURL(const GURL& url) { | |
32 return url.is_valid() && url.spec().size() <= kMaxDataLength; | |
palmer
2013/12/20 19:53:36
By doing this, you are in effect asserting a limit
Ilya Sherman
2013/12/20 23:54:52
Ack.
| |
33 } | |
34 | |
35 bool IsSanitizedFormFieldData(const FormFieldData& field) { | |
36 return | |
37 IsSanitizedString16(field.label) && | |
38 IsSanitizedString16(field.name) && | |
39 IsSanitizedString16(field.value) && | |
40 IsSanitizedString(field.form_control_type) && | |
41 IsSanitizedString(field.autocomplete_attribute) && | |
42 IsSanitizedString16Vector(field.option_values) && | |
43 IsSanitizedString16Vector(field.option_contents); | |
44 } | |
45 | |
46 bool IsSanitizedFormData(const FormData& form) { | |
47 if (!IsSanitizedString16(form.name) || | |
48 !IsSanitizedString16(form.method) || | |
49 !IsSanitizedGURL(form.origin) || | |
50 !IsSanitizedGURL(form.action)) | |
51 return false; | |
52 | |
53 if (form.fields.size() > kMaxListSize) | |
54 return false; | |
55 | |
56 for (std::vector<FormFieldData>::const_iterator it = form.fields.begin(); | |
57 it != form.fields.end(); ++it) { | |
58 if (!IsSanitizedFormFieldData(*it)) | |
59 return false; | |
60 } | |
61 | |
62 return true; | |
63 } | |
64 | |
65 bool IsSanitizedPasswordFormFillData(const PasswordFormFillData& form) { | |
66 if (!IsSanitizedFormData(form.basic_data) || | |
67 !IsSanitizedString(form.preferred_realm)) | |
68 return false; | |
69 | |
70 for (PasswordFormFillData::LoginCollection::const_iterator it = | |
71 form.additional_logins.begin(); | |
72 it != form.additional_logins.end(); ++it) { | |
73 if (!IsSanitizedString16(it->first) || | |
74 !IsSanitizedString16(it->second.password) || | |
75 !IsSanitizedString(it->second.realm)) | |
76 return false; | |
77 } | |
78 | |
79 for (PasswordFormFillData::UsernamesCollection::const_iterator it = | |
80 form.other_possible_usernames.begin(); | |
81 it != form.other_possible_usernames.end(); ++it) { | |
82 if (!IsSanitizedString16(it->first.username) || | |
83 !IsSanitizedString16(it->first.password) || | |
84 !IsSanitizedString(it->first.realm) || | |
85 !IsSanitizedString16Vector(it->second)) | |
86 return false; | |
87 } | |
88 | |
89 return true; | |
90 } | |
91 | |
92 bool IsSanitizedString16Vector(const std::vector<base::string16>& v) { | |
93 if (v.size() > kMaxListSize) | |
94 return false; | |
95 | |
96 for (std::vector<base::string16>::const_iterator it = v.begin(); | |
97 it != v.end(); ++it) { | |
98 if (!IsSanitizedString16(*it)) | |
99 return false; | |
100 } | |
101 | |
102 return true; | |
103 } | |
104 | |
105 bool IsSanitizedFormDataVector(const std::vector<FormData>& v) { | |
106 if (v.size() > kMaxListSize) | |
107 return false; | |
108 | |
109 for (std::vector<FormData>::const_iterator it = v.begin(); it != v.end(); | |
110 ++it) { | |
111 if (!IsSanitizedFormData(*it)) | |
112 return false; | |
113 } | |
114 | |
115 return true; | |
116 } | |
117 | |
118 } // namespace autofill | |
OLD | NEW |