Sanitise inline content fields on snapshot restore and content import
CI / build (push) Has been cancelled
CI / build (push) Has been cancelled
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user