Skip to content

Commit 7cdef80

Browse files
DCtheTallChromium LUCI CQ
authored and
Chromium LUCI CQ
committed
Send Sec-CH-Partioned-Cookies:?1 to embedded frames in the CHIPS OT
Bug: 1324687 Change-Id: I9922232d9231dd54af7555689ee23522f31185b8 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3641657 Reviewed-by: Ari Chivukula <arichiv@chromium.org> Commit-Queue: Ari Chivukula <arichiv@chromium.org> Cr-Commit-Position: refs/heads/main@{#1002910}
1 parent da3ebdd commit 7cdef80

File tree

2 files changed

+129
-3
lines changed

2 files changed

+129
-3
lines changed

chrome/browser/client_hints/client_hints_browsertest.cc

+125
Original file line numberDiff line numberDiff line change
@@ -5802,6 +5802,131 @@ IN_PROC_BROWSER_TEST_F(ThirdPartyPartitionedCookiesOriginTrialBrowserTest,
58025802
EXPECT_FALSE(cookies[0].IsPartitioned());
58035803
}
58045804

5805+
class EmbeddedPartitionedCookiesOriginTrialBrowserTest
5806+
: public PartitionedCookiesOriginTrialBrowserTest {
5807+
public:
5808+
EmbeddedPartitionedCookiesOriginTrialBrowserTest() = default;
5809+
5810+
void SetUpOnMainThread() override {
5811+
// We use a URLLoaderInterceptor, rather than the EmbeddedTestServer, since
5812+
// the origin trial token in the response is associated with a fixed
5813+
// origin, whereas EmbeddedTestServer serves content on a random port.
5814+
url_loader_interceptor_ =
5815+
std::make_unique<URLLoaderInterceptor>(base::BindRepeating(
5816+
&EmbeddedPartitionedCookiesOriginTrialBrowserTest::InterceptRequest,
5817+
base::Unretained(this)));
5818+
InProcessBrowserTest::SetUpOnMainThread();
5819+
}
5820+
5821+
// URLLoaderInterceptor callback
5822+
bool InterceptRequest(URLLoaderInterceptor::RequestParams* params) {
5823+
if (expected_request_urls_.find(params->url_request.url) ==
5824+
expected_request_urls_.end())
5825+
return false;
5826+
5827+
if (params->url_request.url.path() ==
5828+
base::StrCat({"/partitioned_cookies_embedder.html"})) {
5829+
std::string headers = "HTTP/1.1 200 OK\nContent-Type: text/html\n";
5830+
std::string body = "<html><head>";
5831+
base::StrAppend(&body, {"</head><body>"});
5832+
base::StrAppend(&body, {BuildIframeHTML()});
5833+
base::StrAppend(&body, {"</body></html>"});
5834+
URLLoaderInterceptor::WriteResponse(headers, body, params->client.get());
5835+
return true;
5836+
}
5837+
5838+
if (params->url_request.url.path() ==
5839+
base::StrCat({"/partitioned_cookies_embeddee.html"})) {
5840+
std::string headers = "HTTP/1.1 200 OK\nContent-Type: text/html\n";
5841+
base::StrAppend(&headers, {BuildOriginTrialHeader()});
5842+
URLLoaderInterceptor::WriteResponse(
5843+
"chrome/test/data/client_hints/partitioned_cookies_embeddee.html",
5844+
params->client.get(), &headers, absl::nullopt,
5845+
params->url_request.url);
5846+
return true;
5847+
}
5848+
5849+
NOTREACHED();
5850+
return false;
5851+
}
5852+
5853+
GURL embedder_url() const {
5854+
return GURL(base::StrCat(
5855+
{kFirstPartyOriginUrl, "/partitioned_cookies_embedder.html"}));
5856+
}
5857+
5858+
// In this test, the OT participant is the embedded site.
5859+
GURL origin_trial_participant_url() const {
5860+
return GURL(
5861+
base::StrCat({kCookieOriginUrl, "/partitioned_cookies_embeddee.html"}));
5862+
}
5863+
5864+
// The URL that was used to register the Origin Trial token as the first
5865+
// party. Requests to this origin should be handled by URLLoader interceptor.
5866+
static constexpr const char kFirstPartyOriginUrl[] =
5867+
"https://my-site.com:44444";
5868+
5869+
// The URL of the site receiving cookies.
5870+
// Requests to this origin should be handled by the test server.
5871+
static constexpr char kCookieOriginUrl[] = "https://127.0.0.1:44444";
5872+
5873+
std::string BuildOriginTrialHeader() const override {
5874+
std::string headers;
5875+
5876+
static constexpr const char kOriginTrialToken[] =
5877+
"A1mBOyrOKGAaaoT8mjM1qSNrOSrdDUa9WyqicVLlDGW3feIBSdWqSiHDAXUeKkGKaVqUiC"
5878+
"X8avwCM0gpG5LtxgAAAAByeyJvcmlnaW4iOiAiaHR0cHM6Ly8xMjcuMC4wLjE6NDQ0NDQi"
5879+
"LCAiZmVhdHVyZSI6ICJQYXJ0aXRpb25lZENvb2tpZXMiLCAiZXhwaXJ5IjogMjAwMDAwMD"
5880+
"AwMCwgImlzVGhpcmRQYXJ0eSI6IHRydWV9";
5881+
5882+
if (test_options_.has_accept_ch_header) {
5883+
base::StrAppend(&headers,
5884+
{"Accept-CH: ", "sec-ch-partitioned-cookies", "\n"});
5885+
}
5886+
if (test_options_.has_critical_ch_header) {
5887+
base::StrAppend(&headers,
5888+
{"Critical-CH: ", "sec-ch-partitioned-cookies", "\n"});
5889+
}
5890+
if (test_options_.has_ot_token) {
5891+
base::StrAppend(
5892+
&headers,
5893+
{"Origin-Trial: ",
5894+
test_options_.valid_ot_token ? kOriginTrialToken : "invalid", "\n"});
5895+
}
5896+
5897+
return headers;
5898+
}
5899+
5900+
private:
5901+
std::string BuildIframeHTML() {
5902+
std::string html = "<iframe src=\"";
5903+
base::StrAppend(&html,
5904+
{kCookieOriginUrl, "/partitioned_cookies_embeddee.html",
5905+
"\"></iframe>"});
5906+
return html;
5907+
}
5908+
};
5909+
5910+
IN_PROC_BROWSER_TEST_F(EmbeddedPartitionedCookiesOriginTrialBrowserTest,
5911+
ValidTokenAndHeaderPresent) {
5912+
SetTestOptions(
5913+
{/*has_ot_token=*/true, /*valid_ot_token=*/true,
5914+
/*has_accept_ch_header=*/true, /*has_critical_ch_header=*/false},
5915+
{embedder_url(), origin_trial_participant_url()});
5916+
5917+
NavigateTwiceAndCheckClientHint(embedder_url(), true, true);
5918+
}
5919+
5920+
IN_PROC_BROWSER_TEST_F(EmbeddedPartitionedCookiesOriginTrialBrowserTest,
5921+
InvalidToken) {
5922+
SetTestOptions(
5923+
{/*has_ot_token=*/false, /*valid_ot_token=*/true,
5924+
/*has_accept_ch_header=*/true, /*has_critical_ch_header=*/false},
5925+
{embedder_url(), origin_trial_participant_url()});
5926+
5927+
NavigateTwiceAndCheckClientHint(embedder_url(), false, false);
5928+
}
5929+
58055930
class PartitionedCookiesBypassOriginTrialBrowserTest
58065931
: public PartitionedCookiesOriginTrialBrowserTest {
58075932
public:

content/browser/client_hints/client_hints.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ bool IsOriginTrialHintEnabledForFrame(
498498

499499
// TODO(crbug.com/1258063): Delete this function when the UserAgentReduction and
500500
// SendFullUserAgentAfterReduction Origin Trial is finished.
501-
void RemoveAllClientHintsExceptUaReducedOrUaDeprecation(
501+
void RemoveAllClientHintsExceptOriginTrialHints(
502502
const url::Origin& origin,
503503
FrameTreeNode* frame_tree_node,
504504
ClientHintsControllerDelegate* delegate,
@@ -510,7 +510,8 @@ void RemoveAllClientHintsExceptUaReducedOrUaDeprecation(
510510

511511
for (auto it = accept_ch->begin(); it != accept_ch->end();) {
512512
if (*it == WebClientHintsType::kUAReduced ||
513-
*it == WebClientHintsType::kFullUserAgent) {
513+
*it == WebClientHintsType::kFullUserAgent ||
514+
*it == WebClientHintsType::kPartitionedCookies) {
514515
++it;
515516
} else {
516517
it = accept_ch->erase(it);
@@ -1067,7 +1068,7 @@ ParseAndPersistAcceptCHForNavigation(
10671068
// TODO(crbug.com/1258063): Delete this call when the UserAgentReduction
10681069
// Origin Trial is finished.
10691070
if (!frame_tree_node->IsMainFrame()) {
1070-
RemoveAllClientHintsExceptUaReducedOrUaDeprecation(
1071+
RemoveAllClientHintsExceptOriginTrialHints(
10711072
origin, frame_tree_node, delegate, &accept_ch, &main_frame_origin,
10721073
&third_party_origin);
10731074
if (accept_ch.empty()) {

0 commit comments

Comments
 (0)