Skip to content

Commit f3ac8b9

Browse files
committed
Policy updates following addition of Report-Only
1 parent 107fbc1 commit f3ac8b9

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

  • files/en-us/web
    • api/permissionspolicyviolationreport
    • http/reference/headers/permissions-policy

files/en-us/web/api/permissionspolicyviolationreport/index.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ browser-compat: api.ReportingObserver.ReportingObserver.options_parameter.types_
1111

1212
The `PermissionsPolicyViolationReport` dictionary of the [Reporting API](/en-US/docs/Web/API/Reporting_API) represents a report that is generated when a document violates its [Permissions Policy](/en-US/docs/Web/HTTP/Guides/Permissions_Policy).
1313

14-
Reports of this type can be observed from within a page using a {{domxref("ReportingObserver")}}, and a serialized version can be sent to the [default reporting server endpoint](/en-US/docs/Web/HTTP/Reference/Headers/Reporting-Endpoints#default_reporting_endpoint).
14+
Reports of this type can be observed from within a page using a {{domxref("ReportingObserver")}}, and a serialized version can be sent to a reporting endpoint server.
1515

1616
## Instance properties
1717

@@ -47,15 +47,16 @@ Reports of this type can be observed from within a page using a {{domxref("Repor
4747

4848
Permissions Policy violations are reported when a document attempts to use a browser feature that is blocked by its [Permissions Policy](/en-US/docs/Web/HTTP/Guides/Permissions_Policy).
4949
The policy is set using the {{httpheader("Permissions-Policy")}} HTTP header, or a `<meta http-equiv="permissions-policy">` element.
50+
Violations of the policy may also be reported but not enforced using the {{httpheader("Permissions-Policy-Report-Only")}} HTTP header, or a `<meta http-equiv="permissions-policy-report-only">` element.
5051

5152
You can monitor for Permissions-Policy violation reports within the page that sets the policy using the [Reporting API](/en-US/docs/Web/API/Reporting_API).
5253
To do this you create a {{domxref("ReportingObserver")}} object to listen for reports, passing a callback method and an (optional) `options` property specifying the types of reports that you want to report on.
5354
The callback method is then called with reports of the requested types, passing a report object.
54-
For `Permissions-Policy` violations, the object will be a `PermissionsPolicyViolationReport` instance with `PermissionsPolicyViolationReport.type == "permissions-policy-violation"`.
55+
For `Permissions-Policy` or `Permissions-Policy-Report-Only` violations, the object will be a `PermissionsPolicyViolationReport` instance with `PermissionsPolicyViolationReport.type == "permissions-policy-violation"`.
5556

5657
The structure of a typical in-page report is shown below.
5758
Note that we can see the URL of the page that had its policy violated (`url`), and from `body.featureId` we can see which feature was blocked.
58-
The `body.disposition` field shows that the violation was enforced.
59+
The `body.disposition` field shows that the violation was enforced or only reported.
5960

6061
```json
6162
{
@@ -66,14 +67,14 @@ The `body.disposition` field shows that the violation was enforced.
6667
"lineNumber": 44,
6768
"columnNumber": 29,
6869
"featureId": "geolocation",
69-
"disposition": "enforce",
70+
"disposition": "enforce", // Policy was enforced!
7071
"message": "Permissions policy violation: geolocation access has been blocked because of a permissions policy applied to the current document."
7172
}
7273
}
7374
```
7475

75-
Violation reports may also be sent as a JSON object in a {{httpmethod("POST")}} request to the [reporting server endpoint](/en-US/docs/Web/API/Reporting_API#reporting_server_endpoints) named `"default"`, if one is defined.
76-
The reporting server endpoint and its mapping to a particular URL are set using the {{httpheader("Reporting-Endpoints")}} header.
76+
Violation reports may also be sent as a JSON object in a {{httpmethod("POST")}} request to the [reporting server endpoint](/en-US/docs/Web/API/Reporting_API#reporting_server_endpoints) indicated by name in a per-directive `report-to` parameter, or otherwise to the [`default` reporting server endpoint](/en-US/docs/Web/HTTP/Reference/Headers/Reporting-Endpoints#default_reporting_endpoint).
77+
The reporting server endpoint and its mapping to a particular URL are set using the {{httpheader("Reporting-Endpoints")}} response header.
7778

7879
The structure of the server report is almost exactly the same as `PermissionsPolicyViolationReport`, except that it additionally includes `age` and `user_agent` fields.
7980

@@ -163,13 +164,24 @@ Note that the `type` is `"permissions-policy-violation"` and `body.featureId` id
163164

164165
### Sending a Permissions Policy violation report to a reporting endpoint
165166

166-
Here we define the define reporting endpoint named `"default"` using the {{httpheader("Reporting-Endpoints")}} response header, and set the `Permissions-Policy` header to block use of the `geolocation` feature.
167+
This example shows how to configure reporting of `Permissions-Policy` violations to a server endpoint.
168+
169+
The response headers below block geolocation and define the reporting endpoint name for the feature as "geo_endpoint".
170+
The {{HTTPHeader("Reporting-Endpoints")}} HTTP response header is used to define URL of this endpoint name.
167171

168172
```http
169-
Reporting-Endpoints: default="https://example.com/reports"
170-
Permissions-Policy: geolocation=()
173+
Reporting-Endpoints: geo_endpoint="https://example.com/reports"
174+
Permissions-Policy: geolocation=();report-to=geo_endpoint
171175
```
172176

177+
> [!NOTE]
178+
> To send all violation reports to the same endpoint we might instead define the [`"default"` reporting endpoint](/en-US/docs/Web/HTTP/Reference/Headers/Reporting-Endpoints#default_reporting_endpoint):
179+
>
180+
> ```http
181+
> Reporting-Endpoints: default="https://example.com/reports"
182+
> Permissions-Policy: geolocation=()
183+
> ```
184+
173185
As before, a violation is triggered by attempting to use a blocked feature:
174186
175187
```js
@@ -214,6 +226,7 @@ Note that the `type` is `"permissions-policy-violation"` and the `body` property
214226

215227
- {{domxref("ReportingObserver")}}
216228
- {{httpheader("Permissions-Policy")}}
229+
- {{httpheader("Permissions-Policy-Report-Only")}}
217230
- {{httpheader("Reporting-Endpoints")}}
218231
- [Permissions Policy](/en-US/docs/Web/HTTP/Guides/Permissions_Policy)
219232
- [Reporting API](/en-US/docs/Web/API/Reporting_API)

files/en-us/web/http/reference/headers/permissions-policy/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ The [report payload](/en-US/docs/Web/API/Reporting_API#reporting_server_endpoint
395395
## See also
396396

397397
- [Permissions Policy](/en-US/docs/Web/HTTP/Guides/Permissions_Policy)
398+
- {{HTTPHeader("Permissions-Policy-Report-Only")}}
398399
- {{DOMxRef("Document.featurePolicy")}} and {{DOMxRef("FeaturePolicy")}}
399400
- {{HTTPHeader("Content-Security-Policy")}}
400401
- {{HTTPHeader("Referrer-Policy")}}

0 commit comments

Comments
 (0)