Dart Insecure Websocket Channel

Description

This detector identifies insecure WebSocket connections in Dart applications that use non-encrypted protocols (ws://) instead of secure protocols (wss://). Using unencrypted WebSocket connections exposes data transmission to interception and man-in-the-middle attacks, compromising the confidentiality and integrity of communication.

Weakness:

022 - Use of an insecure channel

Category: Information Collection

Detection Strategy

    Scans Dart source code for imports of WebSocket packages and identifies connection establishment functions

    Examines WebSocket connection calls to check if the first argument (URI) uses an insecure protocol

    Reports vulnerability when a WebSocket connection is made using 'ws://' protocol instead of the secure 'wss://' protocol

    Validates that the URI parameter passed to WebSocket connection methods contains insecure protocol schemes

Vulnerable code example

import 'package:web_socket_channel/web_socket_channel.dart';

void connectWebSocket() {
  // VULNERABLE: Uses insecure ws:// protocol instead of wss://
  final channel = WebSocketChannel.connect(
    Uri.parse('ws://example.com/socket'),
  );
}

✅ Secure code example

import 'package:web_socket_channel/web_socket_channel.dart';

void connectWebSocket() {
  // SAFE: Uses wss:// protocol for encrypted WebSocket transport
  final channel = WebSocketChannel.connect(
    Uri.parse('wss://example.com/socket'),
  );
}