Skip to content

Commit

Permalink
Remove ambient-light-sensor=() Fix browser warning: Error with Permis…
Browse files Browse the repository at this point in the history
…sions-Policy header: Unrecognized feature: 'ambient-light-sensor'. (#203)

* Remove ambient-light-sensor=() from the Default Permission policy, fix warning in Brower

* Fix defaults
  • Loading branch information
damienbod authored Oct 17, 2024
1 parent 951249a commit 8ecda56
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ As described in the [OWASP guidance](https://cheatsheetseries.owasp.org/cheatshe
* `X-Frame-Options: Deny`
* `Content-Security-Policy: default-src: none; frame-ancestors 'none'`
* `Referrer-Policy: no-referrer`
* `Permissions-Policy: accelerometer=(), ambient-light-sensor=(), autoplay=(), camera=(), display-capture=(), encrypted-media=(), fullscreen=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=()`
* `Permissions-Policy: accelerometer=(), autoplay=(), camera=(), display-capture=(), encrypted-media=(), fullscreen=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=()`

Apply it in the same way to your header policy collection:

Expand Down Expand Up @@ -449,10 +449,6 @@ public void Configure(IApplicationBuilder app)
.Self()
.For("http://testUrl.com");

builder.AddAmbientLightSensor() // ambient-light-sensor 'self' http://testUrl.com
.Self()
.For("http://testUrl.com");

builder.AddAutoplay() // autoplay 'self'
.Self();

Expand Down Expand Up @@ -523,7 +519,7 @@ var policyCollection = new HeaderPolicyCollection()
This applies a "secure" policy based on the [suggested by OWASP for APIs](https://cheatsheetseries.owasp.org/cheatsheets/REST_Security_Cheat_Sheet.html#security-headers):
```HTTP
Permissions-Policy: accelerometer=(), ambient-light-sensor=(), autoplay=(), camera=(), display-capture=(), encrypted-media=(), fullscreen=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=()
Permissions-Policy: accelerometer=(), autoplay=(), camera=(), display-capture=(), encrypted-media=(), fullscreen=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=()
```

Alternatively, if you want to relax some of these directives, you can use the builder version:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ public PermissionsPolicyBuilder AddDefaultSecureDirectives()
{
// https://github.com/w3c/webappsec-permissions-policy/blob/f15a4548691ea69a87227c0f67571da2cc0e08c1/features.md?plain=1#L19
AddAccelerometer().None();
AddAmbientLightSensor().None();
AddAutoplay().None();

// AddBattery().None(); // Request: https://issues.chromium.org/issues/40100229
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class PermissionsPolicyHeaderExtensions
/// The policy applied by <see cref="AddPermissionsPolicyWithDefaultSecureDirectives"/>
/// </summary>
internal const string DefaultSecurePolicy =
"accelerometer=(), ambient-light-sensor=(), autoplay=(), camera=(), display-capture=(), " +
"accelerometer=(), autoplay=(), camera=(), display-capture=(), " +
"encrypted-media=(), fullscreen=(), geolocation=(), gyroscope=(), magnetometer=(), " +
"microphone=(), midi=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), " +
"screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=()";
Expand Down Expand Up @@ -41,7 +41,7 @@ public static HeaderPolicyCollection AddPermissionsPolicy(this HeaderPolicyColle
/// not available by default, or not implemented. For consistency with <see cref="PermissionsPolicyBuilder"/>,
/// those directives are not included in the policy.
///
/// The policy added is equivalent to <c>accelerometer=(), ambient-light-sensor=(),
/// The policy added is equivalent to <c>accelerometer=(),
/// autoplay=(), camera=(), display-capture=(), encrypted-media=(), fullscreen=(),
/// geolocation=(), gyroscope=(), magnetometer=(), microphone=(), midi=(), payment=(),
/// picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(),
Expand Down

0 comments on commit 8ecda56

Please sign in to comment.