Unsanitized user input in raw HTML strings (XSS)

Description

Including unsanitized user input in HTML exposes your application to cross-site scripting (XSS) attacks. This vulnerability allows attackers to inject malicious scripts into web pages viewed by other users.

Remediations

  • Do not include user input directly in HTML strings. This practice can lead to XSS vulnerabilities.
    html = "<h1>#{params[:title]}</h1>"
  • Do use a templating language, such as ERB, and keep the template in a separate file to safely incorporate user input.
  • Do sanitize user input when HTML strings must be used, to prevent malicious code injection.
    html = "<h1>#{strip_tags(params[:title])}</h1>"

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=ruby_lang_raw_html_using_user_input

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

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