Skip to content

feat: integrate DOMPurify for HTML sanitization across components#1

Merged
MoinJulian merged 1 commit intomainfrom
fix-html-xss
May 2, 2026
Merged

feat: integrate DOMPurify for HTML sanitization across components#1
MoinJulian merged 1 commit intomainfrom
fix-html-xss

Conversation

@MoinJulian
Copy link
Copy Markdown
Owner

This pull request introduces HTML sanitization across the codebase to improve security and prevent XSS vulnerabilities when rendering user-generated or dynamic HTML content. The main change is the introduction and use of a new sanitizeHTML Svelte action, which leverages the dompurify library to safely inject HTML into the DOM. This action replaces all previous usages of the Svelte {@html ...} directive in relevant files. Additionally, the dompurify dependency is added to the project.

The most important changes are:

Security Improvements: HTML Sanitization

  • Added a new sanitizeHTML Svelte action in src/lib/client/sanitize_HTML.ts, which uses dompurify to sanitize HTML before injecting it into the DOM. This action supports both initial rendering and updates.
  • Replaced all instances of the Svelte {@html ...} directive with the new sanitizeHTML action in UI components and pages, including Popup.svelte, Selection.svelte, and all major route pages that display dynamic HTML content. This ensures that all rendered HTML is sanitized.

Dependency Management

  • Added the dompurify library as a dependency in package.json and updated pnpm-lock.yaml accordingly to ensure it is available for use in the project.

Code Refactoring

  • Updated imports and component logic to use the new sanitizeHTML action instead of direct HTML injection, and ensured all affected files import the new utility.

These changes collectively harden the application against XSS attacks by ensuring all dynamic HTML is sanitized before rendering.

@MoinJulian MoinJulian merged commit 271c837 into main May 2, 2026
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