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. Label elements should have a text label and an associated control

           Code Smell
        2. Elements with an interactive role should support focus

           Code Smell
        3. Images should have a non-redundant alternate description

           Code Smell
        4. Heading elements should have accessible content

           Code Smell
        5. Non-interactive DOM elements should not have an interactive handler

           Code Smell
        6. Non-interactive elements shouldn't have event handlers

           Code Smell
        7. DOM elements should not use the "accesskey" property

           Code Smell
        8. Non-interactive DOM elements should not have the `tabIndex` property

           Code Smell
        9. Anchor tags should not be used as buttons

           Code Smell
        10. Interactive DOM elements should not have non-interactive ARIA roles

           Code Smell
        11. Non-interactive DOM elements should not have interactive ARIA roles

           Code Smell
        12. "tabIndex" values should be 0 or -1

           Code Smell
        13. DOM elements should use the "autocomplete" attribute correctly

           Code Smell
        14. Anchors should contain accessible content

           Code Smell
        15. Focusable elements should not have "aria-hidden" attribute

           Code Smell
        16. DOM elements with the `aria-activedescendant` property should be accessible via the tab key

           Code Smell
        17. ARIA properties in DOM elements should have valid values

           Code Smell
        18. Using remote artifacts without integrity checks is security-sensitive

           Security Hotspot
        19. "<object>" tags should provide an alternative content

           Code Smell
        20. Table cells should reference their headers

           Bug
        21. Tables used for layout should not include semantic markup

           Bug
        22. HTML "<table>" should not be used for layout purposes

           Code Smell
        23. Tables should have headers

           Bug
        24. "aria-label" or "aria-labelledby" attributes should be used to differentiate similar elements

           Code Smell
        25. "<html>" element should have a language attribute

           Bug
        26. Disabling auto-escaping in template engines is security-sensitive

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

           Security Hotspot
        28. <script>...</script> elements should not be nested

           Bug
        29. Videos should have subtitles

           Code Smell
        30. Track presence of forbidden parent element

           Code Smell
        31. Dynamic includes should not be used

           Code Smell
        32. Track uses of disallowed elements

           Code Smell
        33. The "style" attribute should not be used

           Code Smell
        34. Track uses of disallowed attributes

           Code Smell
        35. Track lack of required child elements

           Code Smell
        36. Some Java packages or classes should not be used in JSP files

           Code Smell
        37. Track uses of disallowed child elements

           Code Smell
        38. Multiple "page" directives should not be used

           Code Smell
        39. White space should be used in JSP/JSF tags

           Code Smell
        40. Disallowed "taglibs" should not be used

           Code Smell
        41. Track lack of required attributes

           Code Smell
        42. Labels should be defined in the resource bundle

           Bug
        43. Track lack of required parent elements

           Code Smell
        44. Files should not be too complex

           Code Smell
        45. HTML comments should be removed

           Code Smell
        46. Web pages should not contain absolute URIs

           Code Smell
        47. Attributes deprecated in HTML5 should not be used

           Code Smell
        48. JSP expressions should not be used

           Code Smell
        49. All HTML tags should be closed

           Bug
        50. Attributes should be quoted using double quotes rather than single ones

           Code Smell
        51. JavaScript scriptlets should not have too many lines of code

           Code Smell
        52. Track lack of copyright and license headers

           Code Smell
        53. Track lack of required an element with the required "id"

           Code Smell
        54. JSF expressions should be syntactically valid

           Bug
        55. Track uses of disallowed namespaces in XHTML documents

           Code Smell
        56. Sections of code should not be commented out

           Code Smell
        57. Track uses of "TODO" tags

           Code Smell
        58. Track uses of "FIXME" tags

           Code Smell
        59. "<th>" tags should have "id" or "scope" attributes

           Bug
        60. Links with identical texts should have identical targets

           Code Smell
        61. "<strong>" and "<em>" tags should be used

           Bug
        62. Image tags should have "width" and "height" attributes

           Bug
        63. Favicons should be used in all pages

           Code Smell
        64. "input", "select" and "textarea" tags should be labeled

           Bug
        65. "<title>" should be present in all pages

           Bug
        66. "<!DOCTYPE>" declarations should appear before "<html>" tags

           Bug
        67. Meta tags should not be used to refresh or redirect

           Code Smell
        68. "<li>" and "<dt>" item tags should be in "<ul>", "<ol>" or "<dl>" container tags

           Bug
        69. Links should not directly target images

           Code Smell
        70. Server-side image maps ("ismap" attribute) should not be used

           Bug
        71. "<frames>" should have a "title" attribute

           Bug
        72. "<fieldset>" tags should contain a "<legend>"

           Bug
        73. Flash animations should be embedded using the window mode

           Bug
        74. Flash animations should be embedded using both "<object>" and "<embed>"

           Bug
        75. Heading tags should be used consecutively from "H1" to "H6"

           Code Smell
        76. "<table>" tags should have a description

           Bug
        77. Links should not target "#" or "javascript:void(0)"

           Code Smell
        78. Elements deprecated in HTML5 should not be used

           Bug
        79. Mouse events should have corresponding keyboard events

           Bug
        80. Image, area and button with image elements should have an "alt" attribute

           Code Smell
        81. Tabulation characters should not be used

           Code Smell
        82. Files should not have too many lines

           Code Smell
        83. Lines should not be too long

           Code Smell

        Using remote artifacts without integrity checks is security-sensitive

        intentionality - complete
        security
        Security Hotspot
        • cwe

        Using remote artifacts without integrity checks can lead to the unexpected execution of malicious code in the application.

        On the client side, where front-end code is executed, malicious code could:

        • impersonate users' identities and take advantage of their privileges on the application.
        • add quiet malware that monitors users' session and capture sensitive secrets.
        • gain access to sensitive clients' personal data.
        • deface, or otherwise affect the general availability of the application.
        • mine cryptocurrencies in the background.

        Likewise, a compromised software piece that would be deployed on a server-side application could badly affect the application’s security. For example, server-side malware could:

        • access and modify sensitive technical and business data.
        • elevate its privileges on the underlying operating system.
        • Use the compromised application as a pivot to attack the local network.

        By ensuring that a remote artifact is exactly what it is supposed to be before using it, the application is protected from unexpected changes applied to it before it is downloaded.
        Especially, integrity checks will allow for identifying an artifact replaced by malware on the publication website or that was legitimately changed by its author, in a more benign scenario.

        Important note: downloading an artifact over HTTPS only protects it while in transit from one host to another. It provides authenticity and integrity checks for the network stream only. It does not ensure the authenticity or security of the artifact itself.

        Ask Yourself Whether

        • The artifact is a file intended to execute code.
        • The artifact is a file that is intended to configure or affect running code in some way.

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

        Recommended Secure Coding Practices

        To check the integrity of a remote artifact, hash verification is the most reliable solution. It does ensure that the file has not been modified since the fingerprint was computed.

        In this case, the artifact’s hash must:

        • Be computed with a secure hash algorithm such as SHA512, SHA384 or SHA256.
        • Be compared with a secure hash that was not downloaded from the same source.

        To do so, the best option is to add the hash in the code explicitly, by following Mozilla’s official documentation on how to generate integrity strings.

        Note: Use this fix together with version binding on the remote file. Avoid downloading files named "latest" or similar, so that the front-end pages do not break when the code of the latest remote artifact changes.

        Sensitive Code Example

        The following code sample uses neither integrity checks nor version pinning:

        <script
            src="https://cdn.example.com/latest/script.js"
        ></script> <!-- Sensitive -->
        

        Compliant Solution

        <script
            src="https://cdn.example.com/v5.3.6/script.js"
            integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
        ></script>
        

        See

        • OWASP - Top 10 2021 Category A8 - Software and Data Integrity Failures
        • CWE - CWE-353 - Missing Support for Integrity Check
        • OWASP - Top 10 2017 Category A6 - Security Misconfiguration
        • developer.mozilla.org - Subresource Integrity
        • Wikipedia, Watering Hole Attacks
          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
          9.1
        • SonarQube ServerAnalyze code in your
          on-premise CI
          Developer Edition
          Available Since
          9.1

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use