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

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

Issue 2902933002: Verify all files in the request body are accessible by the renderer process. (Closed)
Patch Set: Remove NOTREACHED as tests exercise this codepath. Created 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/ptr_util.h"
8 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "content/browser/child_process_security_policy_impl.h"
10 #include "content/browser/frame_host/navigation_handle_impl.h" 12 #include "content/browser/frame_host/navigation_handle_impl.h"
11 #include "content/browser/frame_host/navigation_request.h" 13 #include "content/browser/frame_host/navigation_request.h"
12 #include "content/browser/web_contents/web_contents_impl.h" 14 #include "content/browser/web_contents/web_contents_impl.h"
15 #include "content/common/frame_messages.h"
13 #include "content/common/site_isolation_policy.h" 16 #include "content/common/site_isolation_policy.h"
14 #include "content/public/browser/notification_types.h" 17 #include "content/public/browser/notification_types.h"
15 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
16 #include "content/public/common/content_switches.h" 19 #include "content/public/common/content_switches.h"
17 #include "content/public/common/url_constants.h" 20 #include "content/public/common/url_constants.h"
18 #include "content/public/test/browser_test_utils.h" 21 #include "content/public/test/browser_test_utils.h"
19 #include "content/public/test/content_browser_test.h" 22 #include "content/public/test/content_browser_test.h"
20 #include "content/public/test/content_browser_test_utils.h" 23 #include "content/public/test/content_browser_test_utils.h"
21 #include "content/public/test/navigation_handle_observer.h" 24 #include "content/public/test/navigation_handle_observer.h"
22 #include "content/public/test/test_navigation_observer.h" 25 #include "content/public/test/test_navigation_observer.h"
23 #include "content/shell/browser/shell.h" 26 #include "content/shell/browser/shell.h"
24 #include "content/shell/browser/shell_network_delegate.h" 27 #include "content/shell/browser/shell_network_delegate.h"
28 #include "content/test/content_browser_test_utils_internal.h"
29 #include "ipc/ipc_security_test_util.h"
30 #include "net/base/load_flags.h"
25 #include "net/dns/mock_host_resolver.h" 31 #include "net/dns/mock_host_resolver.h"
26 #include "net/test/embedded_test_server/embedded_test_server.h" 32 #include "net/test/embedded_test_server/embedded_test_server.h"
27 #include "net/test/url_request/url_request_failed_job.h" 33 #include "net/test/url_request/url_request_failed_job.h"
28 #include "url/gurl.h" 34 #include "url/gurl.h"
29 35
30 namespace content { 36 namespace content {
31 37
32 class BrowserSideNavigationBrowserTest : public ContentBrowserTest { 38 class BrowserSideNavigationBrowserTest : public ContentBrowserTest {
33 public: 39 public:
34 BrowserSideNavigationBrowserTest() {} 40 BrowserSideNavigationBrowserTest() {}
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 ASSERT_TRUE(root->navigation_request()); 321 ASSERT_TRUE(root->navigation_request());
316 EXPECT_EQ(GURL(), 322 EXPECT_EQ(GURL(),
317 root->navigation_request()->navigation_handle()->GetReferrer().url); 323 root->navigation_request()->navigation_handle()->GetReferrer().url);
318 324
319 // The navigation should commit without being blocked. 325 // The navigation should commit without being blocked.
320 EXPECT_TRUE(manager.WaitForResponse()); 326 EXPECT_TRUE(manager.WaitForResponse());
321 manager.WaitForNavigationFinished(); 327 manager.WaitForNavigationFinished();
322 EXPECT_EQ(kInsecureUrl, shell()->web_contents()->GetLastCommittedURL()); 328 EXPECT_EQ(kInsecureUrl, shell()->web_contents()->GetLastCommittedURL());
323 } 329 }
324 330
331 // Test to verify that an exploited renderer process trying to upload a file
332 // it hasn't been explicitly granted permissions to is correctly terminated.
333 // TODO(nasko): This test case belongs better in
334 // security_exploit_browsertest.cc, so move it there once PlzNavigate is on
335 // by default.
336 IN_PROC_BROWSER_TEST_F(BrowserSideNavigationBrowserTest,
337 PostUploadIllegalFilePath) {
338 GURL form_url(
339 embedded_test_server()->GetURL("/form_that_posts_to_echoall.html"));
340 EXPECT_TRUE(NavigateToURL(shell(), form_url));
341
342 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(
343 shell()->web_contents()->GetMainFrame());
344
345 // Prepare a file for the upload form.
346 base::ThreadRestrictions::ScopedAllowIO allow_io_for_temp_dir;
347 base::ScopedTempDir temp_dir;
348 base::FilePath file_path;
349 std::string file_content("test-file-content");
350 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
351 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.GetPath(), &file_path));
352 ASSERT_LT(
353 0, base::WriteFile(file_path, file_content.data(), file_content.size()));
354
355 // Fill out the form to refer to the test file.
356 std::unique_ptr<FileChooserDelegate> delegate(
357 new FileChooserDelegate(file_path));
358 shell()->web_contents()->SetDelegate(delegate.get());
359 EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
360 "document.getElementById('file').click();"));
361 EXPECT_TRUE(delegate->file_chosen());
362
363 // Ensure that the process is allowed to access to the chosen file and
364 // does not have access to the other file name.
365 EXPECT_TRUE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
366 rfh->GetProcess()->GetID(), file_path));
367
368 base::FilePath wrong_file(file_path.value() + "-foobarz");
ncarter (slow) 2017/05/24 20:06:19 base::FilePath wrong_file(file_path.value() + FILE
369 EXPECT_FALSE(ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
370 rfh->GetProcess()->GetID(), wrong_file));
371
372 // Setup a BeginNavigate IPC with the invalid file path.
373 scoped_refptr<ResourceRequestBodyImpl> request_body =
374 new ResourceRequestBodyImpl();
375 request_body->AppendFileRange(
376 wrong_file, 0, std::numeric_limits<uint64_t>::max(), base::Time());
377
378 GURL url(embedded_test_server()->GetURL("/title1.html"));
379 CommonNavigationParams common_params(
380 url, Referrer(), ui::PAGE_TRANSITION_LINK,
381 FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT, true, false,
382 base::TimeTicks(), FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(),
383 GURL(), PREVIEWS_UNSPECIFIED, base::TimeTicks::Now(), "POST",
384 request_body, base::Optional<SourceLocation>(), CSPDisposition::CHECK);
385 BeginNavigationParams begin_params(
386 std::string(), net::LOAD_NORMAL, false, false,
387 REQUEST_CONTEXT_TYPE_LOCATION,
388 blink::WebMixedContentContextType::kBlockable,
389 true, // is_form_submission
390 url::Origin(url));
391 std::unique_ptr<FrameHostMsg_BeginNavigation> msg =
392 base::WrapUnique(new FrameHostMsg_BeginNavigation(
ncarter (slow) 2017/05/24 20:06:19 nit: this could be created on the stack, or as a t
393 rfh->GetRoutingID(), common_params, begin_params));
394
395 RenderProcessHostWatcher process_exit_observer(
396 rfh->GetProcess(), RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
397 IPC::IpcSecurityTestUtil::PwnMessageReceived(rfh->GetProcess()->GetChannel(),
398 *(msg.get()));
399 process_exit_observer.Wait();
400 }
401
325 } // namespace content 402 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698