slop audit
Blog post 62 / Security and launch readiness

Permissions-Policy header: setup and testing guide

Set the Permissions-Policy header, choose feature allowlists, debug blocked iframe permissions, and verify deployed responses and browser tasks before launch.

By Slop Audit · 8 min read

The Permissions-Policy header controls whether a document and its embedded frames may use particular browser features. Before launch, decide which features your page needs, deliver that policy on the public HTML response, and test the affected tasks in a browser.

A portfolio may have no reason to use camera, microphone, or location. A video interview page or nearby-store finder has different requirements. Copying the same restrictive header onto both can break a real task. This guide gives you a small policy, an iframe example, a debugging sequence, and a release check you can adapt.

Permissions-Policy header launch checklist

  1. List features used by your page and each embedded service.
  2. Disable unused features and name required origins explicitly.
  3. Configure the final HTML response at one owned deployment layer.
  4. Inspect the delivered header on representative routes.
  5. Check iframe delegation and the embedded document's own restrictions.
  6. Test allowed, denied, and unavailable-feature experiences in supported browsers.
  7. Save the approved value in CI, then audit the public release.

Use the broader website security headers checklist for HTTPS, CSP, MIME handling, and referrer controls. This article focuses on browser feature access.

Choose feature allowlists by page purpose

For a public page that does not use these three features, start with:

Permissions-Policy: camera=(), microphone=(), geolocation=()

The empty allowlist disables the named feature in the document and its descendants where the browser implements that directive. Header directives use commas. To allow geolocation on your own origin while keeping camera and microphone disabled:

Permissions-Policy: camera=(), microphone=(), geolocation=(self)

self refers to the document's origin. An explicit external origin is quoted inside the parentheses, such as geolocation=(self "https://maps.example.net"). Avoid * unless the product requirement genuinely calls for that breadth. MDN's Permissions-Policy header reference documents the syntax and flags limited browser availability. Review compatibility for each directive you choose.

An omitted directive uses its feature's default allowlist; it does not automatically disable that feature. The W3C Permissions Policy working draft defines these defaults and the distinction between response and container policies. Treat the draft as work in progress and verify behavior in your supported browsers.

Write down the reason for each exception. For example: “The store locator uses geolocation after the visitor selects Find nearby stores; manual address entry remains available.” That gives a reviewer a task to test and a reason to reject an unrelated camera allowance.

Deliver the policy on the final HTML response

Set the header where your application, hosting platform, or reverse proxy creates the response. In a Fetch API response handler, the relevant operation is:

const headers = new Headers(upstreamResponse.headers);
headers.set(
  'Permissions-Policy',
  'camera=(), microphone=(), geolocation=()'
);
return new Response(upstreamResponse.body, {
  status: upstreamResponse.status,
  statusText: upstreamResponse.statusText,
  headers,
});

Adapt this fragment inside an existing handler with an upstreamResponse available. Preserve the application's other headers and response behavior. Apply it to the HTML routes you intend to govern; do not replace an existing route-specific policy without reviewing its requirements. MDN's Headers.set reference describes replacing a header value in a mutable Headers object.

Choose one configuration owner. If application middleware sets one value and a CDN adds another, remove the accidental duplication and verify the public result. Keep a separate locator policy if that route needs location while the homepage does not.

Inspect deployment output with a GET request:

curl --silent --show-error --location \
  --dump-header - --output /dev/null \
  'https://example.com/'

These curl options follow redirects, print response headers, and discard the body. Identify the final HTML response rather than accepting a header attached only to a redirect. Repeat on a nested route and an application-generated error page. Record the final URL, status, policy, and deployment version.

Combine iframe allow with the response policy

Suppose an owned parent page embeds a location widget at https://maps.example.net. Its reviewed header could be:

Permissions-Policy: camera=(), microphone=(), geolocation=(self "https://maps.example.net")

The matching iframe delegates location to that origin:

<iframe
  src="https://maps.example.net/locator"
  title="Nearby store locator"
  allow="geolocation https://maps.example.net"
></iframe>

The iframe attribute uses different syntax from the header. When several features are listed in allow, separate their declarations with semicolons. MDN's iframe allow reference explains that this attribute further restricts the response policy. It cannot restore a feature that the parent policy disabled.

If the parent sends geolocation=(), adding allow="geolocation" does not undo that block. Inspect the child response too: its own restrictions can still deny access. Recheck the actual frame origin after redirects and navigation; an exception for one hostname does not describe every destination a widget might load.

Keep the iframe accessibility checks in the same release review. A frame that receives the right feature allowance still needs a useful title, keyboard access, and a usable failure state.

Diagnose blocked permissions without widening every allowance

A permission error alone does not identify the faulty layer. Use this sequence:

  1. Reproduce the exact task and save the console message.
  2. Identify whether the API runs in the parent document or an iframe.
  3. Inspect that document's URL, response policy, and ancestor frame attributes.
  4. Check HTTPS, browser support, user permission, and operating-system settings.
  5. Change only the policy entry justified by the intended task, then repeat it.

Chrome DevTools exposes allowed and disabled features under Application > Frames > Permissions Policy. Select the affected frame and use its details to investigate a disabled feature. The Chrome frame inspection guide documents this view. Other browsers may expose different diagnostics.

For geolocation specifically, a policy block produces a PERMISSION_DENIED error callback, according to MDN's geolocation directive reference. User refusal can also prevent the task. MDN's getCurrentPosition reference lists secure-context, permission, and policy requirements. Test with a clean permission state so a saved refusal does not hide your fix.

Give visitors a useful alternative when access is unavailable: manual location entry, a file upload, or an ordinary support link, depending on the task. Check the JavaScript console error workflow for separating the original failure from follow-on messages. Do not solve an unknown failure by granting all origins access to every feature.

Add Permissions-Policy header testing to CI

In a project already using Playwright Test, a focused delivery test can catch a missing or changed policy after deployment:

import { test, expect } from '@playwright/test';

const origin = process.env.RELEASE_ORIGIN;
if (!origin) throw new Error('Set RELEASE_ORIGIN to your owned deployment');

const expected = 'camera=(), microphone=(), geolocation=()';

for (const path of ['/', '/docs']) {
  test(`Permissions-Policy on ${path}`, async ({ request }) => {
    const url = new URL(path, origin).href;
    const response = await request.get(url);
    expect(response.status()).toBe(200);
    expect(response.url()).toBe(url);
    expect(response.headers()['content-type']).toContain('text/html');
    expect(response.headers()['permissions-policy']).toBe(expected);
  });
}

Replace the routes and expected string with your approved contract. This intentionally fails on an unexpected redirect or a differently serialized policy; review intentional changes before updating it. Playwright's APIResponse documentation describes the response URL and headers used here.

This test checks delivery, not parsing or effective browser enforcement. Add a separate browser task test for any allowed feature and its denial fallback. In a locator fixture, for example, verify that the page displays a simulated permitted location, then verify manual address entry when permission is denied. Run the same task in the browsers your release supports.

Store those results alongside the expected header in your website regression testing baseline. A passing request test should never substitute for testing an embedded service after a policy change.

Check the public release with Slop Audit

After deployment, run Slop Audit on your public URL. Its static audit records observed Permissions-Policy and Referrer-Policy response headers in a combined finding. Use that evidence to find a missing header, repair the response layer, and rescan the same route.

Slop Audit checks presence here. It does not validate every directive, calculate effective iframe permissions, grant user permission, or exercise camera, microphone, and location tasks. Keep the browser-flow results next to the report so the release record shows both what was measured and what still needs review.

Before sign-off, retain the final header value, tested routes, browser versions, iframe origins, allowed-task results, denied-task fallbacks, and reviewer. That record makes the next deployment's policy change easier to assess.