Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <string> | 5 #include <string> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1405 std::unique_ptr<BubbleObserver> prompt_observer( | 1405 std::unique_ptr<BubbleObserver> prompt_observer( |
| 1406 new BubbleObserver(WebContents())); | 1406 new BubbleObserver(WebContents())); |
| 1407 ui_test_utils::NavigateToURL(browser(), https_url); | 1407 ui_test_utils::NavigateToURL(browser(), https_url); |
| 1408 | 1408 |
| 1409 observer.SetPathToWaitFor("/password/done_and_separate_login_form.html"); | 1409 observer.SetPathToWaitFor("/password/done_and_separate_login_form.html"); |
| 1410 observer.Wait(); | 1410 observer.Wait(); |
| 1411 | 1411 |
| 1412 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); | 1412 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); |
| 1413 } | 1413 } |
| 1414 | 1414 |
| 1415 // Tests whether a attempted submission of a malicious credentials gets blocked. | |
| 1416 // This simulates a case which is described in http://crbug.com/571580. | |
| 1417 IN_PROC_BROWSER_TEST_F( | |
| 1418 PasswordManagerBrowserTestBase, | |
| 1419 NoPromptForSeperateLoginFormWhenSwitchingFromHttpsToHttp) { | |
| 1420 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 1421 ::switches::kAllowRunningInsecureContent); | |
| 1422 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 1423 ::switches::kIgnoreCertificateErrors); | |
| 1424 const base::FilePath::CharType kDocRoot[] = | |
| 1425 FILE_PATH_LITERAL("chrome/test/data"); | |
| 1426 net::EmbeddedTestServer https_test_server( | |
| 1427 net::EmbeddedTestServer::TYPE_HTTPS); | |
| 1428 https_test_server.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); | |
| 1429 ASSERT_TRUE(https_test_server.Start()); | |
| 1430 | |
| 1431 std::string path = "/password/password_form.html"; | |
| 1432 GURL https_url(https_test_server.GetURL(path)); | |
| 1433 ASSERT_TRUE(https_url.SchemeIs(url::kHttpsScheme)); | |
| 1434 | |
| 1435 NavigationObserver form_observer(WebContents()); | |
| 1436 ui_test_utils::NavigateToURL(browser(), https_url); | |
| 1437 form_observer.Wait(); | |
| 1438 | |
| 1439 std::string fill_and_submit_redirect = | |
| 1440 "document.getElementById('username_redirect').value = 'user';" | |
| 1441 "document.getElementById('password_redirect').value = 'password';" | |
| 1442 "document.getElementById('submit_redirect').click()"; | |
| 1443 ASSERT_TRUE( | |
| 1444 content::ExecuteScript(RenderViewHost(), fill_and_submit_redirect)); | |
| 1445 | |
| 1446 NavigationObserver redirect_observer(WebContents()); | |
| 1447 redirect_observer.SetPathToWaitFor("/password/redirect.html"); | |
| 1448 redirect_observer.Wait(); | |
| 1449 | |
| 1450 // Normally the redirect happens to done.html. Here an attack is simulated | |
| 1451 // that hijacks the redirect to a attacker controlled page. | |
| 1452 GURL http_url( | |
| 1453 embedded_test_server()->GetURL("/password/simple_password.html")); | |
| 1454 std::string attacker_redirect = | |
| 1455 "window.location.href = '" + http_url.spec() + "';"; | |
| 1456 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), attacker_redirect)); | |
| 1457 | |
| 1458 NavigationObserver attacker_observer(WebContents()); | |
| 1459 attacker_observer.SetPathToWaitFor("/password/simple_password.html"); | |
| 1460 attacker_observer.Wait(); | |
| 1461 | |
| 1462 std::string fill_and_submit_attacker_form = | |
| 1463 "document.getElementById('username_field').value = 'attacker_username';" | |
| 1464 "document.getElementById('password_field').value = 'attacker_password';" | |
| 1465 "document.getElementById('input_submit_button').click()"; | |
| 1466 ASSERT_TRUE( | |
| 1467 content::ExecuteScript(RenderViewHost(), fill_and_submit_attacker_form)); | |
| 1468 | |
| 1469 NavigationObserver done_observer(WebContents()); | |
| 1470 done_observer.SetPathToWaitFor("/password/done.html"); | |
| 1471 done_observer.Wait(); | |
| 1472 | |
|
vasilii
2017/01/12 14:59:21
We need WaitForPasswordStore() to be safe here.
jdoerrie
2017/01/12 17:40:58
Done.
| |
| 1473 BubbleObserver prompt_observer(WebContents()); | |
| 1474 EXPECT_TRUE(prompt_observer.IsShowingSavePrompt()); | |
| 1475 prompt_observer.AcceptSavePrompt(); | |
| 1476 | |
| 1477 // Wait for password store and check that credentials are stored. | |
| 1478 WaitForPasswordStore(); | |
| 1479 scoped_refptr<password_manager::TestPasswordStore> password_store = | |
| 1480 static_cast<password_manager::TestPasswordStore*>( | |
| 1481 PasswordStoreFactory::GetForProfile( | |
| 1482 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) | |
| 1483 .get()); | |
| 1484 EXPECT_FALSE(password_store->IsEmpty()); | |
|
vasilii
2017/01/12 14:59:21
Is it needed?
jdoerrie
2017/01/12 17:40:58
No, it's implied by a successful execution of |Che
| |
| 1485 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("user"), | |
| 1486 base::ASCIIToUTF16("password")); | |
| 1487 } | |
| 1488 | |
| 1415 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, | 1489 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, |
| 1416 PromptWhenPasswordFormWithoutUsernameFieldSubmitted) { | 1490 PromptWhenPasswordFormWithoutUsernameFieldSubmitted) { |
| 1417 scoped_refptr<password_manager::TestPasswordStore> password_store = | 1491 scoped_refptr<password_manager::TestPasswordStore> password_store = |
| 1418 static_cast<password_manager::TestPasswordStore*>( | 1492 static_cast<password_manager::TestPasswordStore*>( |
| 1419 PasswordStoreFactory::GetForProfile( | 1493 PasswordStoreFactory::GetForProfile( |
| 1420 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get()); | 1494 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get()); |
| 1421 | 1495 |
| 1422 EXPECT_TRUE(password_store->IsEmpty()); | 1496 EXPECT_TRUE(password_store->IsEmpty()); |
| 1423 | 1497 |
| 1424 NavigateToFile("/password/form_with_only_password_field.html"); | 1498 NavigateToFile("/password/form_with_only_password_field.html"); |
| (...skipping 1652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3077 // about all frames, not just the main one. The factories should receive | 3151 // about all frames, not just the main one. The factories should receive |
| 3078 // messages for non-main frames, in particular | 3152 // messages for non-main frames, in particular |
| 3079 // AutofillHostMsg_PasswordFormsParsed. If that were the first time the | 3153 // AutofillHostMsg_PasswordFormsParsed. If that were the first time the |
| 3080 // factories hear about such frames, this would crash. | 3154 // factories hear about such frames, this would crash. |
| 3081 tab_strip_model->AddWebContents(detached_web_contents.release(), -1, | 3155 tab_strip_model->AddWebContents(detached_web_contents.release(), -1, |
| 3082 ::ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 3156 ::ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| 3083 TabStripModel::ADD_ACTIVE); | 3157 TabStripModel::ADD_ACTIVE); |
| 3084 } | 3158 } |
| 3085 | 3159 |
| 3086 } // namespace password_manager | 3160 } // namespace password_manager |
| OLD | NEW |