Sanitizing HTML content
One of the biggest security issues with web applications is Cross Site Scripting (XSS). In an XSS attack, malicious code is added to HTML that we expect the browser to parse, thus rendering and executing the malicious code on the page. Let's assume that we have the following template. ```js foreach(review in reviews) {
${review.title}
${review.text}
Friendly and delicious!
The restaurant is right in the center of town...
Kitchen nightmares
Fine location, ... things.
HELLO
'; const clean = DOMPurify.sanitize(dirty); document.getElementById('sanitized').innerHTML = clean; ``` You can also create a configuration object to let some elements through the sanitizer. The example does the following: 1. Defines the dirty text 2. Specify a configuration directive, only <p> elements allowed * We want to also keep <p>'s text content, so we add #text too 3. Sanitize the input 4. place the sanitized input in the document {.custom-ordered} ```js // 1 const dirty = 'HELLO
\