SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
HTML

HTML static code analysis

Unique rules to find Bugs, Security Hotspots, and Code Smells in your HTML code

  • All rules 83
  • Bug23
  • Security Hotspot3
  • Code Smell57
 
Tags
    Impact
      Clean code attribute
        1. Using remote artifacts without integrity checks is security-sensitive

           Security Hotspot
        2. Disabling auto-escaping in template engines is security-sensitive

           Security Hotspot
        3. Authorizing an opened window to access back to the originating window is security-sensitive

           Security Hotspot

        Disabling auto-escaping in template engines is security-sensitive

        intentionality - complete
        security
        Security Hotspot
        • cwe

        To reduce the risk of cross-site scripting attacks, templating systems, such as Twig, Django, Smarty, Groovy's template engine, allow configuration of automatic variable escaping before rendering templates. When escape occurs, characters that make sense to the browser (eg: <a>) will be transformed/replaced with escaped/sanitized values (eg: & lt;a& gt; ).

        Auto-escaping is not a magic feature to annihilate all cross-site scripting attacks, it depends on the strategy applied and the context, for example a "html auto-escaping" strategy (which only transforms html characters into html entities) will not be relevant when variables are used in a html attribute because ':' character is not escaped and thus an attack as below is possible:

        <a href="{{ myLink }}">link</a> // myLink = javascript:alert(document.cookie)
        <a href="javascript:alert(document.cookie)">link</a> // JS injection (XSS attack)
        

        Ask Yourself Whether

        • Templates are used to render web content and
          • dynamic variables in templates come from untrusted locations or are user-controlled inputs
          • there is no local mechanism in place to sanitize or validate the inputs.

        There is a risk if you answered yes to any of those questions.

        Recommended Secure Coding Practices

        Enable auto-escaping by default and continue to review the use of inputs in order to be sure that the chosen auto-escaping strategy is the right one.

        Sensitive Code Example

        <!-- Django templates -->
        <p>{{ variable|safe }}</p><!-- Sensitive -->
        {% autoescape off %}<!-- Sensitive -->
        
        <!-- Jinja2 templates -->
        <p>{{ variable|safe }}</p><!-- Sensitive -->
        {% autoescape false %}<!-- Sensitive -->
        

        See

        • OWASP - Top 10 2021 Category A3 - Injection
        • OWASP Cheat Sheet - XSS Prevention Cheat Sheet
        • OWASP - Top 10 2017 Category A7 - Cross-Site Scripting (XSS)
        • CWE - CWE-79 - Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
          Available In:
        • SonarQube IdeCatch issues on the fly,
          in your IDE
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories
        • SonarQube Community BuildAnalyze code in your
          on-premise CI
          Available Since
          10.4
        • SonarQube ServerAnalyze code in your
          on-premise CI
          Developer Edition
          Available Since
          10.4

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use