Usage of manual HTML sanitization (XSS)

Description

Sanitizing HTML manually is error prone and can lead to Cross Site Scripting (XSS) vulnerabilities.

Remediations

❌ Avoid manually escaping HTML:

const sanitizedUserInput = user.Input
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;');
const html = `<strong>${sanitizedUserInput}</strong>`;

✅ Use a HTML sanitization library:

import sanitizeHtml from 'sanitize-html';

const html = sanitizeHtml(`<strong>${user.Input}</strong>`);

Resources

Associated CWE

OWASP Top 10

Configuration

To skip this rule during a scan, use the following flag

bearer scan /path/to/your-project/ --skip-rule=javascript_lang_manual_html_sanitization

To run only this rule during a scan, use the following flag

bearer scan /path/to/your-project/ --only-rule=javascript_lang_manual_html_sanitization