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
Dart

Dart static code analysis

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

  • All rules 126
  • Vulnerability4
  • Bug15
  • Security Hotspot8
  • Code Smell99
Filtered: 17 rules found
cwe
    Impact
      Clean code attribute
        1. Exposing native code through JavaScript interfaces is security-sensitive

           Security Hotspot
        2. Pubspec urls should be secure

           Vulnerability
        3. Enabling JavaScript support for WebViews is security-sensitive

           Security Hotspot
        4. Cipher algorithms should be robust

           Vulnerability
        5. Encryption algorithms should be used with secure mode and padding scheme

           Vulnerability
        6. Using clear-text protocols is security-sensitive

           Security Hotspot
        7. Accessing Android external storage is security-sensitive

           Security Hotspot
        8. Server certificates should be verified during SSL/TLS connections

           Vulnerability
        9. Using weak hashing algorithms is security-sensitive

           Security Hotspot
        10. Exceptions should not be ignored

           Code Smell
        11. Using pseudorandom number generators (PRNGs) is security-sensitive

           Security Hotspot
        12. Code annotated as deprecated should not be used

           Code Smell
        13. Unused assignments should be removed

           Code Smell
        14. "==" operator and "hashCode()" should be overridden in pairs

           Bug
        15. Jump statements should not occur in "finally" blocks

           Bug
        16. Track uses of "TODO" tags

           Code Smell
        17. Track uses of "FIXME" tags

           Code Smell

        Exposing native code through JavaScript interfaces is security-sensitive

        responsibility - trustworthy
        security
        Security Hotspot
        • cwe
        • android

        Using JavaScript interfaces in WebViews to expose Java objects is unsafe. Doing so allows JavaScript to invoke Java methods, potentially giving attackers access to data or sensitive app functionality. WebViews might include untrusted sources such as third-party iframes, making this functionality particularly risky. As JavaScript interfaces are passed to every frame in the WebView, those iframes are also able to access the exposed Java object.

        Ask Yourself Whether

        • The content in the WebView is fully trusted and secure.
        • Potentially untrusted iframes could be loaded in the WebView.
        • The JavaScript interface has to be exposed for the entire lifecycle of the WebView.
        • The exposed Java object might be called by untrusted sources.

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

        Recommended Secure Coding Practices

        Disable JavaScript

        If it is possible to disable JavaScript in the WebView, this is the most secure option.

        When using the webview_flutter package, JavaScript is disabled by default. Therefore, setJavaScriptMode does not need to be explicitly called with JavaScriptMode.disabled on WebViewController (v4 and above) or WebView (v3 and below).

        When using the flutter_inappwebview package, on the other hand, the default behavior is to enable JavaScript. Therefore, it is necessary to set the enableJavaScript parameter to false in instances of InAppWebViewSettings and InAppWebViewOptions.

        Of course, sometimes it is necessary to enable JavaScript, in which case the following recommendations should be considered.

        Remove JavaScript interface when loading untrusted content

        JavaScript interfaces can be removed at a later point. It is recommended to remove the JavaScript interface when it is no longer needed. If it is needed for a longer time, consider removing it before loading untrusted content. This can be done by calling webViewController.removeJavaScriptChannel('channelName') for the webview_flutter package or webViewController.removeJavaScriptHandler('channelName') for the flutter_inappwebview package.

        A good place to do this in Flutter is inside navigation callbacks like NavigationDelegate.onNavigationRequest for the webview_flutter package or WebViewClient.shouldOverrideUrlLoading for the flutter_inappwebview package package, where you can check the URL being loaded and remove the JavaScript channel if the content is untrusted.

        Alternative methods to implement native bridges

        If a native channel has to be added to the WebView or its controller, and it is impossible to remove it at a later point, consider using an alternative method that offers more control over the communication flow.

        For the webview_flutter package, there is currently no way to know the origin of an incoming JavaScript message. Therefore using JavaScript communication with webview_flutter is discouraged.

        For the flutter_inappwebview package, use WebMessageListener which allows you to restrict the origins that can send messages to your application.

        Sensitive Code Example

        webview_flutter

        final _controller = WebViewController()
            ..setJavaScriptMode(JavaScriptMode.unrestricted)
            ..addJavaScriptChannel("channel", onMessageReceived: (m) {}); // Sensitive
        

        flutter_inappwebview

        InAppWebView(
          onWebViewCreated: (controller) {
            controller?.addJavaScriptHandler( // Sensitive
              handlerName: "channel",
              callback: (args) {}
            );
          },
        );
        

        Compliant Solution

        The most secure option is to not enable, or disable, JavaScript entirely. S6362 further explains why it should not be enabled unless absolutely necessary.

        webview_flutter

        final _controller = WebViewController();
        

        If possible, remove the JavaScript channel after it is no longer needed, or before loading any untrusted content.

        webview_flutter

        _controller.removeJavaScriptChannel("channel");
        

        flutter_inappwebview

        _controller.removeJavaScriptHandler("channel");
        

        If a JavaScript channel must be used, consider using flutter_inappwebview instead of webview_flutter. The Web Message API allows you to restrict the origins that can send messages to the JavaScript bridge.

        InAppWebView(
          onWebViewCreated: (controller) async {
            await inAppController.addWebMessageListener(
              WebMessageListener(
                jsObjectName: "channel",
                  allowedOriginRules: {
                    "https://secure-origin",
                  }, // Restrict to specific origin
                  onPostMessage: (message, origin, isMainFrame, replyProxy) {},
                ),
              );
          },
        );
        

        See

        • Android Documentation - Insecure WebView native bridges
        • Android Documentation - WebViewCompat API reference
        • OWASP - Top 10 2021 Category A5 - Security Misconfiguration
        • OWASP - Mobile Top 10 2024 Category M4 - Insufficient Input/Output Validation
        • OWASP - Mobile Top 10 2024 Category M8 - Security Misconfiguration
        • CWE - CWE-79 - Improper Neutralization of Input During Web Page Generation

        Related rules

        • S6362 - Enabling JavaScript support for WebViews is security-sensitive
          Available In:
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories
        • SonarQube ServerAnalyze code in your
          on-premise CI

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use