React Native popularity and adoption is ticking up every day, and it is used to build many enterprise applications. As it is gaining more traction, more vulnerabilities are being discovered and reported. This means that it is crucial to keep the security of React Native apps in mind while building them. Because of its open-source background, RN apps are more prone to security vulnerabilities. This means that more vigilance is needed to keep them secure.
Since most of the logic for React Native apps is written in JS, the coverage or threat area is much larger than that of native apps. So, in essence, we have to ensure the security of both the native code and the JS code. Just like any other frontend app, the code of the app is shipped to devices for execution, which makes it inherently vulnerable to getting tampered with.
This article will look at some of the most common security threats for React Native apps and some of the tools and techniques that can be used to secure against them.
Tools & TricksLet’s look at some super valuable tools and techniques to make your React Native apps more secure. We will cover the areas of network security, data security, static analysis, dependency security, platform security, and more.
Secure Network Communication – SSL PinningAs much as 35% of attacks in 2019 were related to attempts at exploitation using Man in the Middle attacks. For mobile apps communicating with servers, it is necessary to ensure that communication is secure and not tampered with. SSL pinning is a technique that allows you to verify the identity of the server you are communicating with, helping you avoid MITM attacks.
Apps using HTTPS depend on CA and DNS to verify the server’s identity. A malicious actor can bypass this by setting up an unsafe certificate on the client’s devices and making all communication between the client and the server insecure.
SSL pinning allows you to verify the server’s identity by verifying the server’s certificate; this is done by verifying the server’s certificate fingerprint. SSL pinning will ensure that the communication is secure and has not been tampered with.
Here are a couple of tools for SSL pinning:
fetch with import {fetch} from 'react-native-ssl-pinning'. It also supports multipart forms. Important note: you have to implement error handling for certificate expiry and might require an app update to update certificates.fetch method.Securing Stored DataToday’s apps rely not only on network data, they also store data locally on the device. This data can be sensitive and should be protected. Another critical aspect of security is to ensure that all data stored on the device is secure; this includes data stored in the app’s local storage, database, cache, etc. It is crucial to ensure that the data stored on the device is not accessible to other apps or users.
Fortunately, iOS and Android provide tools to secure data stored on devices using Keychain and Keystore, respectively. Here are some of the RN wrappers for these tools:
However, it is essential to note that these tools are not a silver bullet. They are not a replacement for proper data encryption. They are just a way to secure data stored on the device. For an added security layer; It is better to encrypt data before storing it on the device. Or better yet, don’t store data on the device in the first place.
Obfuscation of JS CodeObfuscation is a technique that makes the code harder to read and understand. Obfuscation makes it harder for attackers to understand code and exploit it. For React Native apps, obfuscation of JS code is more important than obfuscation of native code, as most of the app logic resides in JS. General obfuscation of JS code done by default modifiers or Hermes conversion of JS to bytecode is not enough. It is essential to use a tool that can obfuscate the code in a way that is harder to understand and exploit.
Here are some of the tools for obfuscation:
Protection from SQL InjectionSQL injection is a code injection technique that can destroy your database. It is also one of the most common web hacking techniques. Be it the apps using the local database or API calls to remote servers, SQL injection is a threat to both. It is essential to protect your app from SQL injection attacks. All user input should be appropriately validated and sanitized before being used outside any UI scope. Sanitization will ensure that the user input is not malicious for the app.
Here are some tools for protection from SQL injection attacks:
Here is a more detailed guide on input validation to protect your app from SQL injection.
Segregation of Authenticated & Public PartsIn most applications, some parts are accessible to everyone, and components are accessible only to authenticated users or users with a specific role. It is essential to keep these parts of the application separate. Segregation will help you to keep your application secure. For React Native apps, this can mostly be done at the Javascript level with multi routers and multi bundles.
Static Application Security Testing (SAST)Static Application Security Testing (SAST) is a type of application security testing that analyzes application source code, byte code, and binaries for software vulnerabilities. SAST tools analyze an application without actually running it, and can find vulnerabilities that are difficult to see with dynamic testing. SAST tools are also high-speed and can scan code in a CI/CD pipeline.
Here are some of popular tools for SAST:
Checking Dependencies for VulnerabilitiesUsually, React Native apps use a lot of third-party libraries. It is essential to regularly check these libraries for vulnerabilities. Relying on a library that has a vulnerability can be a security risk. To keep our apps secure, we should regularly check our dependencies for vulnerabilities. It is important to make a dependency check part of the CI/CD pipeline for every PR or commit, so that you can be sure that the app is not using any vulnerable libraries.
Here are some tools that can help you check your dependencies for vulnerabilities:
Jailbreak/Rooted Device DetectionJailbroken or Rooted devices, as well as emulators, sometimes bypass security measures provided by the OS. Attackers can use such devices to access sensitive data and perform malicious actions. It is essential to detect jailbroken and rooted devices and prevent them from accessing your app.
Here is a good tool to detect jailbroken and rooted devices:
Checking for App TamperingApp tampering can be done by modifying the app binary or by modifying the app data. It is crucial to detect app tampering and prevent the app from running if it has been tampered with. This is especially important for apps handling sensitive user data or financial transactions, as it must be ensured that all transactions are triggered by a genuine app running on a genuine device.
Here are some of the tools that can be used to detect app tampering:
Getting Deep-Linking RightDeep-linking is a way to open a specific screen in your app from a URL. It is essential to get deep-linking right in order to prevent phishing attacks. It is crucial to validate the URL before opening the screen. It is also necessary to make sure that private URLs are not accessible to everyone and, above all, that URLs are pruned before the app processes them.
For apps using third-party libraries with deep linking, it is vital to ensure that the libraries are not vulnerable to phishing attacks.
Platform Security (Android/iOS)React Native apps work on both Android and iOS, so it is vital to keep the security of both platforms in mind while building your app. Any tools or techniques available to secure native apps are equally relevant to React Native apps.
Here are some Guardsquare tools to secure your app on both platforms:
App Distribution & SigningIt’s also essential to ensure that the application is signed correctly and distributed through official channels to prevent malicious actors from distributing tampered versions of the application. For large-scale apps developed by multiple teams, it is important to have a proper process in place to ensure that the application is properly signed and distributed. CI/CD pipelines should be used to automate signing and distribution of the application.
Bring Security to CI/CDIn addition to these security considerations, it’s important to keep in mind the best practices for securing a CI/CD pipeline, such as implementing secure authentication and access controls and regularly monitoring for and addressing any security threats or vulnerabilities. Here are some security actions that should be implemented in your CI/CD pipeline:
For every PR before merging:* SAST checks * Checking for vulnerable dependencies * Ensure that storage is not used without encryption * Running automated tests to verify that authenticated parts of the app are accessible only with authentication
For release builds:* Restrict access to prod SSL certs by injecting them into the app at build time * Checking for deep-linking vulnerabilities before releasing the app * Signing the app with release certificates from the pipeline to prevent them from being leaked * Testing the hardening of release builds on jailbroken and rooted devices before releasing the app
ConclusionReact Native is an excellent framework for building cross-platform apps, but it is essential to keep security in mind. Whether you’re working with financial or personal data, it is crucial to keep your app secure. Security is an ongoing marathon, and we must keep ourselves up-to-date with the latest security threats and vulnerabilities.
The post Ready to Release? Securing Your React Native Apps appeared first on Semaphore.