React Native — Detecting device is rooted or jailbroken

Detecting whether an Android device is rooted or an iOS device is jailbroken is a security-sensitive task, and it’s important to note that no method is foolproof. Determining the root or jailbreak status can be challenging due to various techniques used by users to hide such modifications. However, there are libraries available that attempt to check for root or jailbreak status.

For React Native, you can use the following libraries:

1. react-native-root-detection:

npm install react-native-root-detection
import RootDetection from 'react-native-root-detection';

RootDetection.isRooted().then(isRooted => {
      console.log(`Is the device rooted or jailbroken? ${isRooted ? 'Yes' : 'No'}`);
});

2. react-native-device-info:

  • GitHub: react-native-device-info
  • While primarily a library for obtaining device information, it includes a method to check whether the device is rooted or jailbroken.

npm install react-native-device-info
import DeviceInfo from 'react-native-device-info';

const isRootedOrJailbroken = DeviceInfo.isEmulatorOrSimulator() || DeviceInfo.isPinOrFingerprintSet();
console.log(`Is the device rooted or jailbroken? ${isRootedOrJailbroken ? 'Yes' : 'No'}`);

Keep in mind that these methods may not be foolproof, and users who are determined to hide root or jailbreak status may find ways to bypass these checks. It’s essential to consider the context in which you are using such checks and understand their limitations. Additionally, relying solely on this type of check for security purposes is not recommended; other security measures should be implemented as well.

To make it 100% foolproof solution

It’s important to note that there is no foolproof solution for detecting whether an Android device is rooted or an iOS device is jailbroken. 

Determining root or jailbreak status is essentially a cat-and-mouse game between developers and users, and users can employ various methods to hide these modifications.

However, you can implement multiple checks and employ security best practices to make it more challenging for users to bypass detection. Here are some strategies:

1. Root/Jailbreak Detection Libraries:

  • Use multiple detection libraries: Combine the use of different root or jailbreak detection libraries to increase the complexity for users attempting to bypass them.

2. Integrity Checks:

  • Implement integrity checks on critical parts of your app. Monitor for changes in the app’s binary or key files.

3. Obfuscation and Anti-Tamper Techniques:

  • Use code obfuscation to make it more difficult for users to understand and modify your code.
  • Implement anti-tamper techniques to detect if the app has been modified.

4. Server-Side Verification:

  • Perform critical operations on the server side rather than the client side. This makes it more challenging for users to manipulate the app’s behavior.

5. Dynamic Analysis Detection:

  • Implement dynamic analysis detection to identify if the app is running in a controlled environment like an emulator.

6. User Behavior Monitoring:

  • Monitor and analyze user behavior for anomalies that might indicate tampering.

7. Regular Updates:

  • Keep your app updated with the latest security measures to address new methods users might employ.

8. Legal and Ethical Considerations:

  • Keep in mind the legal and ethical aspects of trying to detect root or jailbreak status. Always respect user privacy and ensure compliance with relevant laws.

It’s important to recognize that while these measures can increase the difficulty of bypassing root or jailbreak detection, determined users may still find ways to do so. Security is about layers, and a combination of techniques should be employed to create a more resilient defense. Additionally, consider the impact on the user experience, as overly aggressive security measures may lead to user frustration and negative reviews.

You might also like