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';
| Directive | Value | Used for |
|---|---|---|
script-src | https://integration.graphcomment.com | The GraphComment loader script |
frame-src | https://graphcomment.com | The comment widget iframe |
connect-src | https://graphcomment.com | Page-view statistics sent by the loader |
connect-src (optional) | wss://graphcomment.com | Only for the comment count helper, which updates live |
style-src | nothing to add | See 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 displayThis guide covers the standard in-page widget. The side panel display mode does not support strict policies yet.
Roll it out safelyShip the policy as
Content-Security-Policy-Report-Onlyfirst, check your browser console or your report endpoint, then switch toContent-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, whichstyle-srcdoes 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 policyIn the constructed-stylesheet case, GraphComment's rules apply after your own stylesheets. If you override
.gc-iframe(for instance itsmax-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.targettakes a CSS selector in the block (for instance"#comments"), instead of a DOM element. If the selector matches nothing, the console showsGraphComment: target "<selector>" not foundand the widget does not start.
Three rules for this mode
- 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.
- 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.- 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 scriptsdefer, loader firstDeferred scripts run in document order, so the entry point always exists when your file runs. Avoid
asyncon the loader combined with aloadlistener in a deferred script: if the loader runs first, theloadevent 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 listintegration.graphcomment.cominscript-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-srcandconnect-srcstay as above.
<script nonce="<your-nonce>" type="text/javascript">
/* standard snippet from Getting Started */
</script>Next steps
- Getting Started — the standard installation
- Widget configuration — every parameter of the configuration object
- Comment count — display comment counts next to your links
Updated 17 days ago
