When generating and inserting HTML or CSS as raw strings, treat it as untrusted input and avoid direct injection into the DOM. Constructing
Guidance:
Examples: // Unsafe: building a ; // avoid this unless input is fully trusted
// Safer: set CSS variables on elements (no raw HTML injection) // For each themed container element: <div data-likec4-color={name} style= />
// If injection is required, sanitize and document import DOMPurify from ‘dompurify’; const safe = DOMPurify.sanitize(styles, {ALLOWED_TAGS: [‘style’], ALLOWED_ATTR: []}); return <style dangerouslySetInnerHTML= />; // include comment why injection is necessary
Why this matters: Unescaped or unsanitized content inserted into the DOM can enable XSS or CSS injections. Using safe APIs, validation, or vetted sanitization prevents class of security vulnerabilities and makes intent explicit during code review.
Enter the URL of a public GitHub repository