Unsafe HTML Injection

dangerouslySetInnerHTML, direct innerHTML assignment

criticalSecurityunsafe-html

Why this matters

Injecting unsanitized HTML opens the door to XSS attacks. An attacker can execute JavaScript in your users' browsers, steal sessions, and exfiltrate data.

Example

Flaggedcomponents/comment.tsx
function Comment({ html }: { html: string }) {
  return (
    <div dangerouslySetInnerHTML={{ __html: html }} />
  );
}
Fixedcomponents/comment.tsx
import DOMPurify from "dompurify";

function Comment({ html }: { html: string }) {
  const clean = DOMPurify.sanitize(html);
  return (
    <div dangerouslySetInnerHTML={{ __html: clean }} />
  );
}

How to fix

Sanitize all HTML with DOMPurify or a similar library before rendering. Better yet, use React's built-in text escaping and avoid dangerouslySetInnerHTML entirely.

Reference

In the output
Findings carry "ruleId": "unsafe-html" in --json and the same id in SARIF and in the terminal.
Silence one line
// prodlint-disable-next-line unsafe-html
Silence a whole file
// prodlint-disable unsafe-html at the top of the file
How it works
Reads the syntax tree, with a text fallback for files that don't parse. Source on GitHub