Production-grade guide to mobile app security testing covering architecture patterns, implementation strategies, testing approaches, and operational best practices for enterprise engineering teams.
Mobile App Security Testing is the process of validating the security of native and hybrid mobile applications across the development lifecycle, from code integration to production deployment. It matters most during CI/CD pipeline execution, after a new feature branch is merged, when releasing a new app version, or in response to a critical security alert. It ensures that authentication, data storage, network communication, and runtime behavior meet defined security requirements, catching vulnerabilities before they reach users.
Integrate mobile app security testing into the CI pipeline to enforce security gates. Use git to trigger builds, then run scanning tools via curl, docker, and jq to validate artifacts.
A typical mobile CI pipeline starts with a ci.yml file in .github/workflows/:
name: Mobile Security Scan
on: [push, pull_request]
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build App
run: |
cd ios && xcodebuild -scheme MyApp -configuration Release -archivePath build/MyApp.xcarchive
cd ../android && ./gradlew assembleRelease
- name: Run Mobile Security Tests
run: |
docker run --rm -v $(pwd):/app \
-v $(pwd)/artifacts:/artifacts \
-w /app \
aquasec/trivy:latest \
--exit-code 1 \
--severity HIGH,CRITICAL \
--ignore-unfixed \
--input-dir ./artifacts \
--output ./reports/trivy-results.json
Trivy scans the app binaries, dependencies, and configuration files. The --input-dir flag scans both iOS .ipa and Android .apk artifacts. The --exit-code 1 ensures the pipeline fails on any high or critical vulnerability. Trivy outputs JSON results that are consumed by subsequent steps.
Before testing, verify that the app artifact is correctly built and signed.
For iOS, check that the .ipa file contains the expected Info.plist and embedded.mobileprovision:
unzip -l MyApp.ipa | grep -E "(Info.plist|embedded.mobileprovision)"
For Android, extract the APK and validate the AndroidManifest.xml:
unzip -p MyApp.apk AndroidManifest.xml | xmllint --format - | grep -A 5 -B 2 "package=\"com.example.myapp\""
A missing or incorrectly signed embedded.mobileprovision file causes the app to fail on Apple’s App Store validation. The CFBundleIdentifier must match the app’s provisioning profile. When it does not, the app fails to launch on devices with restricted profiles.
Mobile apps rely on third-party libraries. Scan them with npm, gradle, and cocoapods-specific tools.
In Android, ./gradlew dependencies --configuration compileClasspath outputs the full dependency graph. Use gradle’s --configuration flag to isolate runtime and test dependencies.
For iOS, use pod install with Podfile.lock to lock versions. Validate the lock file with:
pod install --repo-update
diff Podfile.lock Podfile.lock.orig
A mismatch between Podfile.lock and Podfile causes version skew across environments. The --repo-update flag ensures that the latest versions of all pods are pulled, but does not regenerate the lock file. To update the lock file, run pod update and commit Podfile.lock.
Validate that the app communicates securely over the network using HTTPS, with proper certificate pinning.
Use curl to test the app’s API endpoints with client certificates and custom headers:
curl -v \
--cert client.pem \
--key client.key \
--cacert ca.crt \
--header "Authorization: Bearer $(cat token.txt)" \
--header "X-App-Version: 1.2.3" \
https://api.example.com/v1/user/me
The --cert and --key flags send client certificates for mutual TLS. The --cacert flag validates the server’s certificate chain. A failure in certificate pinning results in a SSL certificate verify failed error, often caused by an incorrect or expired server.certificate.pinned file in the app bundle.
Certificate pinning ensures the app trusts only specific certificates, reducing the risk of man-in-the-middle attacks.
For iOS, the app bundle must contain pinning.json in Resources/:
{
"certificates": [
{
"sha256": "a1b2c3d4e5f67890abcdef1234567890abcdef1234567890abcdef1234567890"
},
{
"sha256": "f0e1d2c3b4a5968776543210fedcba9876543210fedcba9876543210fedcba9876"
}
],
"domains": [
"api.example.com",
"auth.example.com"
]
}
The sha256 values are derived from the DER-encoded certificate using openssl x509 -in cert.pem -outform DER | openssl dgst -sha256 -binary | xxd -p.
For Android, use network_security_config.xml in res/xml/:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config>
<domain includeSubdomains="true">api.example.com</domain>
<pin-set expiration="2025-12-31">
<pin digest="SHA-256">a1b2c3d4e5f67890abcdef1234567890abcdef1234567890abcdef1234567890</pin>
<pin digest="SHA-256">f0e1d2c3b4a5968776543210fedcba9876543210fedcba9876543210fedcba9876</pin>
</pin-set>
</domain-config>
</network-security-config>
The expiration attribute is a date string in yyyy-MM-dd format. If the pin-set is missing or the digest value is misaligned (e.g., using SHA-1 instead of SHA-256), the app fails to connect to the server with a android.security.KeyChainException: Certificate pinning failure error.
Ensure data is stored securely on-device, both in memory and on disk.
For iOS, check that SQLite databases are encrypted and use SQLCipher.
sqlite3 /path/to/app.db ".tables"
sqlite3 /path/to/app.db "PRAGMA cipher_version;"
The PRAGMA cipher_version; command returns the version of SQLCipher used. If the database is not encrypted, the output includes cipher_version: 4.0.0 but cipher_page_size is 1024 and cipher_kdf_iter is 1000. A mismatch between expected and actual values results in SQL error: database is not encrypted.
For Android, verify that Room databases use RoomDatabase with Room.databaseBuilder and that the database is encrypted using SQLCipher:
Room.databaseBuilder(context, MyDatabase.class, "my-db")
.setJournalMode(JournalMode.WRITE_AHEAD_LOGGING)
.setEncryptionKey("my-secret-key".getBytes())
.build();
The setEncryptionKey method requires a 32-byte key. If the key is shorter or longer, the database fails to open with android.database.sqlite.SQLiteException: database disk image is malformed.
On iOS, use security command-line tool to validate keychain entries:
security find-generic-password -l "API_KEY" -a "com.example.myapp" -w
The -l flag specifies the label, -a the account, and -w outputs only the password. A missing keychain entry returns no output. To verify the keychain is properly accessed, check that the keychain file is backed up and synced across devices:
security list-keychains -s login.keychain-db iCloud.keychain
On Android, use keytool to inspect the AndroidKeystore:
keytool -list -v -keystore /data/data/com.example.myapp/files/keystore.bks
The -v flag provides verbose output. The keystore.bks file uses BKS format, and the keytool command must be run on the device or copied from the device. If the keystore.bks file is missing or corrupted, the app fails with java.security.KeyStoreException: Keystore was not correctly initialized.
Validate the app’s behavior at runtime using adb, xcrun, and logcat.
Use adb logcat to capture logs during app startup:
adb logcat -s "MyApp:Main" -s "MyApp:Security"
The -s flag filters logs by tag. The MyApp:Main tag captures initialization events. A common failure is a missing applicationId in AndroidManifest.xml:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="MyApp"
android:theme="@style/AppTheme"
android:appComponentFactory="androidx.core.app.CoreComponentFactory"
android:appComponentFactory="androidx.core.app.CoreComponentFactory" />
The android:appComponentFactory attribute is often duplicated or misspelled, causing the app to fail to load the Application class.
Verify that the app’s integrity is preserved from build to deployment.
Use sha256sum to generate checksums of all app assets:
find . -name "*.ipa" -o -name "*.apk" -o -name "*.aab" | xargs sha256sum > app-checksums.txt
The find command collects all app artifacts. The xargs command runs sha256sum on each file. The app-checksums.txt file is committed to version control and used to validate deployments:
sha256sum -c app-checksums.txt
A mismatch between the expected and actual checksums causes the deployment pipeline to fail with sha256sum: app-checksums.txt: FAILED.
For apps that use dynamic code loading (e.g., React Native, Flutter), validate that the JavaScript bundle is correctly bundled and signed.
For React Native, use react-native bundle with --dev false:
react-native bundle \
--entry-file index.js \
--platform ios \
--bundle-output ios/main.jsbundle \
--dev false \
--minify
The --minify flag enables JavaScript minification. The --dev false flag disables development mode. A missing --bundle-output file results in Error: Cannot find module 'index.js' at runtime.
For Flutter, use flutter build aot:
flutter build aot \
--target-platform=ios \
--output-dir=build/aot \
--tree-shake-icons
The --tree-shake-icons flag reduces the size of the icon assets. A missing --target-platform option causes the app to fail to load the AOT compiled code.
After testing, generate a report that includes all findings, with links to raw results.
Use jq to extract and format Trivy’s JSON output:
jq -r '
.Results[] |
select(.Target | contains("MyApp")) |
{
"Target": .Target,
"Severity": .Severity,
"Vulnerabilities": .Vulnerabilities | length
} |
. | @json
' reports/trivy-results.json
The @json format outputs a JSON object for each result. The select function filters results by target. The length function counts vulnerabilities. The output is consumed by a CI dashboard.
Certificate pinning failure in logcat or console.log, but the pinning.json file is not in the correct location or has invalid JSON.Podfile.lock file is committed, but pod install is run with a different Podfile version, causing unexpected library versions.keychain file is not included in the app bundle, or the login.keychain-db is not in the Keychains directory.SQLCipher database is created but not encrypted during the app’s first run. The PRAGMA cipher_page_size is set but cipher_kdf_iter is not, causing performance issues.AndroidManifest.xml: The android:appComponentFactory attribute is missing, causing the app to fail to load the Application class.These failures are silent: the app launches, but users experience unexpected behavior, such as login failures or data loss. They are discovered only after deployment.
Mobile App Security Testing is not a one-off task. It is a continuous validation of the app’s security posture across the CI/CD pipeline, from build to deployment. It relies on standard Unix tools and conventions: curl, jq, docker, adb, keytool, sqlite3, security, logcat. The testing process is defined by data flow: artifacts are scanned, dependencies are validated, network communication is tested, data storage is verified, and runtime behavior is monitored. The result is a robust, secure mobile application that withstands real-world threats.
This page was rewritten on 12 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.
We use cookies for analytics (Google Analytics) and advertising (Google AdSense) to improve your experience and support free content. Privacy Policy