Skip to content

fix(web): sanitize v-html (DOMPurify) + security/memory hardening#687

Merged
xiaofei-zheng merged 7 commits into
mainfrom
fix/web-xss-sanitize-dompurify
Jul 21, 2026
Merged

fix(web): sanitize v-html (DOMPurify) + security/memory hardening#687
xiaofei-zheng merged 7 commits into
mainfrom
fix/web-xss-sanitize-dompurify

Conversation

@fengshaoyi-amd

Copy link
Copy Markdown
Contributor

Summary

Security and stability hardening for the SaFE web app (Web/apps/safe), centered on XSS sanitization plus low-risk memory/perf fixes surfaced by an audit.

Changes

Security

  • XSS: add dompurify and a shared src/utils/sanitize.ts (renderMarkdown / sanitizeHtml / textToBr); route every untrusted v-html sink (chat messages, QA answers, AI analysis reports, confirm dialogs) through it. Enable vue/no-v-html lint guard to prevent regressions.
  • Open redirect: add shared getSafeRedirect() and apply it to SSO / post-login redirects (only same-origin relative paths allowed).
  • Tabnabbing: add rel=noopener noreferrer / noopener to external links and window.open calls.

Memory / performance

  • WebShell: fix a resize listener leak (removeEventListener was passed a new anonymous fn).
  • PlaygroundAgent: abort in-flight stream on onBeforeUnmount; memoize parseThinkingContent (called many times per render).
  • Chat: memoize formatMessage output (capped) to avoid re-parsing markdown on every render / streaming tick.
  • ModelOptimization SSE: cancel reconnect timer on close; cap streamed logs to 5000.
  • Clear debounce timers on unmount (Nodes / QABase / ModelOptimization); remove FloatingChatBot drag listeners if unmounted mid-drag.

Chore

  • Fix 5 pre-existing eslint errors in the touched confirm/chat/playground components.

Verification

  • vue-tsc --noEmit -p tsconfig.app.json passes (exit 0).
  • No new eslint errors introduced; remaining vue/no-v-html warnings are intentional (sanitized sinks).
  • Secret scan of src and tracked env files: clean.

fengshaoyi-amd and others added 5 commits July 17, 2026 11:38
Add dompurify + shared src/utils/sanitize.ts (renderMarkdown / sanitizeHtml / textToBr) and route chat messages, QA answers, and AI analysis reports through it. Prevents stored/reflected XSS from untrusted markdown rendered via v-html.

Co-authored-by: Cursor <cursoragent@cursor.com>
Remove dead secondaryLoading ref, prefix unused param, and scope-disable no-explicit-any for dynamic Element Plus form values.
- WebShell: fix resize listener leak (removeEventListener used a new anon fn)
- Add rel=noopener/noreferrer to external links and window.open calls (anti tabnabbing)
- Add shared getSafeRedirect() and apply to SSO/post-login redirects (anti open-redirect)
- PlaygroundAgent: abort in-flight stream on onBeforeUnmount (fix leak)
- Memoize parseThinkingContent and formatMessage (called many times per render/streaming)
- Cap caches to avoid unbounded growth from streaming tokens
- useOptimizationEvents: cancel SSE reconnect timer on close; cap logs to 5000
- Clear debounce timers on unmount (Nodes, QABase, ModelOptimization)
- FloatingChatBot: remove drag listeners if unmounted mid-drag
@fengshaoyi-amd
fengshaoyi-amd requested a review from a team as a code owner July 17, 2026 08:53
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

fengshaoyi-amd and others added 2 commits July 20, 2026 18:48
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@xiaofei-zheng
xiaofei-zheng merged commit 01e8d9e into main Jul 21, 2026
17 checks passed
@xiaofei-zheng
xiaofei-zheng deleted the fix/web-xss-sanitize-dompurify branch July 21, 2026 03:18
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.

2 participants