Skip to content

Latest commit

 

History

History
21 lines (17 loc) · 866 Bytes

sanitation.md

File metadata and controls

21 lines (17 loc) · 866 Bytes

Sanitation

Use of the innerHTML method can lead to cross-site scripting (XSS) vunerabilities if not properly sanitized. If you can't use vnodes for any reason, create your own replacement function to explicitly state the intent of performing an "unsafe" operation.

function dangerouslySetInnerHTML(html) {
  return element => {
    element.innerHTML = html
  }
}

function ItemContent({ item: { url, summary } }) {
  return (
    <div class="content">
      <a href={url} oncreate={dangerouslySetInnerHTML(summary)} />
    </div>
  )
}

Setting HTML from code is dangerous because it's easy to inadvertently expose your users to an XSS attack. DOMPurify and sanitize-html are two popular HTML sanitizer libraries.