fix: add explicit DOMPurify allowlist for ANSI log rendering#35
Conversation
Restrict allowed tags to span and br, attributes to style only. Tighter than DOMPurify defaults — guards against future version changes while preserving ANSI color spans. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
| Filename | Overview |
|---|---|
| frontend/src/ide/editor/no-code-model/no-code-model.jsx | Adds explicit ALLOWED_TAGS and ALLOWED_ATTR config to DOMPurify.sanitize in parseLog — correct, minimal, and matches ansi-to-html output. |
Sequence Diagram
sequenceDiagram
participant LogSource as Log Source
participant parseLog as parseLog()
participant ansiToHtml as ansi-to-html
participant DOMPurify as DOMPurify.sanitize()
participant DOM as React innerHTML
LogSource->>parseLog: "raw ANSI log string"
parseLog->>ansiToHtml: "toHtml(log)"
ansiToHtml-->>parseLog: "HTML with span[style] and br tags"
parseLog->>DOMPurify: "sanitize(html, {ALLOWED_TAGS:[span,br], ALLOWED_ATTR:[style]})"
DOMPurify-->>parseLog: "sanitized HTML - only span/br with style"
parseLog-->>DOM: "safe HTML via dangerouslySetInnerHTML"
Reviews (2): Last reviewed commit: "fix: restore package-lock.json from main" | Re-trigger Greptile
npm ci was failing because lock file was out of sync with dependency versions from recent dependabot merges. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Previous regeneration caused version mismatches in CI. This PR only changes a .jsx file — no lock file changes needed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
What
Why
How
ALLOWED_TAGS: ["span", "br"]— only tags ansi-to-html generatesALLOWED_ATTR: ["style"]— only attribute needed for ANSI colorsCan this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)
<span style="color:...">and<br>tags, both are in the allowlistDatabase Migrations
Env Config
Notes on Testing
Checklist
I have read and understood the Contribution Guidelines.