# Content Security Policy (CSP)

A Content Security Policy is a set of instructions a site sends to the browser, normally in the `Content-Security-Policy` response header, that restricts what the page may load and run, which mainly limits the damage of cross-site scripting. Meadowstack 2.1 sets no headers, because it does not run your server, but its security docs give a policy tried against the kit's production build.

Checked 2 December 2026. By Bohuslav Poláček. https://meadowstack.com/glossary/content-security-policy/

*The policy in docs/security.md; its core ran against the demo's production build with no violations.*

From `docs/security.md` in the Meadowstack repository:

```http
default-src 'self';
script-src 'self' 'sha256-<hash of the theme script>';
style-src 'self' 'unsafe-inline';
img-src 'self' data: blob:;
font-src 'self';
connect-src 'self' https://api.your-company.example;
object-src 'self';
base-uri 'self';
form-action 'self';
frame-ancestors 'none'
```

## Why it matters in a business app

A business app shows text other people typed: a supplier's name, a comment, a file name. If any of that ever reaches the page as markup, a script can run with the person's session. React escapes text and the kit renders Markdown without HTML, so the first line of defence is there; a CSP is the second, deciding where scripts may come from and where data may be sent even if something slips through.

MDN lists two other uses: `frame-ancestors` against clickjacking, and enforcing HTTPS. It also notes that `Content-Security-Policy-Report-Only` reports violations without blocking, which is how to try a policy on a live app.

## How Meadowstack handles it

`docs/security.md` explains every line of the policy above by what the kit does:

- **`script-src` with a hash.** The page has one inline script, the theme script that prevents a white flash in dark mode; allow exactly it by its hash, computed from the built page.
- **`style-src 'unsafe-inline'`.** Three dependencies (the toasts, the dialogs' scroll lock, the motion library) add style elements at run time; a style cannot run code, so the script rule stays strict.
- **`img-src data: blob:`** for the tab icon drawn on a canvas and previews of files about to be uploaded; **`object-src 'self'`** because `FilePreview` shows PDFs in an object element.
- **`frame-ancestors 'none'`** works only as a header, not in a meta tag.
- **Never `'unsafe-eval'`**: nothing in the kit needs it.

Setting the header is yours in 2.1: a `vercel.json`, a `_headers` file or nginx. Meadowstack 3.0, coming as an update to every licence, ships strict headers with every app.

## Common mistakes

- **`'unsafe-inline'` for scripts** because one inline script needed it. Hash that script instead.
- **The dev server's policy in production.** Hot reload needs a looser policy; production does not.
- **`connect-src` left at `'self'`** when the api lives elsewhere: every call fails. List the api's origin.
- **Shipping without trying it.** Open the app with the console open and use every feature once; each blocked request is logged.

## Questions

### Can I set a Content Security Policy in a meta tag?

Yes, with a meta element, but it does not support every feature: frame-ancestors and report-only mode work only as headers. Use the header in production.

### Does Meadowstack set a Content Security Policy?

Not in 2.1: the framework does not run your server. The security docs give a policy tried against the kit and explain each line; Meadowstack 3.0 sets strict headers by default.

### Why does the policy allow inline styles?

Three of the kit's dependencies add style elements at run time, and blocking them breaks the toasts' layout and the dialogs' scroll lock. Inline styles cannot run code; inline scripts stay blocked.

## Sources

- [MDN, Content Security Policy (CSP)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP), checked 2 December 2026

## Related

- [Team and roles, with the rules in code](https://meadowstack.com/screens/roles-and-permissions/) (Screens)
- [Permissions](https://meadowstack.com/patterns/permissions/) (Patterns)
- [The approval flow](https://meadowstack.com/patterns/approval-flow/) (Patterns)
- [The audit trail](https://meadowstack.com/patterns/audit-trail/) (Patterns)
- [The settings screen](https://meadowstack.com/patterns/settings/) (Patterns)
- [Google Workspace: only your company's domain](https://meadowstack.com/integrations/google-workspace/) (Integrations)
