Skip to content

Add input sanitization and XSS protection for rich text template fields #611

Description

@Smartdevs17

Context

Email and notification templates accept rich text with HTML. Without sanitization, these fields are XSS vectors for admin users.

Current Limitation/Problem

HTML in email templates is rendered as-is. A malicious admin can inject <script> tags that execute in other admin browsers.

Expected Outcome

Server-side DOMPurify sanitization for all rich text inputs, tag/attribute allowlist, CSP headers on admin dashboard, and back-scan job for existing templates.

Acceptance Criteria

  • Server-side sanitization: DOMPurify (via jsdom) on all rich text input fields
  • Tag allowlist: p, span, a, img, table, tr, td, th, h1-h6, ul, ol, li, strong, em, br, hr
  • Attribute allowlist: href, src, alt, style, class, target (rel=noreferrer forced on links)
  • Protocol restriction: href only allows http:, https:, mailto: (reject javascript:, data:, vbscript:)
  • SVGs: strip all SVG tags and attributes (common XSS vector)
  • CSP headers: Content-Security-Policy on admin dashboard with script-src 'self', object-src 'none'
  • Template preview: render sanitized output in preview pane before save
  • Edge case: already-saved templates with malicious content (back-scan job with quarantine)

Technical Scope

  • backend/shared/sanitizer/ - HTMLSanitizerService wrapping DOMPurify
  • backend/shared/middleware/ - CSP header middleware
  • backend/notification/domain/ - sanitize on template save
  • backend/notification/jobs/ - back_scan_templates cron for existing templates
  • developer-portal/ - CSP headers for admin dashboard pages

Metadata

Metadata

Assignees

Labels

200-points200 point issueStellar WaveIssues in the Stellar wave programdrips-waveIssues in the Drips Wave programhighHigh complexity issue

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions