A Content Security Policy (CSP) is a response header that tells the browser which scripts and styles a page may use. When someone manages to put their own code into a page, through a product name, an order note or a broken dependency, the policy stops the browser from running it.
HexaSync pages show store credentials, orders and customer data. Every Beehexa product sends a policy. Scripts are always strict; for styles, each app chooses one of two levels.
The standard
- Scripts are strict, in every product. No
'unsafe-inline'and no'unsafe-eval'inscript-src. Scripts come from the app’s own files ('self'). If an inline script is really needed, allow it with a nonce or a hash, never with'unsafe-inline'. - Styles have two levels; the app chooses one. See Choose a style level.
- Basic, the floor for every product:
style-src 'self' 'unsafe-inline'. It is the level most large web apps use. - Strict, recommended for apps that hold high-value data, such as a console with OAuth apps and client secrets:
style-src 'self', with no'unsafe-inline'and no hash. The Beehexa components meet it with a build step that removes the few inline styles their component library adds.
- Basic, the floor for every product:
- The Beehexa components look right at both levels. The few parts that do not meet the strict level yet are listed with the components; they affect the strict level only.
- Turn the policy on in the built app, not in a development server.
How the Beehexa components meet both levels, and the build step for the strict level, is on Tools › shadcn-vue package › Content Security Policy.
Sample headers. script-src and style-src are the standard; set the other directives for your app, such as the API it calls in connect-src.
Basic style level:
Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'; form-action 'self'
Strict style level:
Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'; form-action 'self'
Don’t add a style nonce to the basic level: when style-src has a nonce, the browser ignores 'unsafe-inline', and the page gets the strict level by accident.
Choose a style level
Inline style is a smaller risk than inline script. Injected CSS cannot run code; what it can do is restyle the page, to hide, move or fake parts of the interface. CSS that tries to send data out through url() or @import is already stopped by img-src, font-src, connect-src and style-src set to 'self', at both levels.
Basic: 'self' 'unsafe-inline' |
Strict: 'self' |
|
|---|---|---|
| What it blocks | Stylesheets from other origins. With img-src, font-src and connect-src set to 'self', CSS cannot send data to another site |
The same, plus every injected <style> element and style="…" attribute, so injected CSS cannot restyle the page |
| What it lets through | A <style> or style attribute injected into the page can hide, move or fake parts of the interface |
Nothing inline |
| Build | Nothing to add | A build step removes the inline styles the component library adds |
| Component library upgrades | Nothing to do | Check after each upgrade that no new inline style appears |
| Kit parts | Every part looks right | A few parts are not met yet; see the components’ list |
| Development | Styles a development server injects are allowed | A development server that injects <style> elements breaks the page: check the policy on the built app |
| Server rendering | Style attributes in the server’s HTML apply | Every style attribute in the server’s HTML is blocked |
| New libraries | Nothing to check for styles | Check each new library under the policy: many add a <style> or set style attributes |
| Use it for | Every product, as the floor | Apps that hold high-value data, such as credentials, client secrets or payment details |
In your app
| Do | Don’t |
|---|---|
| Keep scripts in files the app builds | Write a <script> into the HTML, or an onclick="…" attribute |
| Keep styles in stylesheet files the build produces | Write a <style> element or a style="…" attribute into the HTML |
| Set dynamic values, such as a width or a colour variable, through the element’s style properties in code | Build a <style> element in code, or set the style attribute as text |
| Add a missing role or component to beehexa.design | Add a hash or 'unsafe-inline' to make a component work |
Watch the browser console, or a report-to endpoint, for CSP errors |
Treat a CSP error as noise. Each one is a style or script the page did not get |