A comprehensive React Native security checker that detects jailbreak, root, emulators, hooks, tampering, and other security threats
npm install react-native-security-checkerA comprehensive React Native security checker that detects jailbreak, root, emulators, hooks, tampering, and other security threats on both iOS and Android platforms.
``sh`
npm install react-native-security-checker
Add the following to your ios/Podfile:
`ruby`
pod 'react-native-security-checker', :path => '../node_modules/react-native-security-checker'
Then run:
`sh`
cd ios && pod install
No additional setup required for Android.
`js
import { detectEnvironment, SecurityCheckResult } from 'react-native-security-checker';
const checkSecurity = async () => {
try {
const result: SecurityCheckResult = await detectEnvironment();
console.log('Security Check Results:', result);
if (result.isInsecureEnvironment) {
console.warn('Insecure environment detected!');
// Handle specific threats
if (result.isRooted || result.isJailbroken) {
console.warn('Device is rooted/jailbroken');
}
if (result.isEmulator || result.isRunningInSimulator) {
console.warn('Running on emulator/simulator');
}
if (result.isHooked) {
console.warn('App is hooked by frameworks');
}
if (result.isTampered) {
console.warn('App has been tampered with');
}
} else {
console.log('Environment appears secure');
}
// Display user-friendly messages
if (result.messages && result.messages.length > 0) {
result.messages.forEach(message => {
console.log(${message.type.toUpperCase()}: ${message.title});Suggestion: ${message.suggestion}
console.log(message.message);
if (message.suggestion) {
console.log();
}
});
}
} catch (error) {
console.error('Security check failed:', error);
}
};
// Run security check
checkSecurity();
`
For continuous security monitoring with automatic checks on app state changes, use the useSecurityChecker hook:
`typescript
import React from 'react';
import { View, Text, Button, Alert } from 'react-native';
import { useSecurityChecker, createDefaultConfig } from 'react-native-security-checker';
function MyComponent() {
const config = createDefaultConfig();
const {
state,
checkSecurity,
startMonitoring,
stopMonitoring,
reset
} = useSecurityChecker(
(result) => {
// Called when security issues are detected
console.log('Security issue detected:', result);
Alert.alert('Security Alert', 'Security threat detected!');
},
5000, // Check every 5 seconds
{
config,
checkOnBackground: true, // Check when app goes to background
checkOnForeground: true, // Check when app comes to foreground
startImmediately: true, // Start monitoring immediately
enableContinuousMonitoring: true // Enable periodic checks
}
);
return (
{state.lastError && (
)}
);
}
`
`js
import {
detectEnvironment,
createDefaultConfig,
createMinimalConfig,
createComprehensiveConfig,
SecurityCheckConfig
} from 'react-native-security-checker';
// Use predefined configurations
const minimalResult = await detectEnvironment(createMinimalConfig());
const defaultResult = await detectEnvironment(createDefaultConfig());
const fullResult = await detectEnvironment(createComprehensiveConfig());
// Custom configuration
const customConfig: SecurityCheckConfig = {
// Basic Security Checks
checkRooted: true,
checkJailbroken: true,
checkEmulator: true,
checkSimulator: true,
checkHooked: true,
checkTampered: true,
// Advanced Security Checks
checkProxy: true,
checkNetworkMonitoring: false, // Skip network monitoring
// Performance Options
includeRootDetails: true,
enableFastMode: false,
enableDetailedChecks: true,
};
const customResult = await detectEnvironment(customConfig);
`
The useSecurityChecker hook accepts the following options:
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| config | SecurityCheckConfig | undefined | Configuration for security checks |interval
| | number | 5000 | Interval in milliseconds for periodic checks |checkOnBackground
| | boolean | true | Check when app goes to background |checkOnForeground
| | boolean | true | Check when app comes to foreground |startImmediately
| | boolean | true | Start monitoring immediately |enableContinuousMonitoring
| | boolean | true | Enable periodic checks |
`js`
const config: SecurityCheckConfig = {
// Basic Security Checks
checkWorkProfile: boolean, // Android work profile detection
checkCloned: boolean, // App cloning detection
checkSecondaryUser: boolean, // Secondary user detection
checkRooted: boolean, // Root detection (Android)
checkJailbroken: boolean, // Jailbreak detection (iOS)
checkEmulator: boolean, // Emulator detection
checkSimulator: boolean, // Simulator detection (iOS)
checkDebuggable: boolean, // Debuggable app detection
checkDeveloperMode: boolean, // Developer mode detection
checkUSBDebugging: boolean, // USB debugging detection
checkVPN: boolean, // VPN detection
checkHooked: boolean, // Hook detection
checkTampered: boolean, // Tamper detection
checkVirtualSpace: boolean, // Virtual space detection
checkSuspiciousApps: boolean, // Suspicious apps detection
checkSandbox: boolean, // Sandbox detection
// Advanced Security Checks
checkDebuggerAttached: boolean, // Debugger attachment detection
checkRunningInBackground: boolean, // Background execution detection
checkProxy: boolean, // Proxy detection
checkNetworkMonitoring: boolean, // Network monitoring detection
checkBiometricCompromised: boolean, // Biometric security detection
checkPerformanceAnomaly: boolean, // Performance anomaly detection
checkRuntimeIntegrity: boolean, // Runtime integrity detection
// Root Detection Details
includeRootDetails: boolean, // Include detailed root detection info
// Performance Options
enableFastMode: boolean, // Skip expensive checks
enableDetailedChecks: boolean, // Include detailed analysis
};
Performs comprehensive security checks and returns a promise with the results.
#### SecurityCheckResult Interface
`typescript
interface SecurityCheckResult {
// Android specific checks
isWorkProfile?: boolean; // Device is in work profile
isCloned?: boolean; // App is running in cloned environment
isSecondaryUser?: boolean; // Running as secondary user
isRooted?: boolean; // Device has root access
isEmulator?: boolean; // Running on emulator
isDebuggable?: boolean; // App is debuggable
isDeveloperModeOn?: boolean; // Developer mode is enabled
isUSBDebuggingOn?: boolean; // USB debugging is enabled
isVPNActive?: boolean; // VPN connection is active
isHooked?: boolean; // App is hooked by frameworks
isTampered?: boolean; // App has been tampered with
isRunningInVirtualSpace?: boolean; // Running in virtual space
hasSuspiciousApps?: boolean; // Suspicious apps detected
isRunningInSandbox?: boolean; // Running in sandbox environment
// iOS specific checks
isJailbroken?: boolean; // Device is jailbroken
isDebugging?: boolean; // Debugger is attached
isRunningInSimulator?: boolean; // Running on iOS Simulator
// Root detection details (Android only)
rootDetectionDetails?: RootDetectionDetails;
// Overall security status
isInsecureEnvironment: boolean; // True if any security threat is detected
}
interface RootDetectionDetails {
rootBeerIsRooted: boolean; // RootBeer primary detection
rootBeerIsRootedWithoutBusyBoxCheck: boolean; // RootBeer without BusyBox check
detectRootManagementApps: boolean; // Root management apps detected
detectPotentiallyDangerousApps: boolean; // Potentially dangerous apps detected
detectTestKeys: boolean; // Test keys detected
checkForBusyBoxBinary: boolean; // BusyBox binary found
checkForSuBinary: boolean; // SU binary found
checkSuExists: boolean; // SU command exists
checkForRWPaths: boolean; // Read-write paths detected
checkForDangerousProps: boolean; // Dangerous properties detected
checkForMagiskBinary: boolean; // Magisk binary found
customRootAppsCheck: boolean; // Custom root apps check
customRootFilesCheck: boolean; // Custom root files check
customDangerousPropsCheck: boolean; // Custom dangerous props check
customSuBinaryCheck: boolean; // Custom SU binary check
customRootNativeCheck: boolean; // Custom root native check
customBusyBoxCheck: boolean; // Custom BusyBox check
}
`
The package includes a comprehensive example app that demonstrates all security features. To run it:
`sh``
cd example
npm installFor iOS
npx react-native run-iosFor Android
npx react-native run-android
- This library provides detection capabilities but cannot prevent all attacks
- Some detection methods may have false positives
- Consider implementing additional security measures based on your app's requirements
- Regularly update the library to get the latest detection methods
- Development workflow
- Sending a pull request
- Code of conduct
MIT
---
Made with create-react-native-library