Content Security Policy

Configure a policy for the assets and interactions your application actually uses.

Current compatibility boundaries

The library uses external JavaScript without eval. Application handlers should live in external files rather than inline onclick attributes. Components modify individual style properties at runtime, including toast progress duration and modal stacking. Do not assume the entire library or documentation site works under every strict policy.

The documentation site also uses external icon/highlighting assets and page-specific scripts. Its asset requirements are broader than a minimal application using self-hosted Focus UI.

Self-hosted starting policy

Start in report-only mode, exercise your real workflows, and inspect violations before enforcement. This example assumes all scripts, styles, fonts and images are self-hosted; adjust it for your application.

Code
Content-Security-Policy-Report-Only:
  default-src 'self';
  script-src 'self';
  style-src 'self';
  img-src 'self' data:;
  font-src 'self';
  connect-src 'self';
  base-uri 'self';
  form-action 'self';
  frame-ancestors 'none';

Style attributes

An enforced style-src-attr 'none' blocks inline style attributes in generated HTML. Individual JavaScript style-property assignments have different enforcement behavior. The generated modal and toast markup does not contain style attributes. Test your application and its dependencies under the policy you intend to enforce. Do not copy a blanket unsafe-inline exception just to remove console errors.

CDN assets

When using the Focus UI CDN, allow https://cdn.focus-ui.de in the script/style directives and pin an immutable version. Font Awesome requires its own stylesheet and font origins if you choose to use it. Pair CDN resources with SRI generated from the exact downloaded bytes.

Application handlers

HTML
<button id="save" class="focus-btn focus-btn-primary">Save</button>
<script src="/vendor/focus-ui.min.js" defer></script>
<script src="/app.js" defer></script>
JavaScript
document.querySelector('#save').addEventListener('click', () => {
  FocusUI.Toast.show({ message: 'Saved', progress: false })
})

The library is exercised in Chromium under a self-only script and style policy across representative component markup and selected JavaScript component interactions. This is a regression check for those paths, not a guarantee for every browser, integration or Content Security Policy.

Verify with headers

Send policies as HTTP response headers. Report-only policies help find breakage but do not enforce restrictions. Test dialogs, search, copy controls and feedback under the enforced policy. A meta tag cannot provide every directive available in an HTTP header.

Reference: MDN style-src-attr.