From 2baac6eab4acd7834506e789923256bdcf920c57 Mon Sep 17 00:00:00 2001 From: Mehboob Khan Date: Wed, 19 Aug 2026 20:15:33 +0500 Subject: [PATCH] Sanitise inline content fields on snapshot restore and content import Post bodies were already re-sanitised on the way back in from a version snapshot or an imported content file, but content.content{} (the inline text-field map) wasn't. applyContent() writes that map straight into the DOM via innerHTML as soon as it loads into the editor, before the admin ever publishes, so a crafted content file or tampered snapshot could carry a stored-XSS payload there and execute it in the admin's session on import alone. Co-Authored-By: Claude Sonnet 5 --- src/cms/admin/HistoryPanel.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cms/admin/HistoryPanel.tsx b/src/cms/admin/HistoryPanel.tsx index 2be84c1..3f90d9c 100644 --- a/src/cms/admin/HistoryPanel.tsx +++ b/src/cms/admin/HistoryPanel.tsx @@ -2,15 +2,20 @@ import { useEffect, useRef, useState } from 'react' import type { Post, SiteContent } from '../types' import { getVersion, listVersions } from '../api' import { resolveContent } from '../store' -import { sanitiseBody, slugify } from '../sanitise' +import { sanitiseBody, sanitiseInline, slugify } from '../sanitise' // A version snapshot or an imported content file was written by *some* prior // publish, possibly by an older build with looser sanitisation. Re-sanitising // on the way back in is idempotent for already-clean bodies and closes off any // stored-XSS route through a crafted "content file" or stale studio draft. +// Both fields matter: applyContent() (src/cms/store.tsx) writes content.content +// straight into the DOM via innerHTML as soon as this loads into the editor — +// before the admin ever clicks Publish — so it needs the same treatment as +// article bodies, not just a same-shape skip. const sanitisePosts = (content: SiteContent): SiteContent => ({ ...content, posts: content.posts.map((p) => ({ ...p, body: sanitiseBody(p.body) })), + content: Object.fromEntries(Object.entries(content.content || {}).map(([id, html]) => [id, sanitiseInline(html)])), }) interface Props {