Missing escape of HTML entities in Handlebars template compilation

Description

In Handlebars (a templating engine that dynamically generates HTML markup), setting noEscape to true disables escaping HTML entities within the template output itself. This poses a security vulnerability, particularly leading to Cross-Site Scripting (XSS) attacks if the template content comes from an untrusted source.

Remediations

  • Do set noEscape to false while compiling Handlebars templates, to ensure that HTML entities are properly escaped, thus mitigating the risk of XSS vulnerabilities.
    Handlebars.compile(template, { noEscape: false });

References

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_handlebars_no_escape

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

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