EthicsComputerCourses
Join training +91 90532 10052

Permissions Policy

HTML · Lesson 169 of 234 Advanced 11 min read Updated

By the end of this lesson you will be able to write a Permissions-Policy header that switches off the browser features your site does not use, give one embedded partner exactly the feature it needs, read the default rules for frames, and test what a frame is allowed to do.

What you should know first: Secure Iframes & Sandbox Attributes, which introduced the allow attribute, Same-Origin Policy, and at least one powerful API such as the Fullscreen API or the HTML5 Geolocation API.

Policy versus permission

Powerful features such as the camera, microphone and location are protected twice:

  • A permission is the user's answer to a prompt: "Allow shop.example.in to use your location?"
  • A permissions policy is the site's own rule about which pages and frames may ask in the first place.

Think of a girls' hostel in Kochi. The warden's rule says "no visitors on the upper floors". If a visitor asks a student to let her up, the student's "yes" does not matter: the rule already said no. The policy is the warden's rule. The user's permission is the student's answer, and it is asked only where the rule allows.

When a policy blocks a feature, the browser does not show a prompt at all. The API simply fails, and navigator.permissions.query() reports "denied". That protects your visitors if a script you load, or a frame you embed, ever turns hostile.

The header syntax

The Permissions-Policy response header is a comma-separated list of feature=allowlist pairs. It uses the HTTP "structured fields" format, which is strict about quotes and brackets.

Text
Permissions-Policy: camera=(), microphone=(), geolocation=(self "https://maps.example.in"), fullscreen=*
AllowlistMeaning
()Nobody, not even your own pages
(self)Only your own origin
(self "https://maps.example.in")Your origin plus that origin; origins go in double quotes
*Every origin, as long as the frame is also given it with allow

Features you do not list keep their default. Here is a store-locator page in PHP that uses location itself and in one partner's map, and turns off what it never needs:

PHP
<?php
declare(strict_types=1);

// Store locator: we use location ourselves and in our maps partner's frame, nothing else.
header('Permissions-Policy: camera=(), microphone=(), payment=(), '
    . 'geolocation=(self "https://maps.example.in"), fullscreen=(self "https://video.example.in")');

With PHP 8.4's built-in server, curl -s -I http://127.0.0.1:8473/store.php | grep -i "^HTTP\|^permissions" prints:

Output
HTTP/1.1 200 OK
Permissions-Policy: camera=(), microphone=(), payment=(), geolocation=(self "https://maps.example.in"), fullscreen=(self "https://video.example.in")

On Apache, the same goes in .htaccess with mod_headers, for example Header always set Permissions-Policy "camera=(), microphone=(), geolocation=(self)".

Default allowlists

Every feature has a default allowlist that applies when no policy mentions it. Most powerful features default to self: your own pages and same-origin frames may use them, cross-origin frames may not unless you grant them. A few harmless features default to *.

FeatureControlsDefault
camera, microphonegetUserMedia()self
geolocationnavigator.geolocationself
fullscreenrequestFullscreen()self
paymentPayment Request APIself
autoplayVideo and audio playing with sound without a clickself
display-captureScreen sharing with getDisplayMedia()self
picture-in-pictureFloating video window*

These defaults were checked in Chrome 157 by asking a cross-origin frame which features it had: only picture-in-picture and sync-xhr were on. Browsers support different feature lists, and Chrome warns Unrecognized feature in the Console for names it does not know.

The iframe allow attribute

A frame gets a feature only when both sides agree: the parent's own policy must include the frame's origin, and the <iframe> must grant it with allow. The allow attribute uses a different, older syntax: semicolons between features, single quotes around keywords, and no quotes around origins.

HTML
<iframe src="https://maps.example.in/embed?q=Connaught+Place"
        title="Map of Connaught Place, Delhi"
        allow="geolocation https://maps.example.in; fullscreen; camera 'none'"></iframe>

A feature with no origin, like fullscreen here, means 'src': the origin of the frame's src. The attribute can never give more than the parent has. In a Chrome 157 test, a page sending Permissions-Policy: geolocation=() embedded a frame with allow="geolocation", and the frame still reported geolocation as blocked. The parent must also hold the feature itself: with payment=("https://pay.example.in") and no self, the payment frame stayed blocked even with allow="payment". Always include self for a feature you delegate.

Parent header for the featureFrame allowCross-origin frame gets it?
Not set (default self)Not setNo
Not set (default self)allow="geolocation"Yes
geolocation=(self "https://maps.example.in")allow="geolocation"Only if the frame is maps.example.in
geolocation=()allow="geolocation"No

Step 1: test four frames

This page creates four hidden frames: two with your origin (srcdoc) and two with an opaque origin (data: URLs), with and without allow. Each frame reports document.fullscreenEnabled, which every modern browser supports, and, where the browser has it, the list of features document.featurePolicy says it may use.

HTMLOpen in editor
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Which features may each frame use?</title>
  <style>
    body { font-family: sans-serif; padding: 1rem; }
    table { border-collapse: collapse; }
    td, th { border: 1px solid #bbb; padding: 4px 8px; text-align: start; font-size: 0.9rem; }
    #frames { display: none; }
  </style>
</head>
<body>
  <table>
    <thead><tr><th>Frame</th><th>fullscreenEnabled</th><th>Policy allows (Chromium only)</th></tr></thead>
    <tbody id="rows"></tbody>
  </table>
  <div id="frames"></div>
  <script>
    // This little page runs inside every frame and reports what its policy allows.
    const reporter = `<script>
      const features = ["camera", "microphone", "geolocation", "fullscreen", "payment", "autoplay", "picture-in-picture"];
      const policy = document.featurePolicy;
      const allowed = policy ? features.filter((f) => policy.allowsFeature(f)).join(", ") || "none of these"
                             : "document.featurePolicy is not supported here";
      parent.postMessage({ fullscreen: document.fullscreenEnabled, allowed }, "*");
    <\/script>`;

    const cases = [
      ["1. Same origin, no allow", "srcdoc", null],
      ["2. Same origin, features switched off", "srcdoc", "camera 'none'; geolocation 'none'; fullscreen 'none'"],
      ["3. Cross-origin, no allow", "data", null],
      ["4. Cross-origin, allow given", "data", "fullscreen; geolocation; camera"]
    ];
    const senders = new Map();

    for (const [label, kind, allow] of cases) {
      const row = document.querySelector("#rows").insertRow();
      row.insertCell().textContent = label + (allow ? ` (allow="${allow}")` : "");
      row.insertCell().textContent = "...";
      row.insertCell().textContent = "...";
      const frame = document.createElement("iframe");
      if (allow) frame.allow = allow;
      if (kind === "srcdoc") frame.srcdoc = reporter;
      else frame.src = "data:text/html," + encodeURIComponent(reporter);
      document.querySelector("#frames").append(frame);
      senders.set(frame.contentWindow, row);
    }

    window.addEventListener("message", (event) => {
      const row = senders.get(event.source);
      if (!row) return;
      row.cells[1].textContent = event.data.fullscreen;
      row.cells[2].textContent = event.data.allowed;
    });
  </script>
</body>
</html>

In Chrome 157 the table showed:

FramefullscreenEnabledPolicy allows
1. Same origin, no allowtruecamera, microphone, geolocation, fullscreen, payment, autoplay, picture-in-picture
2. Same origin, features switched offfalsemicrophone, payment, autoplay, picture-in-picture
3. Cross-origin, no allowfalsepicture-in-picture
4. Cross-origin, allow giventruecamera, geolocation, fullscreen, picture-in-picture

Row 2 shows that allow can also switch features off for a frame from your own site. Row 3 shows the default self rule keeping a foreign frame away from everything powerful. If a feature shows as blocked even in row 1, the server of the page around the editor has turned it off with its own header, which proves the "both sides must agree" rule.

Step 2: watch a blocked call fail

The two frames below hold the same seat map for a cricket stadium. The second frame has allow="fullscreen 'none'". Click Full screen in each.

HTMLOpen in editor
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Full screen with and without allow</title>
  <style>
    body { font-family: sans-serif; padding: 1rem; }
    iframe { inline-size: 18rem; block-size: 8rem; border: 1px solid #999; margin: 0 0.5rem 0.5rem 0; }
  </style>
</head>
<body>
  <p>Each frame holds the same seat map with a full-screen button.</p>
  <iframe id="open" title="Seat map with fullscreen allowed"></iframe>
  <iframe id="closed" title="Seat map with fullscreen blocked" allow="fullscreen 'none'"></iframe>
  <script>
    const seatMap = `<!DOCTYPE html>
      <body style="font-family: sans-serif; background: #fff8e1">
        <p>Wankhede stand, block C</p>
        <button id="big">Full screen</button>
        <p id="msg"></p>
        <script>
          document.getElementById("big").addEventListener("click", async () => {
            const msg = document.getElementById("msg");
            try {
              await document.documentElement.requestFullscreen();
              msg.textContent = "Full screen! Press Esc to leave.";
            } catch (error) {
              msg.textContent = error.name + ": " + error.message;
            }
          });
        <\/script>
      </body>`;
    document.querySelector("#open").srcdoc = seatMap;
    document.querySelector("#closed").srcdoc = seatMap;
  </script>
</body>
</html>

The first frame fills the screen; press Esc to come back. The second shows TypeError: Disallowed by permissions policy, with no prompt, and Chrome's Console adds Permissions policy violation: fullscreen is not allowed in this document. Firefox and Safari word the error differently.

Checking the policy from JavaScript

There is no cross-browser API to read the full policy yet. What exists today:

  • document.featurePolicy in Chromium browsers, with allowsFeature(name), features(), allowedFeatures() and getAllowlistForFeature(name). It keeps the old "feature policy" name. Firefox has it only behind a hidden preference, Safari not at all, and Chrome 157 has no document.permissionsPolicy.
  • Feature-specific checks that work everywhere, such as document.fullscreenEnabled.
  • navigator.permissions.query({ name: "geolocation" }), which returns "denied" without a prompt when the policy blocks the feature.

So feature-detect before you call:

JavaScript
const policy = document.featurePolicy;
if (policy && !policy.allowsFeature("geolocation")) {
  showMessage("Location is switched off on this page. Type your PIN code instead.");
}

Browser support and the legacy header

The Permissions-Policy header works in Chromium browsers (Chrome, Edge, Opera, Samsung Internet). MDN's compatibility data (checked November 2026) lists no support for the header in Firefox or Safari, but both support the allow attribute on frames, which is where the risk usually is. So send the header for the browsers that read it, and always use allow on frames.

Common mistakes

  • CSP-style syntax in the header. camera 'none' breaks the whole header; write camera=().
  • Unquoted origins in the header. Write (self "https://maps.example.in"), not (self https://maps.example.in).
  • Thinking allow grants permission. It only lets the frame ask; the user still decides.
  • Switching off a feature you use. geolocation=() also breaks your own store locator.
  • Delegating without self. A frame cannot get a feature its parent does not hold.
  • Trusting the header alone. Firefox and Safari ignore it; keep allow tight on every frame.

Interview questions

1. What is the difference between a permission and a permissions policy?

A permission is the user's decision in a browser prompt. A permissions policy is the site's rule about which documents may request a feature at all. If the policy blocks a feature, no prompt is shown and the API fails at once.

2. Explain Permissions-Policy: camera=(), geolocation=(self "https://maps.example.in").

The camera is off for the page and every frame in it. Location may be used by the page's own origin and by frames from https://maps.example.in, and those frames must also be given allow="geolocation". Other features keep their defaults.

3. What is the default allowlist, and why does it matter for iframes?

It is the rule used when no policy mentions a feature. For most powerful features it is self, so same-origin frames get them but cross-origin frames do not unless the parent grants them with allow. A few features, such as picture-in-picture, default to *.

4. Can the allow attribute give a frame a feature the parent page does not have?

No. Delegation can only narrow. If the parent's header switches a feature off, or does not list the frame's origin, allow on the iframe has no effect.

5. How is Feature-Policy different from Permissions-Policy?

Feature-Policy is the older name with CSP-like syntax, such as camera 'none'. Permissions-Policy uses structured-field syntax, such as camera=(). Chrome still reads the old header where the new one is silent, but new code should use Permissions-Policy.

Key points

  • Permissions Policy decides whether a document may even ask for a powerful feature; the user's permission comes after.
  • Header syntax: feature=(), feature=(self), feature=(self "https://origin") or feature=*.
  • A syntax error drops the whole header, so check the Console after every change.
  • Most powerful features default to self; cross-origin frames need both the parent's policy and allow.
  • allow can switch features off for a frame and can never grant more than the parent has.
  • The header is Chromium-only; allow on frames works in all major browsers. document.featurePolicy is Chromium-only.

Exercise

Meera's tiffin-delivery site in Pune has a checkout page that embeds a payment frame from https://pay.example.in and a delivery map from https://maps.example.in. The site itself uses location for "detect my address" but never uses the camera, microphone or screen sharing. Write the Permissions-Policy header, the two <iframe> tags, and explain what happens if the map provider's script ever tries to open the camera.

Show solution
Text
Permissions-Policy: camera=(), microphone=(), display-capture=(), geolocation=(self "https://maps.example.in"), payment=(self "https://pay.example.in"), fullscreen=(self)
HTML
<iframe src="https://pay.example.in/checkout?order=7781" title="Payment"
        allow="payment"></iframe>
<iframe src="https://maps.example.in/route?to=Kothrud" title="Delivery route"
        allow="geolocation" loading="lazy"></iframe>

The payment frame gets only payment, and the map frame only geolocation. If the map's script calls getUserMedia() for the camera, it fails at once with no prompt, because the header sets camera=() for every document on the page. payment must include self even though Meera's own pages never call the Payment Request API, because a page can only delegate a feature it holds itself.

Quick Quiz

1. Which header value switches the microphone off for the page and all its frames?

2. A cross-origin iframe has no allow attribute and the parent sends no policy. Can it request the camera?

3. The parent sends geolocation=() and the iframe has allow="geolocation". What does the frame get?

4. Which check works in all modern browsers to see if full screen is allowed in this document?

Learn HTML with a mentor

Free lessons get you started. Our Full Stack Web Development training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call