Commit 70d0600a authored by Mike West's avatar Mike West Committed by Chromium LUCI CQ

Measure `unsafe-url` usage.

We never landed metrics to measure the impact of the proposal in
https://github.com/w3c/webappsec-referrer-policy/pull/124. This
patch remedies that oversight.

Bug: 1158426
Change-Id: Iccde2a755d7003a401a80e6c085a5ad97ac87389
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2589875Reviewed-by: default avatarEric Lawrence [MSFT] <ericlaw@microsoft.com>
Commit-Queue: Mike West <mkwst@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837484}
parent 9bb9dc3a
...@@ -3064,6 +3064,7 @@ enum WebFeature { ...@@ -3064,6 +3064,7 @@ enum WebFeature {
kCrossOriginSubframeWithoutEmbeddingControl = 3742, kCrossOriginSubframeWithoutEmbeddingControl = 3742,
kReadableStreamWithByteSource = 3743, kReadableStreamWithByteSource = 3743,
kReadableStreamBYOBReader = 3744, kReadableStreamBYOBReader = 3744,
kSetReferrerPolicyUnsafeUrlInSecureContext = 3745,
// 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.
......
...@@ -406,6 +406,11 @@ void ExecutionContext::SetReferrerPolicy( ...@@ -406,6 +406,11 @@ void ExecutionContext::SetReferrerPolicy(
UseCounter::Count(this, WebFeature::kSetReferrerPolicy); UseCounter::Count(this, WebFeature::kSetReferrerPolicy);
if (referrer_policy_ != network::mojom::ReferrerPolicy::kDefault) if (referrer_policy_ != network::mojom::ReferrerPolicy::kDefault)
UseCounter::Count(this, WebFeature::kResetReferrerPolicy); UseCounter::Count(this, WebFeature::kResetReferrerPolicy);
if (IsSecureContext() &&
referrer_policy == network::mojom::ReferrerPolicy::kAlways) {
UseCounter::Count(this,
WebFeature::kSetReferrerPolicyUnsafeUrlInSecureContext);
}
referrer_policy_ = referrer_policy; referrer_policy_ = referrer_policy;
} }
......
...@@ -505,6 +505,11 @@ void HTMLAnchorElement::HandleClick(Event& event) { ...@@ -505,6 +505,11 @@ void HTMLAnchorElement::HandleClick(Event& event) {
!HasRel(kRelationNoReferrer)) { !HasRel(kRelationNoReferrer)) {
UseCounter::Count(GetDocument(), UseCounter::Count(GetDocument(),
WebFeature::kHTMLAnchorElementReferrerPolicyAttribute); WebFeature::kHTMLAnchorElementReferrerPolicyAttribute);
if (GetDocument().GetExecutionContext()->IsSecureContext() &&
policy == network::mojom::ReferrerPolicy::kAlways) {
UseCounter::Count(GetDocument(),
WebFeature::kSetReferrerPolicyUnsafeUrlInSecureContext);
}
request.SetReferrerPolicy(policy); request.SetReferrerPolicy(policy);
} }
......
...@@ -184,6 +184,12 @@ void HTMLIFrameElement::ParseAttribute( ...@@ -184,6 +184,12 @@ void HTMLIFrameElement::ParseAttribute(
value, kSupportReferrerPolicyLegacyKeywords, &referrer_policy_); value, kSupportReferrerPolicyLegacyKeywords, &referrer_policy_);
UseCounter::Count(GetDocument(), UseCounter::Count(GetDocument(),
WebFeature::kHTMLIFrameElementReferrerPolicyAttribute); WebFeature::kHTMLIFrameElementReferrerPolicyAttribute);
if (GetDocument().GetExecutionContext()->IsSecureContext() &&
referrer_policy_ == network::mojom::ReferrerPolicy::kAlways) {
UseCounter::Count(
GetDocument(),
WebFeature::kSetReferrerPolicyUnsafeUrlInSecureContext);
}
} }
} else if (name == html_names::kAllowfullscreenAttr) { } else if (name == html_names::kAllowfullscreenAttr) {
bool old_allow_fullscreen = allow_fullscreen_; bool old_allow_fullscreen = allow_fullscreen_;
......
...@@ -286,7 +286,11 @@ void HTMLImageElement::ParseAttribute( ...@@ -286,7 +286,11 @@ void HTMLImageElement::ParseAttribute(
params.new_value, kSupportReferrerPolicyLegacyKeywords, params.new_value, kSupportReferrerPolicyLegacyKeywords,
&referrer_policy_); &referrer_policy_);
} }
if (GetDocument().GetExecutionContext()->IsSecureContext() &&
referrer_policy_ == network::mojom::ReferrerPolicy::kAlways) {
UseCounter::Count(GetDocument(),
WebFeature::kSetReferrerPolicyUnsafeUrlInSecureContext);
}
if (referrer_policy_ != old_referrer_policy) { if (referrer_policy_ != old_referrer_policy) {
GetImageLoader().UpdateFromElement( GetImageLoader().UpdateFromElement(
ImageLoader::kUpdateIgnorePreviousError, referrer_policy_); ImageLoader::kUpdateIgnorePreviousError, referrer_policy_);
......
...@@ -122,6 +122,12 @@ void HTMLLinkElement::ParseAttribute( ...@@ -122,6 +122,12 @@ void HTMLLinkElement::ParseAttribute(
value, kDoNotSupportReferrerPolicyLegacyKeywords, &referrer_policy_); value, kDoNotSupportReferrerPolicyLegacyKeywords, &referrer_policy_);
UseCounter::Count(GetDocument(), UseCounter::Count(GetDocument(),
WebFeature::kHTMLLinkElementReferrerPolicyAttribute); WebFeature::kHTMLLinkElementReferrerPolicyAttribute);
if (GetDocument().GetExecutionContext()->IsSecureContext() &&
referrer_policy_ == network::mojom::ReferrerPolicy::kAlways) {
UseCounter::Count(
GetDocument(),
WebFeature::kSetReferrerPolicyUnsafeUrlInSecureContext);
}
} }
} else if (name == html_names::kSizesAttr) { } else if (name == html_names::kSizesAttr) {
sizes_->DidUpdateAttributeValue(params.old_value, value); sizes_->DidUpdateAttributeValue(params.old_value, value);
......
...@@ -494,6 +494,12 @@ void HTMLPortalElement::ParseAttribute( ...@@ -494,6 +494,12 @@ void HTMLPortalElement::ParseAttribute(
SecurityPolicy::ReferrerPolicyFromString( SecurityPolicy::ReferrerPolicyFromString(
params.new_value, kDoNotSupportReferrerPolicyLegacyKeywords, params.new_value, kDoNotSupportReferrerPolicyLegacyKeywords,
&referrer_policy_); &referrer_policy_);
if (GetDocument().GetExecutionContext()->IsSecureContext() &&
referrer_policy_ == network::mojom::ReferrerPolicy::kAlways) {
UseCounter::Count(
GetDocument(),
WebFeature::kSetReferrerPolicyUnsafeUrlInSecureContext);
}
} }
return; return;
} }
......
...@@ -464,6 +464,11 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position, ...@@ -464,6 +464,11 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
SecurityPolicy::ReferrerPolicyFromString( SecurityPolicy::ReferrerPolicyFromString(
referrerpolicy_attr, kDoNotSupportReferrerPolicyLegacyKeywords, referrerpolicy_attr, kDoNotSupportReferrerPolicyLegacyKeywords,
&referrer_policy); &referrer_policy);
if (context_window->IsSecureContext() &&
referrer_policy == network::mojom::ReferrerPolicy::kAlways) {
UseCounter::Count(*context_window,
WebFeature::kSetReferrerPolicyUnsafeUrlInSecureContext);
}
} }
// Priority Hints is currently a non-standard feature, but we can assume the // Priority Hints is currently a non-standard feature, but we can assume the
......
...@@ -30679,6 +30679,7 @@ Called by update_use_counter_feature_enum.py.--> ...@@ -30679,6 +30679,7 @@ Called by update_use_counter_feature_enum.py.-->
<int value="3742" label="CrossOriginSubframeWithoutEmbeddingControl"/> <int value="3742" label="CrossOriginSubframeWithoutEmbeddingControl"/>
<int value="3743" label="ReadableStreamWithByteSource"/> <int value="3743" label="ReadableStreamWithByteSource"/>
<int value="3744" label="ReadableStreamBYOBReader"/> <int value="3744" label="ReadableStreamBYOBReader"/>
<int value="3745" label="SetReferrerPolicyUnsafeUrlInSecureContext"/>
</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