> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blobhub.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Security Model

> What the platform enforces about a custom widget and the person looking at it, and what it cannot close.

A [custom widget](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widgets.md) is code from a blob, running in the browser of
whoever opens a playground that places it. This page states what the platform enforces about a widget and the person
looking at it: the frame a widget runs in, the headers its origin serves, the nine rules the platform keeps, and the
risks the platform cannot close. [Custom Widgets](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widgets.md) describes
permissions and trust at install, and the [Bridge Protocol](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-bridge.md) every
call and refusal; this page links to them rather than repeat them.

## The frame

The playground's page on blobhub.io holds the viewer's login and draws each custom widget's header itself. Below the
header it places the widget in a frame:

```html theme={null}
<iframe src="https://<label>.widgets.playground.blobhub.io/"
        sandbox="allow-scripts allow-same-origin" allow="" referrerpolicy="no-referrer"></iframe>
```

* **The origin.** `<label>` is the first 32 hex characters of the SHA-256 of `<blob id>:<widget alias>`. Every widget of
  every blob has an origin of its own, the same for every revision and every viewer. The host derives the label from the
  blob and the alias, so no definition chooses its origin, and nothing is registered for it. Every build deployed under
  that alias, in any revision of the blob, runs on that origin and shares its
  [storage](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-libraries.md#storage); no other widget and no page on blobhub.io
  shares its storage or can script it.
* **`sandbox="allow-scripts allow-same-origin"`.** The widget's scripts run, and the frame keeps its own real origin, so
  its storage works. That origin is never blobhub.io's, so the frame cannot reach into the page to lift its `sandbox`
  attribute. Every other token is left out: the frame is allowed no forms, popups, top navigation, modals, downloads or
  pointer lock.
* **`allow=""`.** The page delegates none of its permission-policy features to the frame, so the frame gets no camera,
  microphone or location.
* **`referrerpolicy="no-referrer"`.** The frame's request carries no address of the page around it, and the widget finds
  `document.referrer` empty.

Every widget origin serves the same two things, and nothing else:

* `/`, the **bootstrap page**. It accepts one message, from `https://blobhub.io` only: the bridge port. Then it receives
  the widget's files over the bridge, loads them from `blob:` URLs, writes the [import
  map](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-libraries.md#the-import-map) for the libraries the widget declares,
  sets the theme and imports the [entry](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-bridge.md#the-entry).
* `/libs/`, the [library catalog](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-libraries.md#the-catalog), so every
  platform library is served from the origin of the widget that loads it.

## Headers

Every response from a widget origin, the bootstrap page and every catalog file alike, carries these five headers, and no
script in the frame can loosen them. Each is one line as served; the two long ones are wrapped here.

```text theme={null}
Content-Security-Policy: default-src 'none'; script-src 'self' blob: 'unsafe-inline' 'unsafe-eval';
  style-src 'self' blob: 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data: blob:;
  media-src 'self' data: blob:; connect-src 'self'; frame-src 'self' blob:; worker-src blob:;
  form-action 'none'; base-uri 'self'; object-src 'none'; frame-ancestors 'self' https://blobhub.io
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=(), usb=(), xr-spatial-tracking=(),
  clipboard-read=(), clipboard-write=(), web-share=(), serial=(), hid=(), idle-detection=(), bluetooth=()
Referrer-Policy: no-referrer
X-DNS-Prefetch-Control: off
X-Content-Type-Options: nosniff
```

The content security policy exists to cut the frame off from the network, not to restrain the widget's own script, which
is arbitrary code already:

* **`default-src 'none'`** refuses every kind of load the directives below do not name.
* **`script-src 'self' blob: 'unsafe-inline' 'unsafe-eval'`** runs the bootstrap page and the catalog's libraries from
  the origin, and the widget's own modules from the `blob:` URLs the bootstrap makes. Inline scripts and `eval` give a
  widget nothing it lacks.
* **`style-src 'self' blob: 'unsafe-inline'`** applies the catalog's stylesheets, the widget's own from `blob:` URLs,
  and inline styles.
* **`img-src`, `font-src` and `media-src 'self' data: blob:`** load images, fonts and media from the origin, from
  `data:` URLs inlined in the build, and from `blob:` URLs the widget makes, and from no other host.
* **`connect-src 'self'`** lets `fetch`, XHR, WebSocket, server-sent events and beacons reach only the widget's own
  origin, which serves only the static bootstrap page and catalog.
* **`frame-src 'self' blob:`** and **`base-uri 'self'`** are what TradingView, a catalog library, needs: it draws its
  chart in a `blob:` document and sets a `<base>`. A `blob:` document inherits the frame's policy, so neither opens the
  network.
* **`worker-src blob:`** allows a worker only from a `blob:` URL, so a widget cannot register a service worker on its
  origin, which could otherwise serve itself a page without these headers.
* **`form-action 'none'`** and **`object-src 'none'`** submit no form and load no plugin. The frame's `sandbox`
  attribute also lacks `allow-forms`, so a form's submission is stopped before its `submit` event fires; a widget
  [sends on a click or a key](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widgets.md#on-a-playground) instead.
* **`frame-ancestors 'self' https://blobhub.io`** keeps any other site from framing a widget origin.

The other four headers:

* **`Permissions-Policy`** gives each feature it names an empty allowlist, so a browser that reads the header grants
  none of them on a widget origin, whatever the frame's attributes say.
* **`Referrer-Policy: no-referrer`** sends no address of the frame with any request it makes.
* **`X-DNS-Prefetch-Control: off`** asks the browser not to look up, ahead of use, the host names that appear in the
  frame's document.
* **`X-Content-Type-Options: nosniff`** has the browser run a script or apply a stylesheet from the origin only when it
  is served as one.

## What the platform enforces

1. **Walled off.** A widget runs on an origin of its own, never blobhub.io's and never another widget's, so it cannot
   read the page, the login the page keeps in its storage, or another widget's storage. The browser's same-origin rule
   enforces it, on the [origin](#the-frame) the host derives.
2. **No auth, ever.** The frame never receives a token, key, cookie, API header or API address. The host makes every API
   call itself, inside the page, with the viewer's own login, and hands back data only. Every message it posts is
   checked as well: if its JSON, a file's bytes aside, holds any credential the page holds, a reply is answered
   `api_error` with no `data` instead and a push is dropped.
3. **Its playground only.** The host pins every call to the playground's revision and its selected session at the moment
   of the call, and takes neither from what a widget sends: a call that acts on a session and names another one is
   refused, never run in it. The bridge has no call for other blobs, other revisions, other organizations, account or
   organization settings, definitions, listeners, schedules or a session's lifecycle, so these are out of a widget's
   reach by construction. Two calls reach past the playground, each within a bound: `executions.start` may start a
   workflow defined elsewhere, one the widget lists and the viewer can run, and it runs in the selected session;
   `people.get` answers a person's display name and avatar and nothing more of them.
4. **Never more than the viewer.** While the viewer cannot write in the selected session, the host refuses every write
   to it with `forbidden`, by the same check the built-in widgets use to decide whether the viewer may write, so a
   reader's widget can only read. Writes and workflows run as the viewer, and the API, called with the viewer's own
   login, enforces the viewer's rights whatever the host allowed.
5. **Never more than it declared.** The host refuses with `forbidden` any call whose permission the definition does not
   declare, and an `executions.start` of a workflow the widget does not list under `executions`. It reads the
   permissions from the same downloaded definition whose code runs in the frame.
   [Permissions](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widgets.md#permissions) lists them.
6. **Confirmed at install.** Everything a widget may do is declared in its `widget.yaml` and shown to its installer
   whenever that changes: [`blobhub workflow deploy`](https://docs.blobhub.io/cli/workflow/commands/deploy#confirming-what-a-widget-may-do) and
   [`blobhub workflow push`](https://docs.blobhub.io/cli/workflow/commands/push#widgets-whose-permissions-changed) print the lines of a widget
   whose permissions changed and install it only with `--yes`, at a terminal and in a script alike. Every viewer sees
   the same lines in the playground's details pane, and in the blob's [Widgets
   tab](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widgets.md#the-widgets-tab). The platform does not enforce the
   confirmation: [Upload Definition Content](https://docs.blobhub.io/blob-types/workflow/operations/upload-definition.md) called directly installs
   a widget without it, and `--yes` installs it whether or not anyone read the lines ([Install without
   reading](#residual-risks)).
   At runtime the host checks the declaration, the viewer's own rights and the rate budgets, and nothing about what the
   viewer is doing: a widget writes, starts a workflow it lists, copies, shows a notification or opens a link when it
   calls, with no click and no dialog. A press on one of the widget's header actions, buttons the host draws outside the
   frame, only sends `ui.action` to it. [Trust at
   install](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widgets.md#trust-at-install) says what the host checks.
7. **No network of its choosing.** The frame's [headers](#headers) block every connection except to its own origin,
   which serves only the bootstrap page and the catalog, so data reaches a widget only through the bridge. Two ways out
   remain that no header closes; the residual risk [Channels a browser cannot close](#residual-risks) names them.
8. **No escape hatches.** The `sandbox` attribute allows no popups, forms, top navigation, modals or downloads, the
   headers allow no service worker, and the empty `allow` grants no device permission. What a widget may still need of
   these, the host offers as calls, each under its own permission: `ui.open` opens a link to a host the widget lists
   under `links`, or to any `https` host under `["*"]`, `ui.copy` copies to the clipboard with `clipboard: write`,
   `ui.notify` shows a notification with `notifications: show`, and `files.save` saves a session file with
   `files: read`. A link `ui.open` builds to a named place, the debugger or a profile, needs no permission. A
   notification shows under blobhub.io's own notification permission, which blobhub.io asks for, while it is undecided,
   at most once per page load and only from a call made while the page holds the browser's activation from a click or
   key press. A widget can save only a session file it may read: bytes it made reach the viewer's downloads only by
   first being uploaded to the session, which needs `files: write` and a viewer who can write.
9. **BlobHub sets no cookies.** BlobHub's own code in the web app and the API never sets or reads a cookie, because a
   page on a widget origin, under blobhub.io, can read and set any cookie scoped to the whole domain. Tests in both
   hold this. The login lives in the page's own storage, which no widget origin can read. One third-party cookie
   remains, as the [Cookie Policy](https://blobhub.io/cookies) says: the TradingView charting library carries Google
   Analytics code that may set a cookie for all of blobhub.io on a small fraction of the loads of a page or widget
   that draws its chart. It holds a visitor id, not a login, and BlobHub never reads it. A widget can still set such
   a cookie itself; the residual risk [Same site as blobhub.io](#residual-risks) says what that allows.

## Residual risks

These are the limits of the rules above, stated rather than claimed away.

* **A widget can act without a click.** A widget acts as the viewer whenever it calls, within what it declared and what
  the viewer may do: on load, on a timer or in a loop, it writes to the session, starts the workflows it lists, copies
  to the clipboard, shows notifications and opens links to the hosts it lists, or to any site under `["*"]`, with no
  click and no dialog. The viewer is not asked, and the details pane shows what it may do. The host limits writes,
  workflow starts, saves, copies, links, notifications and changes of session per widget instance, with the rate budgets
  the [Bridge Protocol](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-bridge.md#calls) states, and the platform's
  [limits](https://docs.blobhub.io/general/limits.md) cap the rest. The browser may still refuse a new tab, a clipboard write or a notification
  prompt that no click preceded.
* **Channels a browser cannot close.** A frame can navigate itself to an outside address, and WebRTC can reach an
  outside host; neither is governed by the headers. A navigation that loads a page takes the frame off its bootstrap
  page: the host sees that, stops the widget and replaces it with `This widget left its page and was stopped.`, but only
  after its first request has left. A navigation the outside host answers without a page, with an empty response or as a
  download the frame refuses, never leaves the bootstrap page, so the host does not see it, and a widget can repeat it.
  Nothing stops WebRTC, whose packets in Firefox also carry the machine's local network address. What can leave this way
  is what the widget can read: its playground's data, within its permissions and the viewer's rights, and any keys
  typed into it. It can also leave in the address of a link the widget opens (`ui.open` with a `url`) to a host its
  `links` names, or to any host under `["*"]`, with no click from the viewer. Rules 3 to 5 bound only what a widget
  does through the bridge; rule 7 narrows the ways out.
* **Same site as blobhub.io.** `widgets.playground.blobhub.io` is a subdomain of blobhub.io, so browsers treat a widget
  as the same site as blobhub.io. A browser may run it in the same process as the page holding the login, open to
  side-channel (Spectre-class) reads. A widget can also set a cookie scoped to all of blobhub.io: BlobHub never reads it
  (rule 9), but every other widget can. A browser sends that cookie with each page it loads from blobhub.io or a
  subdomain, with the requests such a page makes to its own origin, and with the realtime connection; BlobHub's own
  calls to its API carry no cookies. So a widget that sets many large ones makes the browser's page loads from
  blobhub.io, its realtime connection, and every widget origin's bootstrap and catalog requests too large to serve,
  until the viewer clears blobhub.io's cookies. It harms only a viewer who opened such a widget, and only in that
  browser. The widget domain is not on the Public Suffix List; an entry there would end this, since a cookie could then
  not be set above a widget's own site.
* **Persuasion and focus.** A widget can draw anything inside its frame, including a fake sign-in or password prompt,
  and keep what the viewer types into it. The keys the viewer types while focus is in a widget's frame reach the widget,
  which can read them, whether the viewer put focus there or the widget moved it there itself, with its own `focus()`
  or `autofocus`, where the browser lets it. When it takes focus as the viewer types or moves focus away, the keys they
  meant for the page, a built-in HTML widget or another widget reach it instead. What it reads either way it can write
  to the session, as its permissions allow, or send through the channels above. The header the host draws shows the
  widget's type, the alias the widget is deployed under, which marks the frame as this blob's own widget. A widget can
  change the text of its alias chip but never that type label, and when the header runs out of room the chip gives way
  first, then the name, and the type label last, so a long chip text never pushes the label out; on a card too narrow
  even for the label, the details pane's Type always shows it in full. BlobHub never asks for a password, an API key or
  a sign-in inside a widget; a prompt for one there comes from the widget.
* **Install without reading.** The confirmation is `--yes`: a script that always passes it, or a direct call to
  [Upload Definition Content](https://docs.blobhub.io/blob-types/workflow/operations/upload-definition.md), installs a widget without anyone
  reading its capabilities ([rule 6](#what-the-platform-enforces)). Every viewer still sees them in the details pane.
* **A definition near the size limit may not travel.** An API request or response carries at most 6 MB, and a definition
  crosses the API JSON-escaped. Built code grows by about 5 to 7% on the way, so a definition at the [size
  limit](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widgets.md#limits) of 4 MiB typically fits, but one made mostly of quotes
  or non-ASCII text can grow past 6 MB and fail its upload or download with a transport error rather than a named
  refusal.
* **Library files outside the import map.** A file a library loads itself, such as an Ace mode, theme or snippet from
  its `basePath`, is not checked against `integrity`, as the [libraries
  page](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-libraries.md#the-format) says. It can come only from the widget
  origin's own `/libs/`, whose published versions never change, under the frame's content security policy.

What this means for a viewer: a widget from a blob you can read can show you anything. It reads what its permissions and
your rights allow in its playground, and the keys you type while focus is in its frame; what it reads can leave through
the two channels above, or in the address of a link it may open. It acts as you, within what it declared and what you
may do, whenever it calls, with no click from you; the details pane lists what it may do. Placing a widget, or opening a
playground that places one, trusts its authors with what it can read and do there.

## See also

* [Custom Widgets](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widgets.md): `widget.yaml`, the definition, permissions,
  trust at install, and deploying.
* [Bridge Protocol](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-bridge.md): the entry, the wire format, every call,
  event and refusal, and the rate budgets.
* [Libraries and Theme](https://docs.blobhub.io/blob-types/workflow/playgrounds/custom-widget-libraries.md): the library catalog, the import map,
  building one module, and a widget's storage.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.