Content Security Policy (CSP)

GraphComment is compatible with strict Content Security Policies — your page only needs to allow it in three directives, and can install it without any inline script.

GraphComment is compatible with strict Content Security Policies. The comment widget runs entirely inside its own iframe, isolated from your page by design: everything it loads — fonts, images, avatars, link previews, the real-time connection — is fetched by that iframe under its own policy, not under yours. Your page only needs to allow GraphComment in three directives.

The policy

script-src  'self' https://integration.graphcomment.com;
frame-src   'self' https://graphcomment.com;
connect-src 'self' https://graphcomment.com;
style-src   'self';
DirectiveValueUsed for
script-srchttps://integration.graphcomment.comThe GraphComment loader script
frame-srchttps://graphcomment.comThe comment widget iframe
connect-srchttps://graphcomment.comPage-view statistics sent by the loader
connect-src (optional)wss://graphcomment.comOnly for the comment count helper, which updates live
style-srcnothing to addSee Styles below

You don't need any GraphComment entry in img-src, font-src or media-src: those resources are loaded inside the iframe.

📘

In-page display

This guide covers the standard in-page widget. The side panel display mode does not support strict policies yet.

👍

Roll it out safely

Ship the policy as Content-Security-Policy-Report-Only first, check your browser console or your report endpoint, then switch to Content-Security-Policy.

Styles

The loader gives the iframe the full width of its container and a stable height while it loads. You don't need 'unsafe-inline' in style-src for that:

  • With a nonce-based policy (see below), the loader applies your nonce to its stylesheet: no console message at all.
  • With a host-list policy (style-src 'self'), the browser refuses the loader's inline stylesheet and the loader switches to a constructed stylesheet, which style-src does not govern. The widget is laid out normally; your console shows one CSP message for the refused stylesheet, with no effect on the widget.
📘

Customising the iframe under a strict policy

In the constructed-stylesheet case, GraphComment's rules apply after your own stylesheets. If you override .gc-iframe (for instance its max-width), use a more specific selector, such as #graphcomment .gc-iframe.

Installing without any script

If your script-src does not allow inline scripts, put the configuration in a JSON block and load the loader: it reads the block and starts on its own. No init script is needed.

<div id="graphcomment"></div>

<script id="graphcomment-config" type="application/json">
  { "graphcommentId": "<shortname>", "behaviour": { "uid": "<your page ID>" } }
</script>
<script src="https://integration.graphcomment.com/gc_graphlogin.js" defer></script>
  • The block accepts the same parameters as the standard snippet (see Widget configuration), except functions, which JSON cannot carry: this mode is for the standard sign-in, not for Single Sign-On.
  • integration.target takes a CSS selector in the block (for instance "#comments"), instead of a DOM element. If the selector matches nothing, the console shows GraphComment: target "<selector>" not found and the widget does not start.
⚠️

Three rules for this mode

  1. The block must be in the HTML your server sends. It is read once, when the page loads; a block added later by JavaScript is ignored.
  2. Never combine it with the standard snippet (or with your own call to __semio__gc_graphlogin) on the same page. Only one of them starts the widget, and which one depends on load timing: if your configurations differ, the page will not behave the same from one load to the next.
  3. It suits pages served as they are. A single-page application that rebuilds the widget when navigating should start it with its own script instead (next section).

Installing with your own init script

If you need JavaScript logic before starting the widget (a single-page application, a configuration computed in the browser), keep the configuration in a JSON block with another id and start the widget from a file served by your own domain:

<div id="graphcomment"></div>

<script id="gc-config" type="application/json">
  { "graphcommentId": "<shortname>", "behaviour": { "uid": "<your page ID>" } }
</script>
<script src="https://integration.graphcomment.com/gc_graphlogin.js" defer></script>
<script src="/js/graphcomment-init.js" defer></script>
// /js/graphcomment-init.js
window.__semio__onGcLoaded = function () {
  // Optional: the widget is ready (e.g. remove a loading placeholder)
};
window.__semio__gc_graphlogin(
  JSON.parse(document.getElementById('gc-config').textContent)
);

window.__semio__gc_graphlogin is GraphComment's public entry point — the same function the standard snippet calls. Don't use the graphcomment-config id here: it would make the loader start on its own, and your call would be ignored.

⚠️

Keep both scripts defer, loader first

Deferred scripts run in document order, so the entry point always exists when your file runs. Avoid async on the loader combined with a load listener in a deferred script: if the loader runs first, the load event has already fired and the widget never starts.

Nonce-based policies

If your policy relies on nonces, GraphComment reuses your nonce for its stylesheet, so nothing is reported in your console.

  • With 'strict-dynamic' (script-src 'nonce-…' 'strict-dynamic'): add your nonce to the snippet's <script> tag. The loader it inserts is then trusted automatically, and you don't need to list integration.graphcomment.com in script-src.
  • Without 'strict-dynamic': add your nonce to the loader's <script> tag (and to your init script, if you use one).
  • In both cases, allow the same nonce in style-src (style-src 'self' 'nonce-…'). frame-src and connect-src stay as above.
<script nonce="<your-nonce>" type="text/javascript">
  /* standard snippet from Getting Started */
</script>

Next steps


Did this page help you?