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

Unified Diff: content/browser/site_per_process_browsertest.cc

Issue 1145013004: Introduce bad_message.h for chrome and NaCl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Small fix to extensions/browser/bad_message.h Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/site_per_process_browsertest.cc
diff --git a/content/browser/site_per_process_browsertest.cc b/content/browser/site_per_process_browsertest.cc
index c09d4297e59b979b3f5922d119e03393d6ee7607..34b890529e45fc8612cfaf21465474b6bdbdb86f 100644
--- a/content/browser/site_per_process_browsertest.cc
+++ b/content/browser/site_per_process_browsertest.cc
@@ -59,8 +59,6 @@ void PostMessageAndWaitForReply(FrameTreeNode* sender_ftn,
}
}
-} // anonymous namespace
-
class RedirectNotificationObserver : public NotificationObserver {
public:
// Register to listen for notifications of the given type from either a
@@ -240,6 +238,15 @@ bool ConsoleObserverDelegate::AddMessageToConsole(
return false;
}
+std::string GetCookieFromJS(RenderFrameHost* frame) {
+ std::string cookie;
+ EXPECT_TRUE(ExecuteScriptAndExtractString(
+ frame, "window.domAutomationController.send(document.cookie);", &cookie));
+ return cookie;
+}
+
+} // namespace
+
//
// SitePerProcessBrowserTest
//
@@ -1061,10 +1068,6 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, DISABLED_CrashSubframe) {
StartFrameAtDataURL();
- // These must stay in scope with replace_host.
- GURL::Replacements replace_host;
- std::string foo_com("foo.com");
-
// Load cross-site page into iframe.
EXPECT_TRUE(NavigateIframeToURL(
shell()->web_contents(), "test",
@@ -2466,4 +2469,135 @@ IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, RFPHDestruction) {
DepictFrameTree(root));
}
+// Exercises
James Cook 2015/05/22 18:13:10 Exercises? Also, is this meant to be part of a di
ncarter (slow) 2015/05/22 18:41:52 Oh gosh yes, this doesn't belong here at all. Stal
+IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, CookieAccessRestrictions) {
+ net::SpawnedTestServer https_server(
+ net::SpawnedTestServer::TYPE_HTTPS, net::SpawnedTestServer::kLocalhost,
+ base::FilePath(FILE_PATH_LITERAL("content/test/data")));
+ ASSERT_TRUE(https_server.Start());
+
+ // The server sends a HttpOnly cookie which should never be seen by any
+ // renderer.
+ GURL https_url = https_server.GetURL("set-cookie?notforjs=1;HttpOnly");
+ GURL http_url = embedded_test_server()->GetURL("/frame_with_load_event.html");
+
+ Shell* shell2 = CreateBrowser();
+ NavigateToURL(shell(), http_url);
+ NavigateToURL(shell2, https_url);
+
+ WebContentsImpl* secure_web_contents =
+ static_cast<WebContentsImpl*>(shell2->web_contents());
+ WebContentsImpl* insecure_web_contents =
+ static_cast<WebContentsImpl*>(shell()->web_contents());
+
+ EXPECT_EQ("http://127.0.0.1/",
+ insecure_web_contents->GetSiteInstance()->GetSiteURL().spec());
+ EXPECT_EQ("https://127.0.0.1/",
+ secure_web_contents->GetSiteInstance()->GetSiteURL().spec());
+
+ EXPECT_NE(insecure_web_contents->GetSiteInstance()->GetProcess(),
+ secure_web_contents->GetSiteInstance()->GetProcess());
+
+ EXPECT_EQ("", GetCookieFromJS(secure_web_contents->GetMainFrame()));
+ EXPECT_EQ("", GetCookieFromJS(insecure_web_contents->GetMainFrame()));
+
+ // HTTP page writes secure cookie.
+ EXPECT_TRUE(ExecuteScript(insecure_web_contents->GetMainFrame(),
+ "document.cookie = 'A=1; secure;';"));
+ EXPECT_EQ("A=1", GetCookieFromJS(secure_web_contents->GetMainFrame()));
+ EXPECT_EQ("", GetCookieFromJS(insecure_web_contents->GetMainFrame()));
+
+ // TLS page writes not-secure cookie.
+ EXPECT_TRUE(ExecuteScript(insecure_web_contents->GetMainFrame(),
+ "document.cookie = 'B=2';"));
+ EXPECT_EQ("A=1; B=2", GetCookieFromJS(secure_web_contents->GetMainFrame()));
+ EXPECT_EQ("B=2", GetCookieFromJS(insecure_web_contents->GetMainFrame()));
+
+ // HTTP page writes secure cookie.
+ EXPECT_TRUE(ExecuteScript(secure_web_contents->GetMainFrame(),
+ "document.cookie = 'C=3;secure;';"));
+ EXPECT_EQ("A=1; B=2; C=3",
+ GetCookieFromJS(secure_web_contents->GetMainFrame()));
+ EXPECT_EQ("B=2", GetCookieFromJS(insecure_web_contents->GetMainFrame()));
+
+ // TLS doc writes not-secure cookie.
+ EXPECT_TRUE(ExecuteScript(secure_web_contents->GetMainFrame(),
+ "document.cookie = 'D=4';"));
+ EXPECT_EQ("A=1; B=2; C=3; D=4",
+ GetCookieFromJS(secure_web_contents->GetMainFrame()));
+ EXPECT_EQ("B=2; D=4", GetCookieFromJS(insecure_web_contents->GetMainFrame()));
+
+ // The iframe on the http page should get its own process.
+ EXPECT_EQ(
+ " Site A ------------ proxies for B\n"
+ " +--Site B ------- proxies for A\n"
+ "Where A = http://127.0.0.1/\n"
+ " B = http://baz.com/",
+ DepictFrameTree(insecure_web_contents->GetFrameTree()->root()));
+
+ RenderFrameHost* evil_iframe = insecure_web_contents->GetFrameTree()
+ ->root()
+ ->child_at(0)
+ ->current_frame_host();
+
+ EXPECT_NE(evil_iframe->GetProcess(),
+ insecure_web_contents->GetMainFrame()->GetProcess());
+ EXPECT_NE(evil_iframe->GetProcess(),
+ secure_web_contents->GetMainFrame()->GetProcess());
+
+ // Try to get cross-site cookies from the subframe's process and wait for it
+ // to be killed.
+ std::string response;
+ FrameHostMsg_GetCookies illegal_get_cookies(
+ evil_iframe->GetRoutingID(), GURL("https://127.0.0.1/"),
+ GURL("https://127.0.0.1/"), &response);
+
+ RenderProcessHostWatcher baz_killed(
+ evil_iframe->GetProcess(),
+ RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
+
+ IPC::IpcSecurityTestUtil::PwnMessageReceived(
+ evil_iframe->GetProcess()->GetChannel(), illegal_get_cookies);
+
+ baz_killed.Wait();
+
+ EXPECT_EQ(
+ " Site A ------------ proxies for B\n"
+ " +--Site B ------- proxies for A\n"
+ "Where A = http://127.0.0.1/\n"
+ " B = http://baz.com/ (no process)",
+ DepictFrameTree(insecure_web_contents->GetFrameTree()->root()));
+
+ EXPECT_EQ(
+ " Site C\n"
+ "Where C = https://127.0.0.1/",
+ DepictFrameTree(secure_web_contents->GetFrameTree()->root()));
+
+ // Now set a cross-site cookie from the main frame's process and wait for it
+ // to be killed.
+ RenderProcessHostWatcher secure_localhost_killed(
+ insecure_web_contents->GetMainFrame()->GetProcess(),
+ RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
+ FrameHostMsg_SetCookie illegal_set_cookie(
+ insecure_web_contents->GetMainFrame()->GetRoutingID(),
+ GURL("https://baz.com/"), GURL("https://baz.com/"), "pwn=ed");
+ IPC::IpcSecurityTestUtil::PwnMessageReceived(
+ secure_web_contents->GetMainFrame()->GetProcess()->GetChannel(),
+ illegal_set_cookie);
+
+ secure_localhost_killed.Wait();
+
+ EXPECT_EQ(
+ " Site C\n"
+ "Where C = https://127.0.0.1/ (no process)",
+ DepictFrameTree(secure_web_contents->GetFrameTree()->root()));
+
+ // Now try to .
+
+ EXPECT_EQ(
+ " Site A\n"
+ "Where A = http://127.0.0.1/ (no process)",
+ DepictFrameTree(insecure_web_contents->GetFrameTree()->root()));
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698