Skip to content
Tutorials Center
My learning

Topics

Lesson 26 of 53 ยท Web Application Security

Mobile App Security and Android Testing

Learn the mobile threat model, secure storage and permissions, how Android app testing is set up in a lab (emulator, proxy, static and dynamic analysis), and how SAST and DAST fit together.

A mobile app is a program that you hand to strangers. It runs on devices you do not control, can be unpacked, inspected and modified by its user, and usually talks to a backend over a network the user may also control. Mobile security therefore combines three areas: the app itself (storage, permissions, code), the device and platform (operating system protections, rooting or jailbreaking) and the backend (APIs, authentication). The backend is often the real target, and the mobile app is just a convenient client for finding it.

Test only apps you own, apps you built for the engagement or apps whose owner has authorized testing in writing. Decompiling, modifying or redistributing someone else's app can breach licenses and law, and intercepting traffic from an app you do not control may expose other people's data. Use test accounts, an emulator and a lab backend. The code in this lesson is a set of simulations.

The mobile threat model

Assume the attacker can do the following on their own device: read the app's files, view its network traffic with a proxy, unpack and read the app package, run it under a debugger and modify it. This is why secrets inside an app (API keys, hard-coded passwords, "private" endpoints) are never secret. Apps can add protections such as root and jailbreak detection, certificate pinning and obfuscation, which raise the effort but never make a client trustworthy. The server must enforce every rule.

The OWASP Mobile Top 10 and the Mobile Application Security Verification Standard (MASVS) list the recurring problems. In plain words: improper credential use, weak supply chain controls, insecure authentication and authorization, insufficient validation of input and output, insecure communication, inadequate privacy controls, insufficient binary protections, security misconfiguration, insecure data storage and weak cryptography.

Secure storage

Where a mobile app keeps data decides who can read it.

  • Shared preferences, plain files, local databases (such as SQLite), logs and the clipboard are readable by anyone with access to the device storage, a backup or a rooted device. Tokens and personal data stored in plain text are a classic finding.
  • Secure storage facilities: on Android, the Keystore system holds keys in hardware-backed storage and encrypted preference libraries build on it; on iOS, the Keychain. Store secrets there, and keep the minimum on the device.
  • Backups. App data can be copied by device backups unless excluded. Sensitive apps should opt out.
  • Logs and screenshots. Do not log tokens; mark sensitive screens to prevent screenshots and app-switcher previews.
  • Short-lived tokens limit the damage if one is stolen, and the server can revoke them.

Permissions and components

Android apps declare permissions in a manifest (camera, location, contacts, storage). Requesting more than needed is both a privacy problem and a larger attack surface. Components can be exported to other apps: an exported activity, broadcast receiver, service or content provider that does not check who calls it can be abused by another app on the device to read data or trigger actions. Review the manifest for exported components, debug flags (debuggable), permissive backup settings and cleartext traffic permission. Custom URL schemes and deep links should treat their input as untrusted.

Setting up Android testing in a lab

A typical authorized setup:

  1. An emulator or a spare test device, not your personal phone. Emulators are convenient and snapshot-friendly. Some protections behave differently on them.
  2. A proxy on your computer with its CA certificate installed on the device. Modern Android versions distrust user-installed certificates for apps by default unless the app opts in, so test builds are often compiled with a debug network configuration that allows it. For a production build you control, use a test build instead of tampering with the release. If the app uses certificate pinning, intercepting needs additional work, which is itself a sign the pin works as designed.
  3. Android Debug Bridge (adb) to install builds, read logs, open a shell and pull files from the app's data directory on a test device.
  4. Analysis tools: a decompiler for the app's bytecode and a manifest viewer for static work; an instrumentation framework for runtime observation on a rooted test device.

Read-only examples:

TEXT
adb devices                            # list connected emulators and devices
adb install app-debug.apk              # install a test build
adb logcat | grep -i token             # are secrets written to the log?
adb shell run-as com.example.lab ls files/   # look at a debuggable app's private files

SAST and DAST

Two broad families of automated analysis complement manual testing.

  • SAST (static application security testing) analyzes source code or the compiled package without running it. It finds hard-coded secrets, dangerous API use, missing checks and misconfigured manifests early, in the developer's pipeline. It can produce false positives and cannot see runtime behavior such as server responses.
  • DAST (dynamic application security testing) exercises the running app and backend like an attacker would: sending unexpected input, watching responses and traffic. It finds what actually happens, including backend issues, but only for code paths that were exercised, and later in the cycle.
  • IAST and runtime protection instrument the running app for more precise findings, and manual review covers logic and design problems tools cannot judge (compare business logic flaws).

The best program uses SAST on every build, DAST on a test environment, and manual testing for the risky areas.

A mini static check on a fake manifest

The stand-in below models an Android manifest and a few files as plain data and runs the sort of checks a SAST tool performs: debug flags, cleartext traffic, exported components without permission, dangerous permissions and hard-coded secrets.

Node.js Run SAST-style checks on invented app data

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Each finding is a lead to verify. A static tool does not know whether the exported receiver really lets another app move money; a tester would confirm that on a test device.

Storage review stand-in

The second stand-in models the contents of an app's private data directory and flags sensitive values that are stored in plain text. This is the same review a tester performs after pulling the files from a test device.

Node.js Find plaintext secrets in app storage

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The fixes are structural: keep tokens in the Keystore-backed storage, never log them, hash passwords on the server with a modern algorithm and a salt (Password Security) and do not cache more than you need.

Testing the backend through the app

Because the server is the real security boundary, a great deal of mobile testing is API testing: capture the app's requests in the proxy, then test authentication, authorization (can user A request user B's resources?) and input handling on every endpoint. See API Security.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why should an API key hard-coded in a mobile app be considered public?

    Mobile packages can be decompiled and inspected, so embedded secrets are extractable. Keep secrets on the server.
  2. 2. Which Android manifest finding is most concerning?

    Exported components can be called by other apps. Without access checks they may leak data or trigger actions.
  3. 3. What is the main difference between SAST and DAST?

    Static analysis reads code early in the pipeline; dynamic analysis attacks a running instance. They find different problems.
  4. 4. Where should authentication tokens be stored on Android?

    Hardware-backed secure storage protects keys and tokens better than plain files, and short lifetimes limit theft damage.

Summary

  • Mobile apps run on devices the attacker controls, so anything inside the app can be read and altered, and the server must enforce the rules.
  • Review storage (prefs, databases, logs, backups), permissions and exported components, debug flags and cleartext traffic permissions.
  • A lab uses an emulator or test device, a proxy with the CA installed, adb and static and dynamic analysis tools; pinning is a defense, not a bug.
  • SAST analyzes code or packages early; DAST attacks the running app; manual testing covers logic.
  • Much of mobile testing is really backend API testing.

Next: Network Attacks and How to Defend Against Them