Skip to content

Security Response Strategies

Section titled “Strategy 1: Graceful Degradation (Recommended)”

Gradually restrict functionality based on threat severity:

class SecurityManager {
static Future<void> handleSecurityStatus() async {
// getRejectReasons() returns a newline-separated string; split it into a list
final rejectReasonsRaw = await AlphynSdk.getRejectReasons();
final rejectReasons = rejectReasonsRaw.split('\n').where((line) => line.trim().isNotEmpty).toList();
final riskFactors = await AlphynSdk.getAllRiskFactors();
if (rejectReasons.isEmpty) {
// TRUSTED - Full functionality
print('✅ Full access granted');
enableAllFeatures();
} else if (rejectReasons.length < 3) {
// FLAGGED - Limited functionality
print('⚠️ Operating in restricted mode');
disableSensitiveFeatures();
logSecurityEvent(rejectReasons);
showSecurityWarning();
} else {
// UNTRUSTED - Minimal or no functionality
print('🚨 Critical security violation');
disableAllSensitiveFeatures();
logCriticalSecurityEvent(rejectReasons);
showCriticalSecurityAlert();
}
}
static void enableAllFeatures() {
// Enable payments, sensitive data access, etc.
}
static void disableSensitiveFeatures() {
// Disable payments, limit data access
}
static void disableAllSensitiveFeatures() {
// Block all sensitive operations
}
static void showSecurityWarning() {
// Show user-friendly warning dialog
}
static void showCriticalSecurityAlert() {
// Show critical security alert with explanation
}
static void logSecurityEvent(List<String> reasons) {
// Log to analytics/monitoring service
}
static void logCriticalSecurityEvent(List<String> reasons) {
// Log critical event with full details
}
}

Make decisions based on specific risk factors:

class RiskBasedSecurityHandler {
static Future<void> evaluateSecurity() async {
// getRejectReasons() returns a newline-separated string; split it into a list
final rejectReasonsRaw = await AlphynSdk.getRejectReasons();
final rejectReasons = rejectReasonsRaw.split('\n').where((line) => line.trim().isNotEmpty).toList();
final riskFactors = await AlphynSdk.getAllRiskFactors();
// Check for critical threats
final hasCriticalThreats = _checkCriticalThreats(rejectReasons);
final hasDebuggerAttached = _checkDebugger(rejectReasons);
final isRooted = _checkRootAccess(rejectReasons);
if (hasCriticalThreats) {
print('🚨 Critical threat detected - terminating');
terminateApp();
} else if (hasDebuggerAttached) {
print('⚠️ Debugger detected - limiting functionality');
disableDebugSensitiveFeatures();
} else if (isRooted) {
print('⚠️ Root/Jailbreak detected');
handleRootedDevice();
} else {
print('✅ No significant threats');
proceedNormally();
}
}
static bool _checkCriticalThreats(List<String> reasons) {
// Check for critical detection types from actual SDK output
final criticalDetections = [
'FRIDA_DETECTED',
'FRIDA_SERVER_RUNNING',
'SIMULATOR_RUNTIME',
'HOOK_DETECTED',
'TAMPERED',
'MODIFIED'
];
return reasons.any((reason) =>
criticalDetections.any((detection) =>
reason.toUpperCase().contains(detection)
)
);
}
static bool _checkDebugger(List<String> reasons) {
// Check for debugger-related detections
final debuggerDetections = [
'DEBUGGER_SYSTEM_CHECK',
'DEBUGGER_PROCESS_CHECK',
'DEBUGGER_EXCEPTION_CHECK'
];
return reasons.any((reason) =>
debuggerDetections.any((detection) =>
reason.toUpperCase().contains(detection)
)
);
}
static bool _checkRootAccess(List<String> reasons) {
// Check for root/jailbreak detections
final rootDetections = [
'ROOT_DETECTED',
'JAILBREAK_DETECTED',
'SUPERUSER',
'SU_BINARY'
];
return reasons.any((reason) =>
rootDetections.any((detection) =>
reason.toUpperCase().contains(detection)
)
);
}
static bool _checkSimulatorOrEmulator(List<String> reasons) {
// Check for simulator/emulator detections
final simulatorDetections = [
'SIMULATOR_ENVIRONMENT',
'SIMULATOR_RUNTIME',
'EMULATOR_DETECTED'
];
return reasons.any((reason) =>
simulatorDetections.any((detection) =>
reason.toUpperCase().contains(detection)
)
);
}
static void terminateApp() {
// Log event and exit app
// SystemNavigator.pop() or exit(0)
}
static void disableDebugSensitiveFeatures() {
// Disable features vulnerable to debugging
}
static void handleRootedDevice() {
// Show warning or restrict features
}
static void proceedNormally() {
// Continue with full functionality
}
}

Implement periodic security checks:

class ContinuousSecurityMonitor {
Timer? _monitoringTimer;
void startMonitoring({Duration interval = const Duration(minutes: 5)}) {
_monitoringTimer?.cancel();
_monitoringTimer = Timer.periodic(interval, (timer) async {
await performSecurityCheck();
});
// Initial check
performSecurityCheck();
}
void stopMonitoring() {
_monitoringTimer?.cancel();
_monitoringTimer = null;
}
Future<void> performSecurityCheck() async {
try {
// getRejectReasons() returns a newline-separated string; split it into a list
final rejectReasonsRaw = await AlphynSdk.getRejectReasons();
final rejectReasons = rejectReasonsRaw.split('\n').where((line) => line.trim().isNotEmpty).toList();
final lastScanDate = await AlphynSdk.getLastScanDate();
print('🔍 Security check at: ${DateTime.now()}');
print('Last scan: $lastScanDate');
print('Threats: ${rejectReasons.length}');
if (rejectReasons.isNotEmpty) {
handleSecurityThreats(rejectReasons);
}
// Check if scan is stale (older than expected interval)
if (lastScanDate != null) {
final timeSinceLastScan = DateTime.now().difference(lastScanDate);
if (timeSinceLastScan > const Duration(minutes: 10)) {
print('⚠️ Warning: Scan data is stale');
}
}
} catch (e) {
print('❌ Security check failed: $e');
}
}
void handleSecurityThreats(List<String> threats) {
// Implement threat response logic
for (var threat in threats) {
print('⚠️ Threat detected: $threat');
}
}
}