# permission replay debugger

- Status: `experiment`
- Track: [delegated authority & keyless execution](https://aifoc.us/labs/delegated-authority/)
- Layer: 3. Identity, Permissions & Delegated Authority
- Updated: 1 December 2026
- Live demo: https://permission-replay-debugger.kinlan-test.workers.dev
- Source: https://github.com/PaulKinlan/permission-replay-debugger

## Inspired by

- [my chrome extensions are just prompts](https://aifoc.us/my-chrome-extensions-are-just-prompts/)
- [agent-do: my agent loop](https://aifoc.us/agent-do-my-agent-loop/)

## Why this matters

When third-party scripts, embedded widgets, or browser extensions try to access camera, microphone, location, or USB APIs, standard JavaScript errors do not separate a user denial from an HTTP policy block or link the violation back to the script step that triggered it. Turning live permission checks and violation reports into a replayable audit log makes least-privilege gaps inspectable before shipping.

## What this opens up

Developers can record, export, and re-import browser permission traces as plain `.jsonl` files, diff Enforcing vs. Report-Only `Permissions-Policy` rules offline before rolling out stricter headers, and measure silent browser denials that block a call without emitting a `ReportingObserver` event.

## How the tests work

1. Click **Scan 6 Browser Permissions** to query `camera`, `microphone`, `geolocation`, `notifications`, `clipboard-read`, and `persistent-storage` via `navigator.permissions.query()` without triggering user popups.
2. Click **Run 4 Blocked Probes in Iframe** to dispatch camera, microphone, geolocation, and WebUSB attempts inside `/probe/restricted-policy` and correlate captured `ReportingObserver` violations against silent reporting gaps.
3. Click **Save & Verify OPFS Audit File** to persist `perm-journal.jsonl` to the browser's Origin Private File System, read it back, and check the line-by-line disk diff.
4. Edit the **Editable Policy Matrix** (or import a saved `.jsonl` trace) and click **Compare Enforcing vs. Report-Only** or **Replay Stored Trace Against Policy** to see which recorded steps flip between allowed and blocked.


## Hypothesis

- **Claim:** Correlating `navigator.permissions.query()`, Enforcing vs. Report-Only HTTP `Permissions-Policy` frame blocks, and `ReportingObserver` / `Reporting-Endpoints` reports into a portable `.jsonl` trace makes unattended permission escalation and silent reporting gaps inspectable before deployment.
- **Confirms it:** Restricted iframe probes emit captureable `ReportingObserver` and SQLite `ReportCollector` entries linked to initiating step IDs, Enforcing vs. Report-Only replay diffs isolate policy flips cleanly, and exported `.jsonl` traces re-import deterministically.
- **Bounds or disproves it:** Silent browser permission denials or uninstrumented third-party frames block calls while emitting zero `ReportingObserver` records, leaving blind spots measured under `Reporting Gaps`.


## Under the hood

[Permission Replay Debugger](https://permission-replay-debugger.kinlan-test.workers.dev) ([source on GitHub](https://github.com/PaulKinlan/permission-replay-debugger)) combines live iframe header enforcement with offline trace replay:

- **Live probe frame & delegation toggles (`/probe/restricted-policy`):** the Worker serves configurable `Permissions-Policy` and `Permissions-Policy-Report-Only` headers plus a per-run `Reporting-Endpoints` sink. Inside the page, you can toggle `sandbox="allow-scripts"` (opaque `"null"` origin) and the parent `<iframe allow>` attribute to inspect how host delegation interacts with child HTTP headers.
- **Cross-frame violation correlation & server collection:** the probe frame registers a [`ReportingObserver`](https://developer.mozilla.org/en-US/docs/Web/API/ReportingObserver), serializes reports via `.toJSON()` before forwarding them over `postMessage`, and matches each violation to its initiating step by directive, frame origin, and timestamp delta. Simultaneously, browser-delivered `application/reports+json` batches land in the `ReportCollector` SQLite Durable Object.
- **Deterministic replay & OPFS `.jsonl` persistence:** `replayRun()` re-evaluates recorded or imported `.jsonl` entries against any edited Enforcing or Report-Only policy matrix without re-triggering browser hardware prompts, while OPFS writes and diffs `perm-journal.jsonl` locally.


## Key terms & further reading

- [HTTP Permissions-Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Permissions-Policy) — An HTTP response header that allows or blocks sensitive browser APIs (camera, microphone, geolocation, USB) per document or iframe before scripts execute.
- [Reporting-Endpoints](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Reporting-Endpoints) — An HTTP header instructing the browser to POST structured violation batches (`application/reports+json`) asynchronously to a server collector.
- [ReportingObserver](https://developer.mozilla.org/en-US/docs/Web/API/ReportingObserver) — A client-side JavaScript observer that receives policy violation reports in real time so an app can match blocked calls to the step that caused them.
- [Permissions API](https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API) — Provides `navigator.permissions.query()` to read whether a capability is `granted`, `denied`, or `prompt` without showing a permission dialog.
- [Origin Private File System (OPFS)](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system) — Private, origin-scoped local file storage in the browser, used here to store, diff, and export newline-delimited JSON (`.jsonl`) audit traces.
- [Cloudflare Durable Objects (ReportCollector)](https://developers.cloudflare.com/durable-objects/) — A per-session SQLite-backed edge endpoint collecting asynchronous browser violation reports at `/api/report/:runId`.

## Open questions to iterate on

- Which APIs omit `ReportingObserver` reports when blocked by `Permissions-Policy` (`clipboard-read`, `geolocation`, USB/serial prompts)?
- Can `PerformanceObserver` event timing and console instrumentation link permission requests back to specific script URLs?

## Iteration log

- **2026-12-01:** Built Permissions API scanner, `/probe/restricted-policy` iframe test, OPFS JSONL journal, and developer code blueprint.
- **2026-12-01:** Reordered page around live permission replay and silent-denial gap telemetry, added pure-DOM syntax highlighting, hardened 700px responsive layout, and enforced no-cache headers on static assets.
- **2026-12-02:** Moved into Track 4 (`delegated-authority`), added `.jsonl` trace import alongside OPFS export, added Enforcing vs. Report-Only `Permissions-Policy` replay diffing, backed reporting endpoints with a SQLite `ReportCollector` Durable Object, and shipped dark mode, `?embed=1` height bridging, and `@container` diagrams.

## Primitives tested

- `Permissions API`
- `Permissions-Policy (Enforcing & Report-Only)`
- `OPFS JSONL Journal`
- `ReportingObserver`
- `Durable Object SQLite (ReportCollector)`

## Connected labs in other tracks

- [self-observing web fault bundler](https://aifoc.us/labs/platform-observability/self-observing-web/) — Captures broader LoAF, CLS, and fetch regressions into JSON replay bundles.
- [passkey attenuated capabilities](https://aifoc.us/labs/delegated-authority/passkey-agent-caps/) — Combines hardware passkey presence with delegated capability spend caps.

---
Canonical: https://aifoc.us/labs/delegated-authority/permission-replay-debugger/
