Strengthening Android App Security: The Upstox Odyssey of Enhancement and Protection

Himanshu Chauhan
Engineering @ Upstox
8 min readMar 22, 2024

Introduction

In today’s era, where mobile applications are integral to our everyday lives, the criticality of stringent app security, particularly for financial dealings, is undeniable. With the pervasive use of smartphones, ensuring the protection of user data against potential threats has become more crucial than ever. This narrative delves into Upstox’s strategic journey to fortify the security of our Android application, aiming to shield our users’ investments with cutting-edge technological defenses.

For developers, the safeguarding of Android applications stands as a paramount concern. A prevalent strategy observed in the industry involves leveraging R8 or ProGuard for app protection. However, the effectiveness of these tools in security terms is frequently overvalued. R8, seamlessly integrated into Android Studio, shares similarities with ProGuard in offering primary functionalities like shrinking and optimization. R8 engages in code shrinking and optimization by discarding unused code and resources, alongside implementing various code alterations. This process not only trims down the application size, facilitating quicker downloads but also enhances the user experience by optimizing performance. Yet, it’s pivotal to recognize that these capabilities primarily target optimization rather than bolstering app security and resilience.

In pursuit of elevating our app’s security to the next level, we embarked on an exploration of diverse methodologies to render our application tamper-resistant and inhibit its operation on rooted devices. Such devices pose a heightened risk as they enable runtime manipulations of the app, uncovering exploits that could potentially divulge sensitive information. This scenario could jeopardize not only the user’s security but also the integrity of the platform at large.

Our commitment to security led us to adopt a multifaceted approach, meticulously crafting a defense strategy that goes beyond conventional optimization tools. By doing so, we aim to establish a robust security framework that diligently protects our user’s financial data and transactions, ensuring peace of mind and fostering trust in our platform. Join us as we continue to navigate through the intricacies of app security, dedicating ourselves to the relentless pursuit of safeguarding our digital ecosystem.

Advancing Security Through Innovation: Upstox’s First Leap in Android App Protection

As we journey deeper into Upstox’s commitment to elevating app security, our first experiment sheds light on the strategic implementation of app signature validation and the encryption of hardcoded strings — a cornerstone in fortifying our defense against unauthorized modifications.

Understanding the Battleground

A primary tactic employed by attackers involves the decompilation of the APK to introduce code changes, followed by recompilation. It’s well understood within the developer community that a legitimate APK is distinguished by a unique signature, bestowed by Google Play upon the submission of a new build (AAB) to their console. Recognizing this, we devised a method to compare this signature at runtime, effectively barring attackers from executing the altered app should any discrepancy in signatures be detected. To further enhance security, we shielded this valid signature key using obfuscation techniques.

Initial Strategies and Insights

Our initial strategy involved straightforward app signature validation at each app launch, conducted locally on the device. For this, we employed a plugin named Enigma to obfuscate the hardcoded valid signature string. However, our exploration revealed a critical vulnerability — though implementing a simple Boolean check to validate the app’s signature was feasible, it proved all too easy for an attacker to negate upon decompiling the APK. Such validation checks, prominently visible within the source code, could be effortlessly bypassed or removed, especially since the app’s entry point could be readily identified through the AndroidManifest.xml file.

Key Takeaways and Forward Steps

This experiment underscored a pivotal lesson: while runtime signature validation holds the potential to thwart attackers from running a modified app, the simplicity of circumventing this check poses a significant challenge. The initial step, therefore, must focus on rendering the AAB/APK build tamper-proof, establishing a robust foundation that prevents any unauthorized code modification. Only upon securing this groundwork can we effectively implement measures to halt app operation based on the device’s state, ensuring a fortified barrier against external threats.

This venture into app security marks the beginning of Upstox’s proactive and multi-layered approach to safeguarding our Android application. By continuously innovating and refining our strategies, we stay committed to providing a secure and trustworthy platform for our users, ensuring their investments and data remain under stringent protection.

Experiment 2: Exploring the Frontier of App Security with Araxn by Digital AI

Delving deeper into Upstox’s quest for unparalleled Android app security, our second experiment involved a proactive assessment of Araxn, a tool by Digital AI renowned for its capabilities in thwarting reverse-engineering attempts. This phase of our journey highlights the challenges and revelations encountered while integrating cutting-edge security measures.

Bridging Knowledge Gaps

Understanding that rendering an app tamper-proof necessitates a profound comprehension of the Android build system, potential exploits, and intricate solutions, we embarked on a proof of concept (POC) with Araxn. This tool not only promised to shield our app from reverse-engineering but also offered real-time alerts on any such attempts post-application on the app’s AAB/APK.

Initial Integration: A Glimpse into Potential

Our initial foray involved collaboration with Digital AI’s technical team, applying their native code protection toolkit directly on our app within a controlled desktop environment. This exploratory phase, spanning a week, yielded promising results, offering a glimpse into the potential enhancements in app security. Encouraged, we proceeded to extend this protection to both native and React code within our remote Continuous Integration (CI) system, operated via Jenkins, aiming to assess feasibility within our actual deployment framework.

Navigating Complexities

The transition to a remote setup unveiled a spectrum of complexities, stretching the integration timeline to three weeks and challenging our expectations. The crux of the integration dilemma lay in the elaborate setup with the remote build system and the initial ineffectiveness of the provided scripts. Resorting to experimental scripts, we navigated through multiple iterations to achieve a semblance of operational harmony.

Weighing the Trade-offs

Despite surmounting the integration hurdles, the resultant build times and app size implications raised significant concerns. A substantial increase in build duration, coupled with a more than 10% surge in app size, starkly contrasted with our ethos of maintaining swift build cycles and lean applications. The prospect of future adaptations to the Android or React build systems further underscored the potential need for continual script updates and exhaustive end-to-end testing.

Reflections and Insights

This exploration into Araxn underscored a critical realization: while the tool’s expansive suite of customization options (including identifier renaming, string encryption, control flow flattening, debug detection, and an in-app firewall) and feature-rich proposition were indisputably appealing, the associated cost and integration complexities posed significant barriers. Our primary security objectives, when juxtaposed with the tool’s offerings, revealed a misalignment of scope and scale. Additionally, the tool’s lack of out-of-the-box compatibility with our Hermes configuration presented an additional layer of challenge.

Moving Forward

The journey through Experiment 2 reaffirmed our dedication to achieving a secure, robust, and user-centric Android application. While Araxn presented a promising avenue, the complexities and trade-offs encountered guided us back to the drawing board, seeking solutions that align more closely with our specific needs and operational dynamics. As we continue our exploration of security enhancements, these experiences enrich our understanding and sharpen our focus on solutions that not only fortify our defenses but also align with our efficiency and scalability objectives.

Experiment 3: Leveraging Automatic Integrity Checks and Root Detection for Enhanced App Security

In the continuous quest to solidify the security of our Android application, our exploration led us to a pivotal discovery within the Play Console itself — the Automatic App Integrity Check feature. This segment of our journey delves into the nuances of employing built-in platform features alongside external libraries to elevate our app’s defense mechanisms.

Playstore’s Automatic Integrity Protection

The Play Console’s Automatic App Integrity Check emerged as a beacon of simplicity in the complex landscape of app security. This feature, when activated, repackages the AAB/APK with additional code and assets designed to thwart tampering efforts. Enabling it required merely flipping a switch, ensuring that every uploaded app version would benefit from an added layer of security.

Addressing Rooted Device Concerns

However, a critical aspect of app protection remained — preventing execution on rooted devices. Our solution? Implementing root detection directly within our source code, rendering it impervious to removal through decompilation. For this purpose, we integrated the RootBeer library, a tool adept at identifying root permissions on devices. With RootBeer, we could gracefully advise users to operate the app on non-rooted devices, enhancing overall security without compromising usability.

Navigating the Caveats

Despite its apparent benefits, the integrity check feature isn’t without its challenges. Notably, the application size saw an approximate increase of 9 MB, a trade-off for the added security layer. Additionally, the feature’s underpromotion within the developer community has led to a slower adoption rate, potentially obscuring insights into related issues or optimizations.

Reflections and Future Directions

The exploration of the Automatic App Integrity Check feature underscored a critical insight — powerful security enhancements could sometimes lie within the tools and platforms we use daily. This experiment reinforced the value of a multi-faceted approach to app security, combining platform-specific features with external libraries to create a robust defense system. While the increase in app size presents a consideration for our development team, the overarching benefits of unauthorized modification prevention, piracy deterrence, and ensuring users receive official updates affirm the merit of this path.

As we advance in our journey to fortify the Upstox app, these experiments serve as milestones, each offering unique lessons and guiding our strategies towards a secure, efficient, and user-centric application. The exploration of built-in platform features, coupled with targeted external solutions, remains a cornerstone of our approach to navigating the ever-evolving landscape of app security.

Conclusion: Charting the Path to Unassailable Mobile App Security

In the digital arena where mobile applications play a pivotal role in our daily transactions and interactions, ensuring these applications are tamper-proof isn’t just a preference — it’s a necessity. Protecting user data, upholding the integrity of applications, adhering to stringent regulations, and preserving the trust and credibility in the digital marketplace are paramount. Moreover, integrating root detection mechanisms within apps not only amplifies security measures but also plays a crucial role in protecting digital rights, ensuring regulatory compliance, bolstering app stability, and securing revenue streams. These measures collectively foster a more secure and reliable app ecosystem for both users and developers alike.

Our voyage through the landscape of app security has imparted valuable insights. The market is teeming with tools and technologies aimed at shielding apps from the prying eyes and malicious intents of nefarious users. However, the key takeaway from our explorations is the importance of tailoring our security strategy to the specific needs and vulnerabilities of our app. Before settling on a security solution, it’s critical to assess the level of protection required and anticipate the caliber of attackers likely to target the app. Our journey led us to a solution that, while simple, required us to venture into uncharted territories — exploring new and uncommon options that ultimately proved to be both time and cost-effective.

Our reliance on the solution provided by the Google Play team underscores our confidence in its efficacy and robustness. It reassures us that not only is our current security posture solid, but we can also count on continuous enhancements and support in the future. This journey has been a testament to the power of innovation, the importance of adaptability, and the value of seeking solutions that align closely with our security needs and goals. As we move forward, these learnings will continue to guide our efforts in creating a safer, more trustworthy digital environment for our users and setting new benchmarks in mobile app security.

--

--