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

# Security

> How CliqHub runs a team's hug safely — the sandbox, the content host, what a page can and can't do, and who is trusted for what.

Hugs

A hug is code a team brings. CliqHub runs it on the Hug page, next to people's data, so it is boxed in: it can draw,
and talk to the host — nothing else.

***

## What it is protected against

| Threat | Stopped by |
| - | - |
| A page that copies Hug data out | No network at all (CSP `connect-src 'none'`, `default-src 'none'`); no outside images, fonts, scripts or form posts |
| A page that reads the Hub's cookies, storage or DOM | A separate origin (the content host) and a sandboxed frame without `allow-same-origin` |
| A page that pretends to be the Hub | The Hub draws the title, who asked, the run and the Submit button, outside the frame |
| A page that answers by itself | Only the Hub's Submit button sends an answer |
| A page that sends people elsewhere | No navigation or popups; links go through the host, and one not in the params is shown first |
| A bundle that isn't what was asked for | The bundle is named by its hash, which CliqHub recomputes |
| A bundle from outside the realm | CliqHub takes bundles only from the Hug's realm's daemons |
| An answer the page didn't check | The agent checks every answer against the definition |

## The sandbox

The page loads in `<iframe sandbox="allow-scripts">` — no `allow-same-origin`, `allow-forms`, `allow-popups`,
`allow-top-navigation`, `allow-modals` or `allow-downloads` — from the content host, with:

```text theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
Content-Security-Policy: default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline';
  img-src 'self' data: blob:; font-src 'self' data:; media-src 'self' blob:; connect-src 'none';
  form-action 'none'; base-uri 'none'; frame-ancestors <the Hub>
X-Content-Type-Options: nosniff
Referrer-Policy: no-referrer
```

So the page can run its own scripts and styles, show images and fonts from its bundle or inlined, and show files the
host hands it (`blob:`) — and nothing more.

## The content host

On cliqhub.io, pages are served from `content.cliqhub.io`, at `/hb/<sha256>/…`. It serves only bundle files, sends
no cookies and receives none. A local cliqd serves pages itself, with the same headers.

## Talking to the host

Everything a page does outside its frame is a message to the host ([bridge protocol](https://docs.getcliq.io/hugs/reference/bridge-protocol.md)),
which checks it:

* messages only from the page's own frame;
* answers of at most 256 KB; files only ones the host gave it, for declared upload slots;
* reads only of the Hug's attachments, the viewer's own uploads, and the files of the answer being shown;
* a Submit label of at most 40 characters;
* rate limits: 20 answer updates a second, one file picker and one link dialog at a time, 10 reads at once and 50 MB
  per page.

Uploads, reads and answers then go through CliqHub, which checks them again with the viewer's permissions.

## Who is trusted for what

* **CliqHub** is trusted about who answered, when, through which channel, and which files they uploaded.
* **The definition** is trusted about what they answered — the agent checks every answer with it before acting.
* **The daemon** is the realm's boundary, as for running agents: a daemon that can open Hugs can already ask anything
  with `form`. That's why there's no registration of hugs: a custom page adds no reach a form doesn't have, and the
  sandbox limits what it can do.

## Writing a safe hug

* Put everything in the bundle; pass data in params and files as attachments.
* Never put secrets in params — they're shown to everyone who can see the Hug.
* Use `html` (or React) rather than building HTML strings, so values are escaped.
* Keep the rules in the definition, not only in the page.


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