flutter_app_security library

Flutter App Security

A comprehensive Flutter security module providing multiple layers of protection against common mobile app attacks.

Features

  • Root/Jailbreak Detection - Detect compromised devices
  • Emulator Detection - Prevent running on emulators/simulators
  • Debug Mode Detection - Detect debugging and development tools
  • App Tampering Detection - Detect repackaged or modified apps
  • Hooking Framework Detection - Detect Frida, Xposed, etc.
  • SSL Pinning - Prevent man-in-the-middle attacks
  • Screenshot Prevention - Prevent screenshots and screen recording

Quick Start

import 'package:flutter_app_security/flutter_app_security.dart';

void main() async {
  // Initialize with configuration
  await AppSecurity.instance.initialize(
    SecurityConfig.production(),
  );

  // Run security checks
  final result = await AppSecurity.instance.runSecurityChecks();

  if (!result.isSecure) {
    print('Threats detected: ${result.detectedThreats}');
  }

  runApp(MyApp());
}

Configuration Options

// Development (relaxed)
SecurityConfig.development()

// Production (strict)
SecurityConfig.production(
  certificatePins: ['sha256/AAAA...'],
  onThreatDetected: (result) => handleThreat(result),
)

// Custom
SecurityConfig(
  checkRootJailbreak: true,
  checkEmulator: true,
  checkDebugMode: false, // Allow debug builds
  preventScreenshot: true,
)

Classes

AppSecurity
Main security service for Flutter apps
CertificatePinGenerator
Helper to generate certificate pins
CheckResult
Result of a specific security check
DebugDetection
Debug mode and debugger attachment detection
EmulatorDetection
Emulator and Simulator detection for Android and iOS
RecordingDetectedWidget
Default widget shown when screen recording is detected
RootDetection
Root and Jailbreak detection for Android and iOS
ScreenSecurity
Screenshot and Screen Recording Prevention
SecureApp
Widget that wraps content with security checks
SecureContent
Widget that protects its content from screenshots
SecurityBlockedScreen
Default widget to show when security checks fail
SecurityCheckResult
Result of a security check
SecurityConfig
Configuration for the security module
SslPinning
SSL Certificate Pinning
TamperingDetection
App tampering and integrity detection

Enums

SecurityAction
Action to take when a security threat is detected
SecurityThreat
Security threat types that can be detected