Skip to content

fix(slides): sanitize model-generated HTML before rendering it - #599

Open
carfeii wants to merge 1 commit into
AsyncFuncAI:mainfrom
carfeii:fix/slide-xss-sanitize-model-html
Open

carfeii wants to merge 1 commit into
AsyncFuncAI:mainfrom
carfeii:fix/slide-xss-sanitize-model-html

Conversation

@carfeii

@carfeii carfeii commented Oct 5, 2026

Copy link
Copy Markdown

The Slides view builds a prompt asking the model to generate a single HTML slide, extracts HTML from the response with a few regexes, and renders the result via dangerouslySetInnerHTML with no sanitization. Repository content can steer what the model outputs here (prompt injection), and a slide whose own output already contains a <style> tag skips the page's default-styling wrapper entirely, using the model's raw output as-is. An onerror/onclick handler or <script> tag the model is induced to emit executes in the DeepWiki origin when the victim opens that repository's Slides view.

Sanitizes the extracted slide body with DOMPurify immediately after extraction (before the default-styling wrapper, whose own trusted mermaid/Chart.js init script is unaffected since it's appended after sanitization), and strips all tags from the slide title (also model-derived) before interpolating it into <h1>.

dompurify was already a transitive dependency (pulled in by mermaid for its own output); this adds it as a direct dependency at the same version range already resolved in yarn.lock, so no new package version needed locking.

Test plan

  • Validated with the real dompurify package against the exact payload shape demonstrated for this finding (an img onerror handler and a script tag), confirming both are stripped.
  • npx tsc --noEmit: passes.
  • npx next build: full production build passes.
  • No frontend test runner exists in this repo to add a persistent automated test alongside this fix.

The Slides view builds a prompt asking the model to generate a single
HTML slide, extracts HTML from the response with a few regexes, and
renders the result via dangerouslySetInnerHTML with no sanitization.
Repository content can steer what the model outputs here (prompt
injection), and a slide whose own output already contains a <style>
tag skips the page's default-styling wrapper entirely, using the
model's raw output as-is. An onerror/onclick handler or <script> tag
the model is induced to emit executes in the DeepWiki origin when the
victim opens that repository's Slides view.

Sanitize the extracted slide body with DOMPurify immediately after
extraction (before the default-styling wrapper, whose own trusted
mermaid/Chart.js init script is unaffected since it's appended after
sanitization), and strip all tags from the slide title (also
model-derived) before interpolating it into <h1>.

dompurify was already a transitive dependency (pulled in by mermaid
for its own output); this adds it as a direct dependency at the same
version range already resolved in yarn.lock, so no new package
version needed locking.

Validated with the real dompurify package against the exact payload
shape demonstrated for this finding (an img onerror handler and a
script tag), confirming both are stripped; tsc --noEmit and a full
next build both pass. No frontend test runner exists in this repo to
add a persistent automated test alongside this fix.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant