Dart Postgres Ssl Verification Bypass

Description

This detector identifies PostgreSQL database connections in Dart applications that bypass SSL certificate verification. When SSL verification is disabled, the application becomes vulnerable to man-in-the-middle attacks where an attacker can intercept, read, or modify database communications by presenting fake certificates.

Weakness:

313 - Insecure service configuration - Certificates

Category: Functionality Abuse

Detection Strategy

    The detector triggers when the 'package:postgres/postgres.dart' library is imported in the Dart code

    It looks for calls to the ConnectionSettings constructor used to configure PostgreSQL database connections

    A vulnerability is reported when any argument passed to ConnectionSettings contains an unsafe SSL mode configuration that disables certificate verification

Vulnerable code example

import 'package:postgres/postgres.dart';

Future<void> unsafeConnection() async {
  final endpoint = Endpoint(host: 'db.example.com', database: 'app');
  await Connection.open(
    endpoint,
    settings: ConnectionSettings(sslMode: SslMode.require), // Vulnerable: accepts invalid certificates
  );...

✅ Secure code example

import 'package:postgres/postgres.dart';

Future<void> safeConnection() async {
  final endpoint = Endpoint(host: 'db.example.com', database: 'app');
  await Connection.open(
    endpoint,
    settings: ConnectionSettings(sslMode: SslMode.verifyFull), // Safe: full certificate verification
  );...