Skip to content
nexus-dialogs
GitHub npm

Security

What the library does with the content you pass it and what falls to whoever uses it. What is on this page is covered by tests (test/unit/seguridad.test.ts).

#The short rule

#Strict mode (default since 0.5.0)

Any string html that does not go through a configured sanitize is shown as text instead of being interpreted. If someone forgets to configure the filter, the result is ugly text, not an XSS.

// With your own content (constants in your code): turn it off on purpose.
configure({ strictHtml: false })

// With content that is not yours: give it a filter and the HTML is interpreted already clean.
configure({ sanitize: (html) => DOMPurify.sanitize(html) })

Before 0.5.0 HTML was inserted as is by default. If you upgrade and see tags like <b> on screen, this is why.

#When to use each thing

I want to show…Use
A message with user data (name, comment, server error)text (or title). Never html.
Your own content with bold, lists or fixed linksString html written by you (a constant in your code) with strictHtml: false, or a sanitize.
Content that comes from outside and must be shown with formattinghtml + the sanitize filter (below), or build a Node with textContent/createElement.

#The sanitize filter

A single entry point for all string HTML. It is configured once:

import DOMPurify from 'dompurify'
import { configure } from 'nexus-dialogs'

configure({ sanitize: (html) => DOMPurify.sanitize(html) })

sanitize can return a string or an object with toString() (for example, a TrustedHTML). With sanitize: null it is removed. From then on, dialog.alert({ html }) and, with nexus-dialogs/swal, html, iconHtml, closeButtonHtml and loaderHtml go through your function before reaching the DOM. The library does not ship its own sanitizer on purpose: cleaning HTML by hand is a classic source of bugs and it is better to use a maintained one (DOMPurify, or the native Sanitizer API when your target browser has it).

What the filter does not touch: texts (they are already text) and Nodes, which are your responsibility (see above).

#Other doors worth knowing about

#What is tested and what is not

ThingHow
Texts as text, sanitize, strictHtmlUnit tests
Formula injection (=1+1, @SUM(A1:A2), +cmd, -1+2, HYPERLINK, cmd|…)Unit tests; in addition, LibreOffice opens the exported CSV and xlsx without creating formulas (checked by converting them with soffice)
Opening in Microsoft ExcelNot tested by us. The file follows OWASP's recommendation, but we haven't opened it in Excel
CSP and Trusted TypesTests in real Chromium
Memory leaks300 dialogs, forms and toasts opened and closed leave no DOM nodes (Chromium)
DependenciesThe library has no production dependencies; production npm audit runs on every change

#How to report a vulnerability

See SECURITY.md: private channel, response times and how versions are published.