Skip to content
Leaked secrets Write-up Beginner

Let’s know How I have explored the buried secrets in React Native application

The React Native application contained hard-coded credentials for a third-party service (Dialogflow) inside its JavaScript bundle. An attacker who extracted the bundle could read those credentials and potentially use the service.

secureITmania Follow

Published on secureitmania.medium.com

#### secureITmania

secureITmania, on secureitmania.medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

React Native is a mobile application framework used to build Android and iOS applications by combining React with native platform capabilities. Its growing popularity means that a large share of the logic in such apps is not compiled into Java or Kotlin bytecode at all: it ships as JavaScript inside the APK.

This write-up describes a hard-coded credentials issue found in a React Native application by a different approach from the classic Android reverse engineering methodology. During initial recon the researcher observed that the application used the Dialogflow service, and that observation guided the search of the bundled JavaScript.

Setup

The tools used are the standard Android reverse engineering set, but only the first part is needed for a React Native app:

  • apktool and dex2jar, followed by analysis in JD-GUI, for the traditional route. This remains useful if the application contains native code that you want to analyse.
  • A zip extraction of the APK, which is enough to reach the React Native JavaScript.
  • Google Chrome with its Developer Tools, used to load and search the bundle.

The report does not name the application, the program or any version numbers.

Finding it

Most of the time the core logic of a React Native application lives in the JavaScript, and that JavaScript can be obtained without dex2jar at all. The first question is therefore whether the target was built on React Native. If it was, the bundle is sitting in the APK in minified form and can be read directly.

The lead that made the search productive came from recon: the application was seen using Dialogflow. Knowing the third-party service in use turns a blind keyword hunt into a targeted pattern search for that service's configuration.

Exploitation

Step 1: confirm the framework and extract the bundle

Rename the APK with a zip extension and extract it to a new folder:

Bash
cp com.example.apk example-apk.zipunzip -qq example-apk.zip -d ReactNative

Browse to the newly created ReactNative folder and find the assets folder. Inside it there should be index.android.bundle, which contains all of the React JavaScript in a minified format.

Step 2: load the bundle in a browser

Create a file named index.html in the same directory containing:

HTML
<script src="index.android.bundle"></script>

Open index.html in Google Chrome, open the Developer Toolbar (Command+Option+J on OS X or Control+Shift+J on Windows) and click on Sources. The JavaScript file appears, split into the folders and files that make up the main bundle.

If a file called index.android.bundle.map is present, the source can be analysed in an unminified format: map files contain the source mapping that allows minified identifiers to be mapped back.

Step 3: search for sensitive credentials and endpoints

Identify sensitive keywords and analyse the JavaScript with them. A pattern popular in React Native applications is the use of third-party services such as Firebase, AWS S3 service endpoints and private keys. Because recon had shown the application using Dialogflow, the search used a pattern related to its configuration, and sensitive hard-coded credentials were found in the JavaScript code.

Image for post
Analysing index.android.bundle in Chrome DevTools From the original on secureitmania.medium.com

The screenshot shows index.android.bundle being analysed in Chrome DevTools.

The report does not reproduce the credential values or the exact search pattern.

Root cause

Secrets were embedded in the React Native JavaScript bundle. Because that bundle ships inside the APK as readable, if minified, JavaScript, anyone who downloads the application can extract it and read the strings. The bundle is minified, and the traditional decompilation step is not required to reach it.

Impact

The credentials found were hard-coded secrets belonging to a third-party service configuration. The report does not state which accounts or data the credentials gave access to, nor any bounty or severity.

Fix

The report gives no remediation details. Its closing guidance is that sensitive credentials and API endpoints can often be extracted from React Native applications by analysing the JavaScript, and that applications built with sensitive logic should be protected against code theft.

Variants to test

  1. Extract any React Native APK and check assets/index.android.bundle. A positive result is the bundle being present and readable as JavaScript.
  2. Look for index.android.bundle.map next to the bundle. A positive result is an unminified source tree in DevTools, which makes the search far quicker.
  3. Grep the bundle for third-party service configuration patterns, starting from services identified during recon (Firebase, AWS S3 endpoints, Dialogflow and similar). A positive result is a literal key, token or endpoint embedded in the code.
  4. Search for private keys and generic credential keywords in the same bundle. A positive result is key material or credential strings in plain text.
  5. Where the app has native code, run the classic apktool and dex2jar route as well. A positive result is secrets that the JavaScript search missed.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

What happened, in plain words

A security researcher was looking at an Android app and found a hard-coded credentials issue. The app was made with a tool called React Native, which lets developers write one set of instructions in a language called JavaScript and have it run on both Android and iOS phones. The mistake was that secret login details for a third-party service were written directly into the app's code, in plain text.

Normally, when people want to look inside an Android app, they use a set of tools that turn the app's compiled code back into something readable. That process is called reverse engineering. For React Native apps, though, there is a much simpler route: the important logic is not compiled at all. It sits inside the app as a JavaScript file, and you can read it with nothing more than a zip extractor and a web browser.

This article walks through that simpler route from the beginning. It assumes you can use a computer and a browser and nothing else. Every tool and term is explained as it comes up.

Background: what React Native is and why it matters here

React Native is a mobile application framework. A framework is a collection of ready-made building blocks that developers use to assemble an app, so they do not have to write every piece from scratch. React Native lets a developer write the app's behaviour once in JavaScript, and the framework translates that into something Android and iOS phones can display and run.

Because of this, a large part of a React Native app's logic is not turned into the compiled code that Android normally uses (Java or Kotlin). Instead, it travels inside the app package as a JavaScript file. That is the key fact for this story: the logic is shipped in a form that a person can read, not in a form that only a machine can run.

The old-fashioned way of looking inside an Android app

The traditional approach to Android reverse engineering uses a few well-known tools:

  • apktool and dex2jar: these unpack an Android app package and convert its compiled code into a form that can be read.
  • JD-GUI: a viewer that displays that converted code in a readable way.

This route is still useful if the app contains native code, meaning code written specifically for the phone's processor rather than in JavaScript. But for a React Native app, most of the interesting logic is in the JavaScript, and that JavaScript can be obtained without any of these tools.

The reverse engineering process, step by step

Step 1: confirm the app was built with React Native

Before doing anything else, you need to know whether the app you are looking at was built with React Native. If it was, the JavaScript bundle is sitting inside the app package, waiting to be read.

An Android app is distributed as a single file with the extension .apk. An APK is really just a zip archive, the same kind of compressed folder you might have downloaded before. So the trick is to rename it so that your computer treats it as a zip, then extract it.

The command used was:

Bash
cp com.example.apk example-apk.zipunzip -qq example-apk.zip -d ReactNative

Line by line:

  • cp com.example.apk example-apk.zip makes a copy of the app file and gives the copy a .zip extension. The original is left untouched. com.example.apk is a placeholder name for the app file; the real app is not named in the report.
  • unzip -qq example-apk.zip -d ReactNative extracts the contents of that zip into a new folder called ReactNative. The -qq part tells the unzip tool to stay quiet and not print a long list of every file it extracts.

After running this, you browse into the new ReactNative folder and look for a folder called assets. Inside assets there should be a file called index.android.bundle. That file contains all of the app's React JavaScript, in a minified format. Minified means the code has been squashed down: spaces and line breaks removed, and long names shortened to short ones, to make the file smaller. It is harder to read than normal code, but it is still plain text and still contains every literal value the developer wrote, including any secrets.

Step 2: load the bundle in a browser

A JavaScript file on its own is just text. To search through it comfortably, you want a tool that understands JavaScript and can display it in an organised way. A web browser can do that.

The researcher created a file called index.html in the same folder as the bundle, containing this single line:

HTML
<script src="index.android.bundle"></script>

Line by line:

  • <script starts an HTML tag that tells the browser to load and run a piece of JavaScript.
  • src="index.android.bundle" says where that JavaScript lives: a file in the same folder, named index.android.bundle.
  • ></script> closes the tag.

In plain terms, this tiny web page says to the browser: "load the app's JavaScript file." When you open index.html in Google Chrome, the browser reads the bundle and makes it available in its developer tools.

Next, open the Developer Toolbar. This is a panel built into Chrome for inspecting web pages. You open it with Command+Option+J on a Mac (OS X) or Control+Shift+J on Windows. Then click on the Sources tab. The Sources panel lists every file the page has loaded. You should see the JavaScript file there, split up into folders and files that make up the main bundle. That split view is the browser's way of presenting the bundle's internal structure, and it makes searching much easier.

One extra detail is worth knowing. If you also find a file called index.android.bundle.map next to the bundle, you are in luck. A map file (source map) records how the minified, squashed code corresponds to the original, readable code. With it, the browser can show you the source in its original, unminified form, which makes the code far easier to follow. The report notes this as a possibility, not something that was present in this case.

Step 3: search for sensitive credentials and endpoints

Now you have the app's JavaScript open in a tool that can search it. The goal is to find sensitive credentials and endpoints.

  • A credential is anything that proves identity: a username and password, an API key, a token. If someone else gets it, they can act as the app.
  • An endpoint is the address of a service the app talks to, usually a URL. Knowing an endpoint tells you where the app sends data and what it expects back.

A common pattern in React Native apps is that they rely on third-party services: Firebase (a Google service for app backends), AWS S3 (Amazon's file storage service), and others. Each of these services needs configuration, and that configuration often includes a key or secret. Developers sometimes paste those values straight into the code, which means they end up in the bundle.

During the researcher's initial recon (short for reconnaissance, the early phase of gathering information about a target before attacking it), they noticed that this particular app used Dialogflow. Dialogflow is a Google service for building conversational interfaces, such as chatbots. Knowing which service the app used turned a blind keyword hunt into a targeted search: instead of guessing random words, the researcher searched for patterns related to Dialogflow's configuration.

That search paid off. The researcher found sensitive hard-coded credentials in the JavaScript code. Hard-coded means the value was written directly into the source by the developer, rather than being fetched securely at runtime or stored outside the code.

Image for post
Analysing index.android.bundle in Chrome DevTools From the original on secureitmania.medium.com

The screenshot shows index.android.bundle being analysed in Chrome DevTools.

The report does not reproduce the credential values or the exact search pattern used.

Why this happens

When an app needs a secret to work, that secret has to be available to the app when it runs. The mistake is putting it in the JavaScript bundle. Because the bundle ships inside the APK as readable, if minified, JavaScript, anyone who downloads the app can extract it and read the strings. The bundle is minified, and you do not even need the traditional decompilation tools to reach it.

What the impact was

The credentials found were hard-coded secrets belonging to a third-party service configuration. The report does not state which accounts or data the credentials gave access to, nor any bounty or severity.

How to fix it

The report gives no remediation details. Its closing guidance is that sensitive credentials and API endpoints can often be extracted from React Native applications by analysing the JavaScript, and that applications built with sensitive logic should be protected against code theft.

Variants to test

If you want to try this yourself on other apps, here is a checklist of things to look for. Each item describes what to do and what a positive result looks like.

  1. Extract any React Native APK and check assets/index.android.bundle. A positive result is the bundle being present and readable as JavaScript.
  2. Look for index.android.bundle.map next to the bundle. A positive result is an unminified source tree in DevTools, which makes the search far quicker.
  3. Search the bundle for third-party service configuration patterns, starting from services identified during recon (Firebase, AWS S3 endpoints, Dialogflow and similar). A positive result is a literal key, token or endpoint embedded in the code.
  4. Search for private keys and generic credential keywords in the same bundle. A positive result is key material or credential strings in plain text.
  5. Where the app has native code, run the classic apktool and dex2jar route as well. A positive result is secrets that the JavaScript search missed.

Glossary

  • APK: the file format Android apps are distributed in; it is a zip archive containing the app's code, resources and assets.
  • API: an interface that lets one piece of software talk to another; a set of rules for requesting and receiving data.
  • apktool: a tool that unpacks and repackages Android APK files.
  • AWS S3: Amazon's cloud file storage service, often used by apps to store files.
  • Bundle: here, the single JavaScript file (index.android.bundle) that contains a React Native app's logic.
  • Chrome DevTools: the inspection panel built into Google Chrome, opened with a keyboard shortcut, used to view and search the files a page loads.
  • Credential: any value that proves identity, such as a password, API key or token.
  • dex2jar: a tool that converts Android's compiled code into a form that Java analysis tools can read.
  • Dialogflow: a Google service for building conversational interfaces such as chatbots.
  • Endpoint: the address (usually a URL) of a service that an app communicates with.
  • Firebase: a Google platform for app backends, providing services such as databases and authentication.
  • Framework: a collection of ready-made building blocks developers use to assemble software.
  • Hard-coded: written directly into the source code as a fixed value, rather than fetched or configured at runtime.
  • JD-GUI: a viewer that displays decompiled Java code in a readable form.
  • JavaScript: the programming language used for logic in web pages and in React Native apps.
  • Minified: code with spaces, line breaks and long names removed or shortened to reduce file size; still plain text, still containing literal values.
  • Native code: code written specifically for the phone's processor, as opposed to JavaScript.
  • React Native: a mobile application framework for building Android and iOS apps using JavaScript and React.
  • Recon (reconnaissance): the early information-gathering phase of a security assessment.
  • Reverse engineering: the process of taking apart a finished program to understand how it works.
  • Token: a value, often a string, that a service issues and that an app presents to prove it is authorised.
  • Zip archive: a compressed folder containing multiple files, identified by the .zip extension.

More by secureITmania

View all

3 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Leaked secrets and credentials

The lesson behind this report.

Keys, tokens or passwords left in public code, apps, logs or responses, that grant real access.