Security & Sanitization (@methane-ui/sanitize)
Every rich text, Markdown, and AI streaming surface in Methane sanitizes untrusted HTML through @methane-ui/sanitize. Raw innerHTML and LitunsafeHTML outside @methane-ui/sanitize are statically banned by@methane-ui/lint-plugin.
Defense-in-Depth Rules
- Native Sanitizer API + DOMPurify Parity: Feature-detects
'setHTML' in Element.prototypeand falls back to bundled DOMPurify configured for strict native parity (ALLOW_ARIA_ATTR: false,ALLOW_DATA_ATTR: false,KEEP_CONTENT: false,RETURN_TRUSTED_TYPE: trueunder Trusted Types CSP). - Zero
innerHTMLRe-Serialization: Parsed fragments move directly into the DOM without round-tripping strings. - URL Allowlist (
isSafeUrl): Allows onlyhttps:,http:,mailto:,tel:, and relative/or#paths; rejectsjavascript:,data:, andvbscript:. - User SVGs & Uploads: Uploaded SVGs render exclusively via
<img src>(never inline<svg>). Client-side upload MIME/size checks are advisory UX checks only; server-side validation is mandatory.
import { safeSetHTML, parseSafeFragment, isSafeUrl } from '@methane-ui/sanitize';
safeSetHTML(containerEl, untrustedHtml);