blockcn

Security

What the editor already blocks, and a Content-Security-Policy for an app that embeds it.

The editor treats document JSON, pasted HTML, and framed URLs as untrusted. This page is the policy for an app that mounts it. Link previews and comments are not in the editor yet, so there is no unfurl fetch and no comment HTML to sanitize.

What is already checked

  • Links and media src. javascript:, vbscript:, and data: URLs other than data:image/png, jpeg, gif, or webp are removed from link marks and from media and link blocks, including JSON import and collaboration updates. New tab links use rel="noopener noreferrer" and target="_blank".
  • Pasted HTML. The schema keeps headings, lists, tables, links, code, and images. Unknown tags, event handlers, and a Word cid: image do not become a src. See the paste fixtures under editor/src/test/fixtures/paste/.
  • Embeds. An embed iframe is rendered only when the URL is on the add-on's allowlist. The frame is sandbox="allow-scripts allow-presentation allow-popups" with referrerpolicy="no-referrer". allow-same-origin is omitted, so a page on your own host still cannot read the editor's origin.
  • PDF preview. The preview iframe has no allow-scripts and uses referrerpolicy="no-referrer". The Open file link is the fallback when a browser will not paint a PDF in that frame.
  • YouTube and Vimeo. Those players are iframed with referrerpolicy="strict-origin-when-cross-origin". They are not sandboxed: the player does not run inside allow-scripts without allow-same-origin.
  • Whiteboard import. A saved Excalidraw scene keeps drawing elements, the view settings the editor persists, and image files whose dataURL passes the same check as other media. SVG and javascript: file data are dropped.
  • Uploads. The example server refuses SVG and HTML types, stores a generated name, sends X-Content-Type-Options: nosniff, and deletes a file whose first bytes are SVG, HTML, or XML even when the client sent image/png. Other files are served with Content-Security-Policy: default-src 'none'; sandbox, except PDFs, which Chrome will not render under a CSP sandbox.

Content-Security-Policy

Put this on the page that mounts the editor. Tighten frame-src to the hosts you actually embed.

default-src 'self';
script-src 'self';
style-src 'self' 'unsafe-inline';
img-src 'self' data: blob: https:;
media-src 'self' blob: https:;
font-src 'self' data:;
connect-src 'self' https:;
frame-src https://www.youtube.com https://www.youtube-nocookie.com https://player.vimeo.com;
object-src 'none';
base-uri 'self';
form-action 'self'

style-src includes 'unsafe-inline' because KaTeX and the whiteboard set styles on elements. img-src allows data: and blob: for pasted images and in-progress uploads. Add your upload host to img-src, media-src, and connect-src. If you allow other embed domains, add them to frame-src and to the embed allowlist together.

Still yours to configure

  • The embed allowlist. An empty list renders the URL as text.
  • Upload authentication. POST /api/upload is off until ENABLE_UPLOADS=true, and it requires a Bearer token unless UPLOADS_ALLOW_ANONYMOUS is set for local development.
  • Serving user files from a different origin than the app, so a missed sniff cannot share the app's cookies.

On this page