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

Side by Side Diff: components/autofill/core/browser/autofill_manager.cc

Issue 98753005: [Autofill] Sanitize all data that comes in over IPC. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
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/core/browser/autofill_manager.h" 5 #include "components/autofill/core/browser/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <map> 10 #include <map>
(...skipping 17 matching lines...) Expand all
28 #include "components/autofill/core/browser/autofill_manager_delegate.h" 28 #include "components/autofill/core/browser/autofill_manager_delegate.h"
29 #include "components/autofill/core/browser/autofill_manager_test_delegate.h" 29 #include "components/autofill/core/browser/autofill_manager_test_delegate.h"
30 #include "components/autofill/core/browser/autofill_metrics.h" 30 #include "components/autofill/core/browser/autofill_metrics.h"
31 #include "components/autofill/core/browser/autofill_profile.h" 31 #include "components/autofill/core/browser/autofill_profile.h"
32 #include "components/autofill/core/browser/autofill_type.h" 32 #include "components/autofill/core/browser/autofill_type.h"
33 #include "components/autofill/core/browser/credit_card.h" 33 #include "components/autofill/core/browser/credit_card.h"
34 #include "components/autofill/core/browser/form_structure.h" 34 #include "components/autofill/core/browser/form_structure.h"
35 #include "components/autofill/core/browser/personal_data_manager.h" 35 #include "components/autofill/core/browser/personal_data_manager.h"
36 #include "components/autofill/core/browser/phone_number.h" 36 #include "components/autofill/core/browser/phone_number.h"
37 #include "components/autofill/core/browser/phone_number_i18n.h" 37 #include "components/autofill/core/browser/phone_number_i18n.h"
38 #include "components/autofill/core/common/autofill_data_sanitizer.h"
38 #include "components/autofill/core/common/autofill_pref_names.h" 39 #include "components/autofill/core/common/autofill_pref_names.h"
39 #include "components/autofill/core/common/autofill_switches.h" 40 #include "components/autofill/core/common/autofill_switches.h"
40 #include "components/autofill/core/common/form_data.h" 41 #include "components/autofill/core/common/form_data.h"
41 #include "components/autofill/core/common/form_data_predictions.h" 42 #include "components/autofill/core/common/form_data_predictions.h"
42 #include "components/autofill/core/common/form_field_data.h" 43 #include "components/autofill/core/common/form_field_data.h"
43 #include "components/autofill/core/common/password_form_fill_data.h" 44 #include "components/autofill/core/common/password_form_fill_data.h"
44 #include "components/user_prefs/pref_registry_syncable.h" 45 #include "components/user_prefs/pref_registry_syncable.h"
45 #include "grit/component_strings.h" 46 #include "grit/component_strings.h"
46 #include "third_party/WebKit/public/web/WebAutofillClient.h" 47 #include "third_party/WebKit/public/web/WebAutofillClient.h"
47 #include "ui/base/l10n/l10n_util.h" 48 #include "ui/base/l10n/l10n_util.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 224 }
224 225
225 void AutofillManager::SetExternalDelegate(AutofillExternalDelegate* delegate) { 226 void AutofillManager::SetExternalDelegate(AutofillExternalDelegate* delegate) {
226 // TODO(jrg): consider passing delegate into the ctor. That won't 227 // TODO(jrg): consider passing delegate into the ctor. That won't
227 // work if the delegate has a pointer to the AutofillManager, but 228 // work if the delegate has a pointer to the AutofillManager, but
228 // future directions may not need such a pointer. 229 // future directions may not need such a pointer.
229 external_delegate_ = delegate; 230 external_delegate_ = delegate;
230 autocomplete_history_manager_->SetExternalDelegate(delegate); 231 autocomplete_history_manager_->SetExternalDelegate(delegate);
231 } 232 }
232 233
234 void AutofillManager::ShowAutofillSettings() {
235 manager_delegate_->ShowAutofillSettings();
236 }
237
233 bool AutofillManager::OnFormSubmitted(const FormData& form, 238 bool AutofillManager::OnFormSubmitted(const FormData& form,
234 const TimeTicks& timestamp) { 239 const TimeTicks& timestamp) {
240 // Bail if the arguments appear to be corrupt.
241 if (!IsSanitizedFormData(form))
242 return false;
243
235 // Let Autocomplete know as well. 244 // Let Autocomplete know as well.
236 autocomplete_history_manager_->OnFormSubmitted(form); 245 autocomplete_history_manager_->OnFormSubmitted(form);
237 246
238 // Grab a copy of the form data. 247 // Grab a copy of the form data.
239 scoped_ptr<FormStructure> submitted_form(new FormStructure(form)); 248 scoped_ptr<FormStructure> submitted_form(new FormStructure(form));
240 249
241 if (!ShouldUploadForm(*submitted_form)) 250 if (!ShouldUploadForm(*submitted_form))
242 return false; 251 return false;
243 252
244 // Don't save data that was submitted through JavaScript. 253 // Don't save data that was submitted through JavaScript.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 initial_interaction_timestamp_, 303 initial_interaction_timestamp_,
295 timestamp)); 304 timestamp));
296 } 305 }
297 306
298 return true; 307 return true;
299 } 308 }
300 309
301 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, 310 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms,
302 const TimeTicks& timestamp, 311 const TimeTicks& timestamp,
303 autofill::FormsSeenState state) { 312 autofill::FormsSeenState state) {
313 // Bail if the arguments appear to be corrupt.
314 if (!IsSanitizedFormDataVector(forms))
315 return;
316
304 bool is_post_document_load = state == autofill::DYNAMIC_FORMS_SEEN; 317 bool is_post_document_load = state == autofill::DYNAMIC_FORMS_SEEN;
305 // If new forms were added dynamically, treat as a new page. 318 // If new forms were added dynamically, treat as a new page.
306 if (is_post_document_load) 319 if (is_post_document_load)
307 Reset(); 320 Reset();
308 321
309 if (!driver_->RendererIsAvailable()) 322 if (!driver_->RendererIsAvailable())
310 return; 323 return;
311 324
312 bool enabled = IsAutofillEnabled(); 325 bool enabled = IsAutofillEnabled();
313 if (!has_logged_autofill_enabled_) { 326 if (!has_logged_autofill_enabled_) {
314 metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled); 327 metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled);
315 has_logged_autofill_enabled_ = true; 328 has_logged_autofill_enabled_ = true;
316 } 329 }
317 330
318 if (!enabled) 331 if (!enabled)
319 return; 332 return;
320 333
321 forms_loaded_timestamp_ = timestamp; 334 forms_loaded_timestamp_ = timestamp;
322 ParseForms(forms); 335 ParseForms(forms);
323 } 336 }
324 337
325 void AutofillManager::OnTextFieldDidChange(const FormData& form, 338 void AutofillManager::OnTextFieldDidChange(const FormData& form,
326 const FormFieldData& field, 339 const FormFieldData& field,
327 const TimeTicks& timestamp) { 340 const TimeTicks& timestamp) {
341 // Bail if the arguments appear to be corrupt.
palmer 2013/12/20 19:53:36 Nit: I'd drop the instances of this comment. The f
Ilya Sherman 2013/12/20 23:54:52 Done.
342 if (!IsSanitizedFormData(form) || !IsSanitizedFormFieldData(field))
343 return;
344
328 FormStructure* form_structure = NULL; 345 FormStructure* form_structure = NULL;
329 AutofillField* autofill_field = NULL; 346 AutofillField* autofill_field = NULL;
330 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field)) 347 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field))
331 return; 348 return;
332 349
333 if (!user_did_type_) { 350 if (!user_did_type_) {
334 user_did_type_ = true; 351 user_did_type_ = true;
335 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE); 352 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE);
336 } 353 }
337 354
(...skipping 10 matching lines...) Expand all
348 } 365 }
349 366
350 UpdateInitialInteractionTimestamp(timestamp); 367 UpdateInitialInteractionTimestamp(timestamp);
351 } 368 }
352 369
353 void AutofillManager::OnQueryFormFieldAutofill(int query_id, 370 void AutofillManager::OnQueryFormFieldAutofill(int query_id,
354 const FormData& form, 371 const FormData& form,
355 const FormFieldData& field, 372 const FormFieldData& field,
356 const gfx::RectF& bounding_box, 373 const gfx::RectF& bounding_box,
357 bool display_warning) { 374 bool display_warning) {
375 // Bail if the arguments appear to be corrupt.
376 if (!IsSanitizedFormData(form) || !IsSanitizedFormFieldData(field))
377 return;
378
358 std::vector<base::string16> values; 379 std::vector<base::string16> values;
359 std::vector<base::string16> labels; 380 std::vector<base::string16> labels;
360 std::vector<base::string16> icons; 381 std::vector<base::string16> icons;
361 std::vector<int> unique_ids; 382 std::vector<int> unique_ids;
362 383
363 external_delegate_->OnQuery(query_id, 384 external_delegate_->OnQuery(query_id,
364 form, 385 form,
365 field, 386 field,
366 bounding_box, 387 bounding_box,
367 display_warning); 388 display_warning);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 // hand off what we generated and they will send the results back to the 456 // hand off what we generated and they will send the results back to the
436 // renderer. 457 // renderer.
437 autocomplete_history_manager_->OnGetAutocompleteSuggestions( 458 autocomplete_history_manager_->OnGetAutocompleteSuggestions(
438 query_id, field.name, field.value, values, labels, icons, unique_ids); 459 query_id, field.name, field.value, values, labels, icons, unique_ids);
439 } 460 }
440 461
441 void AutofillManager::OnFillAutofillFormData(int query_id, 462 void AutofillManager::OnFillAutofillFormData(int query_id,
442 const FormData& form, 463 const FormData& form,
443 const FormFieldData& field, 464 const FormFieldData& field,
444 int unique_id) { 465 int unique_id) {
466 // Bail if the arguments appear to be corrupt.
467 if (!IsSanitizedFormData(form) || !IsSanitizedFormFieldData(field))
468 return;
469
445 const AutofillDataModel* data_model = NULL; 470 const AutofillDataModel* data_model = NULL;
446 size_t variant = 0; 471 size_t variant = 0;
447 FormStructure* form_structure = NULL; 472 FormStructure* form_structure = NULL;
448 AutofillField* autofill_field = NULL; 473 AutofillField* autofill_field = NULL;
449 // NOTE: RefreshDataModels may invalidate |data_model| because it causes the 474 // NOTE: RefreshDataModels may invalidate |data_model| because it causes the
450 // PersonalDataManager to reload Mac address book entries. Thus it must come 475 // PersonalDataManager to reload Mac address book entries. Thus it must come
451 // before GetProfileOrCreditCard. 476 // before GetProfileOrCreditCard.
452 if (!RefreshDataModels() || 477 if (!RefreshDataModels() ||
453 !driver_->RendererIsAvailable() || 478 !driver_->RendererIsAvailable() ||
454 !GetProfileOrCreditCard(unique_id, &data_model, &variant) || 479 !GetProfileOrCreditCard(unique_id, &data_model, &variant) ||
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 540
516 autofilled_form_signatures_.push_front(form_structure->FormSignature()); 541 autofilled_form_signatures_.push_front(form_structure->FormSignature());
517 // Only remember the last few forms that we've seen, both to avoid false 542 // Only remember the last few forms that we've seen, both to avoid false
518 // positives and to avoid wasting memory. 543 // positives and to avoid wasting memory.
519 if (autofilled_form_signatures_.size() > kMaxRecentFormSignaturesToRemember) 544 if (autofilled_form_signatures_.size() > kMaxRecentFormSignaturesToRemember)
520 autofilled_form_signatures_.pop_back(); 545 autofilled_form_signatures_.pop_back();
521 546
522 driver_->SendFormDataToRenderer(query_id, result); 547 driver_->SendFormDataToRenderer(query_id, result);
523 } 548 }
524 549
525 void AutofillManager::OnShowAutofillDialog() {
526 manager_delegate_->ShowAutofillSettings();
527 }
528
529 void AutofillManager::OnDidPreviewAutofillFormData() { 550 void AutofillManager::OnDidPreviewAutofillFormData() {
530 if (test_delegate_) 551 if (test_delegate_)
531 test_delegate_->DidPreviewFormData(); 552 test_delegate_->DidPreviewFormData();
532 } 553 }
533 554
534 void AutofillManager::OnDidFillAutofillFormData(const TimeTicks& timestamp) { 555 void AutofillManager::OnDidFillAutofillFormData(const TimeTicks& timestamp) {
535 if (test_delegate_) 556 if (test_delegate_)
536 test_delegate_->DidFillFormData(); 557 test_delegate_->DidFillFormData();
537 558
538 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL); 559 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 const std::vector<FormStructure*>& AutofillManager::GetFormStructures() { 613 const std::vector<FormStructure*>& AutofillManager::GetFormStructures() {
593 return form_structures_.get(); 614 return form_structures_.get();
594 } 615 }
595 616
596 void AutofillManager::SetTestDelegate( 617 void AutofillManager::SetTestDelegate(
597 autofill::AutofillManagerTestDelegate* delegate) { 618 autofill::AutofillManagerTestDelegate* delegate) {
598 test_delegate_ = delegate; 619 test_delegate_ = delegate;
599 } 620 }
600 621
601 void AutofillManager::OnAddPasswordFormMapping( 622 void AutofillManager::OnAddPasswordFormMapping(
602 const FormFieldData& form, 623 const FormFieldData& username_field,
603 const PasswordFormFillData& fill_data) { 624 const PasswordFormFillData& fill_data) {
604 external_delegate_->AddPasswordFormMapping(form, fill_data); 625 // Bail if the arguments appear to be corrupt.
626 if (!IsSanitizedFormFieldData(username_field) ||
627 !IsSanitizedPasswordFormFillData(fill_data))
628 return;
629
630 external_delegate_->AddPasswordFormMapping(username_field, fill_data);
605 } 631 }
606 632
607 void AutofillManager::OnShowPasswordSuggestions( 633 void AutofillManager::OnShowPasswordSuggestions(
608 const FormFieldData& field, 634 const FormFieldData& field,
609 const gfx::RectF& bounds, 635 const gfx::RectF& bounds,
610 const std::vector<base::string16>& suggestions, 636 const std::vector<base::string16>& suggestions,
611 const std::vector<base::string16>& realms) { 637 const std::vector<base::string16>& realms) {
638 // Bail if the arguments appear to be corrupt.
639 if (!IsSanitizedString16Vector(suggestions) ||
640 !IsSanitizedString16Vector(realms) ||
641 suggestions.size() != realms.size())
642 return;
643
612 external_delegate_->OnShowPasswordSuggestions(suggestions, 644 external_delegate_->OnShowPasswordSuggestions(suggestions,
613 realms, 645 realms,
614 field, 646 field,
615 bounds); 647 bounds);
616 } 648 }
617 649
618 void AutofillManager::OnSetDataList(const std::vector<base::string16>& values, 650 void AutofillManager::OnSetDataList(const std::vector<base::string16>& values,
619 const std::vector<base::string16>& labels) { 651 const std::vector<base::string16>& labels) {
620 if (values.size() != labels.size()) 652 // Bail if the arguments appear to be corrupt.
653 if (!IsSanitizedString16Vector(values) ||
654 !IsSanitizedString16Vector(labels) ||
655 values.size() != labels.size())
621 return; 656 return;
622 657
623 external_delegate_->SetCurrentDataListValues(values, labels); 658 external_delegate_->SetCurrentDataListValues(values, labels);
624 } 659 }
625 660
626 void AutofillManager::OnLoadedServerPredictions( 661 void AutofillManager::OnLoadedServerPredictions(
627 const std::string& response_xml) { 662 const std::string& response_xml) {
628 // Parse and store the server predictions. 663 // Parse and store the server predictions.
629 FormStructure::ParseQueryResponse(response_xml, 664 FormStructure::ParseQueryResponse(response_xml,
630 form_structures_.get(), 665 form_structures_.get(),
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 return false; 1135 return false;
1101 1136
1102 // Disregard forms that we wouldn't ever autofill in the first place. 1137 // Disregard forms that we wouldn't ever autofill in the first place.
1103 if (!form.ShouldBeParsed(true)) 1138 if (!form.ShouldBeParsed(true))
1104 return false; 1139 return false;
1105 1140
1106 return true; 1141 return true;
1107 } 1142 }
1108 1143
1109 } // namespace autofill 1144 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698