Your site never uses the camera? Turn it off with Permissions-Policy

The Permissions-Policy header tells the browser which features are allowed on your page and in the iframes inside it. The value () turns a feature off everywhere, so turn off the camera, microphone and location if you don't use them.

Published 2 min read#App security#Web development#Privacy

Your site never asks for the camera, the microphone or the visitor's location. But you have an ad script, a video iframe and a chat widget from another company, all running on the same page. This article shows you how to tell the browser, with one header, that these features are closed, even if something inside the page asks for them.

What is the Permissions-Policy header?

The Permissions-Policy header is an HTTP response header that allows or denies browser features on your page and in every iframe inside it. The features are things like the camera, the microphone and geolocation.

According to the MDN page on the Permissions-Policy header, it looks like Permissions-Policy: <directive>=<allowlist>, which means the feature's name, then who may use it.

Why isn't "I don't use it" enough?

"I don't use it" isn't enough because the page isn't all your code. Every outside script or iframe runs inside your page, so the question is who can ask for the feature.

The human mistake here is simple: we assume a feature we never wrote code for is closed on its own. Nothing guarantees that except an explicit decision from you, written in a header.

What do the values (), self and * mean?

The three values set who may use the feature. () turns it off everywhere, self allows it for your page and same-origin iframes only, and * allows it for any iframe from any origin.

Value

Who can use the feature

()

Nobody: not the page and not any iframe in it

self

Your page and iframes from the same origin only

*

Your page and every iframe, whatever its origin

How do you turn off what you don't use today?

You turn it off by sending the header with every response, with () for each feature you don't use. MDN's own example turns off the microphone and geolocation this way, and the features are off for the whole page and every iframe in it.

Permissions-Policy: camera=(), microphone=(), geolocation=()
  1. List the features your site really uses. Often the list is empty or has one item.

  2. Set every feature you don't use to (), and send the header from the server or the middleware.

  3. If one iframe needs a feature, let the header allow it for that origin, and add the feature's name in the allow attribute on that iframe only. MDN says the header is the upper limit, and the allow attribute grants from inside it.

  4. Open the browser's developer tools and check the header on the page's response.

This header sits next to other headers that protect the same page, like frame protection with frame-ancestors and rolling out CSP in report-only mode.

Where do you start now?

The lesson for us as developers: a feature you don't need should be closed by your decision, because any outside code inside your page can ask for it. Add a Permissions-Policy line today, and turn off the camera, microphone and location in it.

If you want someone to review all the security headers on your site, there is Muhassan. Which outside scripts and iframes are running on your page right now?

FAQ

If I turn off location in the header, will the map iframe on my site stop working?

Yes, if the map asks for the visitor's location. The header is the upper limit, so allow the feature only for the origin that needs it, then grant it with the allow attribute on the iframe.

Does this header replace CSP?

No. CSP controls what loads on the page and from where, and Permissions-Policy controls which browser features may be used. They work together.

Where do I set the header?

In the same place as your other security headers: the server config, your app's middleware, or your hosting platform's settings.

Share

More articles