Skip to the page
Docs articles

Content Security Policy

The sources to allow when your site sends a Content Security Policy, and why the widget needs each one.

Last updated

View as Markdown
On this page

If your site sends a Content-Security-Policy header, the browser blocks anything the policy doesn't allow, and the widget hides or loses a part. Add these sources to the directives your policy already has.

The sources

  • script-src: https://app.notert.io, where the widget's script loads from. The snippet's small inline script needs to run too: see the inline snippet.
  • connect-src: https://app.notert.io, where the widget sends messages and receives replies live.
  • font-src: https://app.notert.io, for the widget's typeface.
  • frame-src: https://app.notert.io, for the check that asks a visitor to confirm they're human before Otto answers them, before their first post or vote as a guest, before the widget emails them a code to confirm their email, and before their first message on a day your workspace gets far more new conversations than usual. It draws inside a frame from Notert, so your policy needs nothing of Cloudflare's.
  • img-src: https://notert-content.com, for your team's photos, your logo and the pictures in a conversation or on a request; https://lh3.googleusercontent.com and https://avatars.githubusercontent.com, for the photo of a teammate, or of a customer commenting or voting on a request, who signed up with Google or GitHub; blob:, for the preview of a picture a visitor attaches; and data:, for your website's icon, which heads the widget in your logo's place until you upload one.
  • media-src: https://notert-content.com, for a recording your team or a visitor sends in a conversation, which plays in the thread, and blob:, for one a visitor attaches, which they can play before they send it.

Put together:

script-src 'self' 'nonce-RANDOM' https://app.notert.io;
connect-src 'self' https://app.notert.io;
font-src 'self' https://app.notert.io;
frame-src 'self' https://app.notert.io;
img-src 'self' blob: data: https://notert-content.com https://lh3.googleusercontent.com https://avatars.githubusercontent.com;
media-src 'self' blob: https://notert-content.com;

The inline snippet

The snippet's first <script> is inline, which a policy without 'unsafe-inline' blocks. Allow it one of these ways:

  • A nonce. If your server already puts a nonce on its scripts, put the same one on the snippet's tag: <script nonce="RANDOM">.
  • A file of your own. Move the two lines inside the tag into a file on your site, such as /notert.js, and load it with <script src="/notert.js"></script> before the widget's script. 'self' then covers it.

A hash works too, but it changes whenever the snippet does, such as when you change its theme.

With a nonce, the snippet looks like this, with your server's nonce for the page in place of RANDOM:

<script nonce="RANDOM">
  window.$notert=window.$notert||[];window.notert=window.notert||new Proxy({},{get:(_,p)=>typeof p=="string"&&p!="then"&&/^[a-z]/i.test(p)?(...a)=>window.$notert.push([p,...a]):void 0});
  window.notert.init("YOUR_WORKSPACE_ID",{widget:true,theme:"page"});
</script>
<script nonce="RANDOM" type="module" async src="https://app.notert.io/embed/v1.js"></script>

The npm package has no inline script: it adds the widget's script from your own bundle, so https://app.notert.io in script-src is all it needs there. Under 'strict-dynamic', the trust your bundle's nonce gives it carries to the script it adds.

With 'strict-dynamic'

A policy with 'strict-dynamic' in script-src ignores the addresses listed beside it, so https://app.notert.io there allows nothing. Put your nonce on both of the snippet's tags, as above: the widget's script then loads, and the parts it loads after it are trusted through it.

Styles

The widget needs nothing in style-src. It draws inside a shadow root with stylesheets its script builds, rather than <style> tags or a stylesheet it links, so a policy that holds back inline styles leaves it as it is.

A whole policy

Your server sends one header, with each directive once. Here's one for a site that serves its own scripts and the widget, with a fresh nonce on every page:

Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-RANDOM' https://app.notert.io; connect-src 'self' https://app.notert.io; font-src 'self' https://app.notert.io; frame-src 'self' https://app.notert.io; img-src 'self' blob: data: https://notert-content.com https://lh3.googleusercontent.com https://avatars.githubusercontent.com; media-src 'self' blob: https://notert-content.com

To try a policy without breaking anything, send it as Content-Security-Policy-Report-Only first: the browser reports in the console what it would block, and blocks nothing.

Checking it

Open your browser's developer tools on a page with the widget. A source the policy blocked is reported in the console with the directive that blocked it. See troubleshooting for the widget's own messages.

Start here

Up and down arrowsto moveEnterto openEscto close