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
  • GroovyGroovy
  • 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
Python

Python static code analysis

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

  • All rules 414
  • Vulnerability45
  • Bug104
  • Security Hotspot50
  • Code Smell215

  • Quick Fix 33
Filtered: 16 rules found
error-handling
    Impact
      Clean code attribute
        1. ExceptionGroup and BaseExceptionGroup should not be caught with except*

           Bug
        2. "SystemExit" should be re-raised

           Code Smell
        3. Bare "raise" statements should only be used in "except" blocks

           Code Smell
        4. Boolean expressions of exceptions should not be used in "except" statements

           Bug
        5. A subclass should not be in the same "except" statement as a parent class

           Code Smell
        6. Some special methods should return "NotImplemented" instead of raising "NotImplementedError"

           Code Smell
        7. Caught Exceptions must derive from BaseException

           Bug
        8. Exceptions' "__cause__" should be either an Exception or None

           Bug
        9. Special method "__exit__" should not re-raise the provided exception

           Code Smell
        10. Bare "raise" statements should not be used in "finally" blocks

           Code Smell
        11. Raised Exceptions must derive from BaseException

           Bug
        12. Delivering code in production with debug features activated is security-sensitive

           Security Hotspot
        13. Exceptions should not be created without being raised

           Bug
        14. "except" clauses should do more than raise the same issue

           Code Smell
        15. Break, continue and return statements should not occur in "finally" blocks

           Bug
        16. "Exception" and "BaseException" should not be raised

           Code Smell

        Delivering code in production with debug features activated is security-sensitive

        consistency - conventional
        security
        Security Hotspot
        • cwe
        • error-handling
        • debug
        • user-experience

        Development tools and frameworks usually have options to make debugging easier for developers. Although these features are useful during development, they should never be enabled for applications deployed in production. Debug instructions or error messages can leak detailed information about the system, like the application’s path or file names.

        Ask Yourself Whether

        • The code or configuration enabling the application debug features is deployed on production servers or distributed to end users.
        • The application runs by default with debug features activated.

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

        Recommended Secure Coding Practices

        Do not enable debugging features on production servers or applications distributed to end users.

        Sensitive Code Example

        Django application startup:

        from django.conf import settings
        
        settings.configure(DEBUG=True)  # Sensitive when set to True
        settings.configure(DEBUG_PROPAGATE_EXCEPTIONS=True)  # Sensitive when set to True
        
        def custom_config(config):
            settings.configure(default_settings=config, DEBUG=True)  # Sensitive
        

        Inside settings.py or global_settings.py, which are the default configuration files for a Django application:

        DEBUG = True  # Sensitive
        DEBUG_PROPAGATE_EXCEPTIONS = True  # Sensitive
        

        Flask application startup:

        from flask import Flask
        
        app = Flask()
        app.debug = True  # Sensitive
        app.run(debug=True)  # Sensitive
        

        The following code defines a GraphQL endpoint with GraphiQL enabled. While this might be a useful configuration during development, it should never be enabled for applications deployed in production:

        from flask import Flask
        from graphql_server.flask import GraphQLView
        
        app = Flask(__name__)
        
        app.add_url_rule(
            '/graphql',
            view_func=GraphQLView.as_view(
                'graphql',
                schema=schema,
                graphiql=True # Sensitive
            )
        )
        

        Compliant Solution

        from django.conf import settings
        
        settings.configure(DEBUG=False)
        settings.configure(DEBUG_PROPAGATE_EXCEPTIONS=False)
        
        def custom_config(config):
            settings.configure(default_settings=config, DEBUG=False)
        
        DEBUG = False
        DEBUG_PROPAGATE_EXCEPTIONS = False
        
        from flask import Flask
        
        app = Flask()
        app.debug = False
        app.run(debug=False)
        
        from flask import Flask
        from graphql_server.flask import GraphQLView
        
        app = Flask(__name__)
        
        app.add_url_rule(
            '/graphql',
            view_func=GraphQLView.as_view(
                'graphql',
                schema=schema
            )
        )
        

        See

        • OWASP - Top 10 2021 Category A5 - Security Misconfiguration
        • OWASP - Top 10 2017 Category A3 - Sensitive Data Exposure
        • CWE - CWE-489 - Active Debug Code
        • CWE - CWE-215 - Information Exposure Through Debug Information
          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

        © 2026 SonarSource Sàrl. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use