Commit 6d865448 authored by Shuran Huang's avatar Shuran Huang Committed by Commit Bot

Add counter for same-site/cross-site postMessage.

Add use counter to collect UMA metrics of when postMessage is called
between top-level windows on a same-site and cross-site basis, and
when targetOrigin is not specified. When is called for cross-site,
metrics will be measured in UKM as well.

These metrics will be used to understand how postMessage is used
between sites to come up with future plans for postMessage API changes.

Bug: 1112491
Change-Id: I0b023067c289d0a957c28100cf7c591c97030d4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2337263
Commit-Queue: Shuran Huang <shuuran@chromium.org>
Reviewed-by: default avatarBrian White <bcwhite@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798833}
parent 3a0baccb
...@@ -175,6 +175,10 @@ UseCounterPageLoadMetricsObserver::GetAllowedUkmFeatures() { ...@@ -175,6 +175,10 @@ UseCounterPageLoadMetricsObserver::GetAllowedUkmFeatures() {
WebFeature::kStorageAccessAPI_requestStorageAccess_Method, WebFeature::kStorageAccessAPI_requestStorageAccess_Method,
WebFeature::kThirdPartyCookieRead, WebFeature::kThirdPartyCookieRead,
WebFeature::kThirdPartyCookieWrite, WebFeature::kThirdPartyCookieWrite,
WebFeature::kCrossSitePostMessage,
WebFeature::kSchemelesslySameSitePostMessage,
WebFeature::kSchemelesslySameSitePostMessageSecureToInsecure,
WebFeature::kSchemelesslySameSitePostMessageInsecureToSecure,
})); }));
return *opt_in_features; return *opt_in_features;
} }
\ No newline at end of file
...@@ -2738,6 +2738,12 @@ enum WebFeature { ...@@ -2738,6 +2738,12 @@ enum WebFeature {
kThirdPartyCookieRead = 3408, kThirdPartyCookieRead = 3408,
kThirdPartyCookieWrite = 3409, kThirdPartyCookieWrite = 3409,
kRTCLegacyRtpDataChannelNegotiated = 3410, kRTCLegacyRtpDataChannelNegotiated = 3410,
kCrossSitePostMessage = 3411,
kSchemelesslySameSitePostMessage = 3412,
kSchemefulSameSitePostMessage = 3413,
kUnspecifiedTargetOriginPostMessage = 3414,
kSchemelesslySameSitePostMessageSecureToInsecure = 3415,
kSchemelesslySameSitePostMessageInsecureToSecure = 3416,
// Add new features immediately above this line. Don't change assigned // Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots. // numbers of any item, and don't reuse removed slots.
......
...@@ -529,6 +529,9 @@ void DOMWindow::DoPostMessage(scoped_refptr<SerializedScriptValue> message, ...@@ -529,6 +529,9 @@ void DOMWindow::DoPostMessage(scoped_refptr<SerializedScriptValue> message,
PostMessageHelper::GetTargetOrigin(options, *source, exception_state); PostMessageHelper::GetTargetOrigin(options, *source, exception_state);
if (exception_state.HadException()) if (exception_state.HadException())
return; return;
if (!target) {
UseCounter::Count(source, WebFeature::kUnspecifiedTargetOriginPostMessage);
}
auto channels = MessagePort::DisentanglePorts(GetExecutionContext(), ports, auto channels = MessagePort::DisentanglePorts(GetExecutionContext(), ports,
exception_state); exception_state);
...@@ -537,12 +540,12 @@ void DOMWindow::DoPostMessage(scoped_refptr<SerializedScriptValue> message, ...@@ -537,12 +540,12 @@ void DOMWindow::DoPostMessage(scoped_refptr<SerializedScriptValue> message,
const SecurityOrigin* target_security_origin = const SecurityOrigin* target_security_origin =
GetFrame()->GetSecurityContext()->GetSecurityOrigin(); GetFrame()->GetSecurityContext()->GetSecurityOrigin();
const SecurityOrigin* source_security_origin = source->GetSecurityOrigin();
auto* local_dom_window = DynamicTo<LocalDOMWindow>(this); auto* local_dom_window = DynamicTo<LocalDOMWindow>(this);
KURL target_url = local_dom_window KURL target_url = local_dom_window
? local_dom_window->Url() ? local_dom_window->Url()
: KURL(NullURL(), target_security_origin->ToString()); : KURL(NullURL(), target_security_origin->ToString());
if (MixedContentChecker::IsMixedContent(source->GetSecurityOrigin(), if (MixedContentChecker::IsMixedContent(source_security_origin, target_url)) {
target_url)) {
UseCounter::Count(source, WebFeature::kPostMessageFromSecureToInsecure); UseCounter::Count(source, WebFeature::kPostMessageFromSecureToInsecure);
} else if (MixedContentChecker::IsMixedContent(target_security_origin, } else if (MixedContentChecker::IsMixedContent(target_security_origin,
source->Url())) { source->Url())) {
...@@ -555,6 +558,34 @@ void DOMWindow::DoPostMessage(scoped_refptr<SerializedScriptValue> message, ...@@ -555,6 +558,34 @@ void DOMWindow::DoPostMessage(scoped_refptr<SerializedScriptValue> message,
} }
} }
if (source->GetFrame() &&
source->GetFrame()->Tree().Top() != GetFrame()->Tree().Top()) {
if ((!target_security_origin->RegistrableDomain() &&
target_security_origin->Host() == source_security_origin->Host()) ||
(target_security_origin->RegistrableDomain() &&
target_security_origin->RegistrableDomain() ==
source_security_origin->RegistrableDomain())) {
if (target_security_origin->Protocol() ==
source_security_origin->Protocol()) {
UseCounter::Count(source, WebFeature::kSchemefulSameSitePostMessage);
} else {
UseCounter::Count(source, WebFeature::kSchemelesslySameSitePostMessage);
if (MixedContentChecker::IsMixedContent(source_security_origin,
target_url)) {
UseCounter::Count(
source,
WebFeature::kSchemelesslySameSitePostMessageSecureToInsecure);
} else if (MixedContentChecker::IsMixedContent(target_security_origin,
source->Url())) {
UseCounter::Count(
source,
WebFeature::kSchemelesslySameSitePostMessageInsecureToSecure);
}
}
} else {
UseCounter::Count(source, WebFeature::kCrossSitePostMessage);
}
}
if (!source->GetContentSecurityPolicy()->AllowConnectToSource( if (!source->GetContentSecurityPolicy()->AllowConnectToSource(
target_url, target_url, RedirectStatus::kNoRedirect, target_url, target_url, RedirectStatus::kNoRedirect,
ReportingDisposition::kSuppressReporting)) { ReportingDisposition::kSuppressReporting)) {
......
...@@ -28757,6 +28757,12 @@ Called by update_use_counter_feature_enum.py.--> ...@@ -28757,6 +28757,12 @@ Called by update_use_counter_feature_enum.py.-->
<int value="3408" label="ThirdPartyCookieRead"/> <int value="3408" label="ThirdPartyCookieRead"/>
<int value="3409" label="ThirdPartyCookieWrite"/> <int value="3409" label="ThirdPartyCookieWrite"/>
<int value="3410" label="RTCLegacyRtpDataChannelNegotiated"/> <int value="3410" label="RTCLegacyRtpDataChannelNegotiated"/>
<int value="3411" label="CrossSitePostMessage"/>
<int value="3412" label="SchemelesslySameSitePostMessage"/>
<int value="3413" label="SchemefulSameSitePostMessage"/>
<int value="3414" label="UnspecifiedTargetOriginPostMessage"/>
<int value="3415" label="SchemelesslySameSitePostMessageSecureToInsecure"/>
<int value="3416" label="SchemelesslySameSitePostMessageInsecureToSecure"/>
</enum> </enum>
<enum name="FeaturePolicyAllowlistType"> <enum name="FeaturePolicyAllowlistType">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment