Guides
Every Document lives in its author's own account, and any app can write to an account's records. SkyScribe cleans a Document's HTML when its author saves it, but the SDK returns whatever is stored. What you need to do depends on whose Documents you show.
renderEmbeds (which ScribeContent runs for you) turns each stored Embed into its player or Poster. It is not a sanitiser: everything else in the HTML is left as it was. Run your sanitiser after it, never before. Embed rendering reads the HTML as text, so markup a sanitiser had made harmless (inside an attribute value, say) can become live again if Embeds are rendered afterwards.
In React, pass your sanitiser to ScribeContent, which runs it after the Embeds and before the HTML goes into the page:
import { ScribeContent } from "@skyscribe-sdk/react";
import { sanitizeDocument } from "./sanitizeDocument";
<ScribeContent html={document.content} sanitize={sanitizeDocument} />
Don't sanitise document.content before passing it in.
Everywhere else, render the Embeds, then sanitise:
import { renderEmbeds } from "@skyscribe-sdk/core";
const html = sanitizeDocument(renderEmbeds(document.content));
Then insert html with v-html in Vue, [innerHTML] in Angular (see below), or your framework's equivalent.
DOMPurify removes iframes by default, which would remove every Embed player. This configuration keeps iframes only from the players the SDK builds (EMBED_FRAME_HOSTS), along with the attributes they need. It uses isomorphic-dompurify, which has the same API and also works during server rendering:
import DOMPurify from "isomorphic-dompurify";
import { EMBED_FRAME_HOSTS } from "@skyscribe-sdk/core";
// Embed players come only from the hosts renderEmbeds uses.
DOMPurify.addHook("uponSanitizeElement", (node, data) => {
if (data.tagName !== "iframe") return;
let origin = "";
try {
origin = new URL((node as Element).getAttribute("src") ?? "").origin;
} catch {
// Not a URL: removed below.
}
if (!(EMBED_FRAME_HOSTS as readonly string[]).includes(origin)) node.parentNode?.removeChild(node);
});
export function sanitizeDocument(html: string): string {
return DOMPurify.sanitize(html, {
ADD_TAGS: ["iframe"],
ADD_ATTR: ["allow", "allowfullscreen", "loading", "referrerpolicy", "scrolling"],
// A <style> element restyles your whole page. SkyScribe never writes one.
FORBID_TAGS: ["style"],
});
}
The SDK's own tests run this configuration against known attacks, and check that Posters and players survive it. Inline style attributes stay, because Posters and image positions need them. If a Document styling its own elements is a concern on your site, add a Content Security Policy as well.
Angular sanitises anything bound to [innerHTML], which stops script, but it also strips every Embed player and the Posters' styles. To keep Embeds, sanitise with the configuration above, then tell Angular the result is safe:
this.html = this.sanitizer.bypassSecurityTrustHtml(sanitizeDocument(renderEmbeds(document.content)));
Only ever pass bypassSecurityTrustHtml the output of your sanitiser.
generateDocumentJsonLd copies the Document's title and description into the JSON-LD. If you write the <script type="application/ld+json"> yourself, serialise it with serializeJsonLd, never JSON.stringify: a title containing </script> would close the tag. React Router's documentMeta already does this for you.
import { generateDocumentJsonLd, serializeJsonLd } from "@skyscribe-sdk/core";
<script type="application/ld+json" dangerouslySetInnerHTML={{ __html: serializeJsonLd(generateDocumentJsonLd(document, publication)) }} />
The SDK fetches each Document from its author's own account, through the address in that account's DID document. It checks that address before using it: an https URL on a public hostname, with no port. It also bounds every request: no redirects, a 10-second timeout, a 5 MB response limit, and at most 50 pages when listing. It can't see where a hostname resolves, so blocking private network addresses is your host's job (for example Cloudflare's global_fetch_strictly_public, or egress rules on your server).
When two Documents in a Publication share a URL slug, fetchDocumentBySlug returns the one in the Publication owner's own account. Pass category to search only the Category in your URL.
It does not check:
listDocuments and listPublications return the record addresses the account's server sends. If your page attributes a Document to an account, take that account from the identity you asked for, not from the record address.