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

Side by Side Diff: content/browser/cross_site_transfer_browsertest.cc

Issue 2062523002: Fixing renderer's access to a file from HTTP POST (after a xsite transfer). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed the new (redundant) access check from RDHI. Created 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <memory>
6
5 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h"
6 #include "base/macros.h" 11 #include "base/macros.h"
7 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "content/browser/child_process_security_policy_impl.h"
8 #include "content/browser/loader/resource_dispatcher_host_impl.h" 14 #include "content/browser/loader/resource_dispatcher_host_impl.h"
9 #include "content/public/browser/navigation_entry.h" 15 #include "content/public/browser/navigation_entry.h"
16 #include "content/public/browser/render_process_host.h"
10 #include "content/public/browser/resource_dispatcher_host_delegate.h" 17 #include "content/public/browser/resource_dispatcher_host_delegate.h"
11 #include "content/public/browser/resource_throttle.h" 18 #include "content/public/browser/resource_throttle.h"
12 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
13 #include "content/public/test/browser_test_utils.h" 20 #include "content/public/test/browser_test_utils.h"
14 #include "content/public/test/content_browser_test.h" 21 #include "content/public/test/content_browser_test.h"
15 #include "content/public/test/content_browser_test_utils.h" 22 #include "content/public/test/content_browser_test_utils.h"
16 #include "content/public/test/test_navigation_observer.h" 23 #include "content/public/test/test_navigation_observer.h"
17 #include "content/shell/browser/shell.h" 24 #include "content/shell/browser/shell.h"
18 #include "content/shell/browser/shell_content_browser_client.h" 25 #include "content/shell/browser/shell_content_browser_client.h"
19 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" 26 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h"
20 #include "net/base/escape.h" 27 #include "net/base/escape.h"
21 #include "net/dns/mock_host_resolver.h" 28 #include "net/dns/mock_host_resolver.h"
22 #include "net/test/embedded_test_server/embedded_test_server.h" 29 #include "net/test/embedded_test_server/embedded_test_server.h"
23 #include "net/url_request/url_request.h" 30 #include "net/url_request/url_request.h"
24 #include "net/url_request/url_request_status.h" 31 #include "net/url_request/url_request_status.h"
32 #include "testing/gmock/include/gmock/gmock-matchers.h"
25 #include "url/gurl.h" 33 #include "url/gurl.h"
26 34
27 namespace content { 35 namespace content {
28 36
29 // Tracks a single request for a specified URL, and allows waiting until the 37 // Tracks a single request for a specified URL, and allows waiting until the
30 // request is destroyed, and then inspecting whether it completed successfully. 38 // request is destroyed, and then inspecting whether it completed successfully.
31 class TrackingResourceDispatcherHostDelegate 39 class TrackingResourceDispatcherHostDelegate
32 : public ShellResourceDispatcherHostDelegate { 40 : public ShellResourceDispatcherHostDelegate {
33 public: 41 public:
34 TrackingResourceDispatcherHostDelegate() : throttle_created_(false) { 42 TrackingResourceDispatcherHostDelegate() : throttle_created_(false) {
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 EXPECT_EQ(1, controller.GetEntryCount()); 419 EXPECT_EQ(1, controller.GetEntryCount());
412 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 420 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
413 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL()); 421 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL());
414 422
415 // Make sure the request for url2 did not complete. 423 // Make sure the request for url2 did not complete.
416 EXPECT_FALSE(tracking_delegate().WaitForTrackedURLAndGetCompleted()); 424 EXPECT_FALSE(tracking_delegate().WaitForTrackedURLAndGetCompleted());
417 425
418 shell()->web_contents()->SetDelegate(old_delegate); 426 shell()->web_contents()->SetDelegate(old_delegate);
419 } 427 }
420 428
429 // Test that verifies that a cross-process transfer retains ability to read
430 // files encapsulated by HTTP POST body that is forwarded to the new renderer.
431 // Invalid handling of this scenario has been suspected as the cause of at least
432 // some of the renderer kills tracked in https://crbug.com/613260.
433 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, PostWithFileData) {
434 // Navigate to the page with form that posts via 307 redirection to
435 // |redirect_target_url| (cross-site from |form_url|). Using 307 (rather than
436 // 302) redirection is important to preserve the HTTP method and POST body.
437 GURL form_url(embedded_test_server()->GetURL(
438 "a.com", "/form_that_posts_cross_site.html"));
439 GURL redirect_target_url(embedded_test_server()->GetURL("x.com", "/echoall"));
440 EXPECT_TRUE(NavigateToURL(shell(), form_url));
441
442 // Prepare a file to upload.
443 base::ScopedTempDir temp_dir;
444 base::FilePath file_path;
445 std::string file_content("test-file-content");
446 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
447 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &file_path));
448 ASSERT_LT(
449 0, base::WriteFile(file_path, file_content.data(), file_content.size()));
450
451 // Fill out the form to refer to the test file.
452 std::unique_ptr<FileChooserDelegate> delegate(
453 new FileChooserDelegate(file_path));
454 shell()->web_contents()->SetDelegate(delegate.get());
455 EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
456 "document.getElementById('file').click();"));
457 EXPECT_TRUE(delegate->file_chosen());
458
459 // Remember the old process id for a sanity check below.
460 int old_process_id = shell()->web_contents()->GetRenderProcessHost()->GetID();
461
462 // Submit the form.
463 TestNavigationObserver form_post_observer(shell()->web_contents(), 1);
464 EXPECT_TRUE(
465 ExecuteScript(shell(), "document.getElementById('file-form').submit();"));
466 form_post_observer.Wait();
467
468 // Verify that we arrived at the expected, redirected location.
469 EXPECT_EQ(redirect_target_url,
470 shell()->web_contents()->GetLastCommittedURL());
471
472 // Verify that the test really verifies access of a *new* renderer process.
473 int new_process_id = shell()->web_contents()->GetRenderProcessHost()->GetID();
474 ASSERT_NE(new_process_id, old_process_id);
475
476 // MAIN VERIFICATION: Check if the new renderer process is able to read the
477 // file.
478 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
479 new_process_id, file_path));
480
481 // Verify that POST body got preserved by 307 redirect. This expectation
482 // comes from: https://tools.ietf.org/html/rfc7231#section-6.4.7
483 std::string actual_page_body;
484 EXPECT_TRUE(ExecuteScriptAndExtractString(
485 shell()->web_contents(),
486 "window.domAutomationController.send("
487 "document.getElementsByTagName('pre')[0].innerText);",
488 &actual_page_body));
489 EXPECT_THAT(actual_page_body, ::testing::HasSubstr(file_content));
490 EXPECT_THAT(actual_page_body,
491 ::testing::HasSubstr(file_path.BaseName().AsUTF8Unsafe()));
492 EXPECT_THAT(actual_page_body,
493 ::testing::HasSubstr("form-data; name=\"file\""));
494 }
495
421 } // namespace content 496 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/frame_host/render_frame_host_impl.h » ('j') | content/public/test/content_browser_test_utils.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698