A docs site built with aiui build ships with a strict Content-Security-Policy
aiui build
and needs no configuration. The policy allows the scripts the site runs and
nothing else, so injected markup cannot run a script, and only your own site
can show the docs in a frame.
aiui build works the policy out from what the site actually loads:
| Source | Directive |
|--------|-----------|
| The site's own files (app, chunks, fonts, customCss/customJs files, the site.components module and its import map's hash) | 'self' |
customCss
customJs
site.components
'self'
| The small inline scripts the build writes (theme, URL, redirect stubs) | script-src 'sha256-…', one hash each |
script-src 'sha256-…'
| The JSON the build inlines in each page (its Markdown, the navigation and route manifest) | nothing: type="application/json" is data the browser never runs |
type="application/json"
| Google Fonts and font, stylesheet and script URLs in site.theme.fonts, customCss, customJs | style-src, font-src, script-src |
site.theme.fonts
style-src
font-src
script-src
| Integrations (analytics, support chat) | each provider's hosts |
| YouTube, Vimeo and Loom embeds on a page | frame-src (the privacy-friendly player) |
frame-src
| The servers of your OpenAPI specs (Try it) | connect-src |
servers
connect-src
| assistant.endpoint, feedback.endpoint on a static host | connect-src |
assistant.endpoint
feedback.endpoint
| A navbar primary button of type: github (the star count) | connect-src https://api.github.com |
primary
type: github
connect-src https://api.github.com
Everything else stays strict: no 'unsafe-inline' or 'unsafe-eval' for
'unsafe-inline'
'unsafe-eval'
scripts, object-src 'none', base-uri 'self', form-action 'self'.
object-src 'none'
base-uri 'self'
form-action 'self'
Images and media load from 'self', data:, blob: and any https: host,
data:
blob:
https:
so Markdown images and badges keep working. Styles allow 'unsafe-inline':
the app's code highlighting, diagrams and dialogs set inline styles.
The policy goes out three ways:
<meta http-equiv="Content-Security-Policy">
right after <meta charset>. This works on any static host, GitHub Pages
<meta charset>
included.
_headers
Cloudflare Pages, with frame-ancestors 'self' added (a meta tag cannot
frame-ancestors 'self'
carry frame-ancestors).
frame-ancestors
aiui serve
aiui dev
/*
preview behaves like the host. The aiui dev reload script is a file
(/__aiui/dev.js), so it runs under the same policy.
/__aiui/dev.js
On another host (nginx, S3 with CloudFront, a CDN), copy the header line from
_headers into its configuration.
| site.csp | Effect |
site.csp
|------------|--------|
| unset | On for a docs build (reported only when integrations.gtm is set, see below); off for other builds |
integrations.gtm
| true | On, enforced |
true
| false | Off: no meta tag, no _headers |
false
| report-only | Only Content-Security-Policy-Report-Only in _headers and from aiui serve: the browser logs what the policy would block, and blocks nothing |
report-only
Content-Security-Policy-Report-Only
| a map | On, with extra sources per directive (a string or a list). A list with 'none' replaces the directive (frame-ancestors: ["'none'"] forbids every frame). report-only: true in the map reports instead of enforcing. report-uri sets where the browser posts reports |
'none'
frame-ancestors: ["'none'"]
report-only: true
report-uri
Directive names are lower-case words (script-src, connect-src, ...) and
sources contain no spaces, ; or ,: anything else is a config error, so
;
,
the value is always a valid header.
fetch
add its origin under connect-src, frame-src or script-src.
and Loom <iframe> players, <img> and <video> (all allowed above), shows
<iframe>
<img>
<video>
any other <iframe> as a link and removes <script>, <form> and similar
<script>
<form>
elements before the policy is ever involved. aiui validate names each one
aiui validate
(finding 7019; see raw HTML). Inline event
handlers (onclick="…") never run.
onclick="…"
which the build cannot see, so the default there is report-only. Add the
hosts of your tags and set site.csp: true to enforce.
site.csp: true
site.plugins
mermaid
syntax-highlight
CDN, which the policy allows when they are listed. Other dashboard plugins
are not meant for docs pages.
To find what a page needs, open the browser console: every blocked load or
script is logged with the directive that blocked it. report-only shows the
same messages without blocking anything.