Mobile App Security Basics

Khimananda Oli 8 min read Virtualization
Mobile App Security Basics

By Khimananda Oli | Last reviewed: August 2026

Shipping a mobile application without a hardened security foundation exposes user data and business logic to interception, tampering, and credential theft. Understanding mobile app security basics is no longer optional for developers or founders; it is the baseline requirement for trust and compliance in 2026. This guide cuts through theoretical frameworks to provide concrete, implementable controls for secure storage, network communication, and authentication that work across both iOS and Android platforms.

Device LayerEncrypted KeystoreBiometric AuthCode ObfuscationNetwork LayerTLS 1.3 OnlyCert PinningPayload EncryptionBackend LayerToken ValidationRate LimitingAudit Logging
Defense-in-depth architecture for mobile app security basics across device, network, and backend layers

How do you securely store sensitive data in mobile apps?

The most frequent failure I see in audits is storing tokens, PII, or credentials in SharedPreferences (Android) or UserDefaults (iOS). These are plaintext XML or plist files readable by any process with app access or via backup extraction. Secure storage requires hardware-backed keystores that isolate cryptographic material from the application runtime.

Use platform-native encrypted storage

Android provides the EncryptedSharedPreferences API backed by the Android Keystore System. iOS offers Keychain Services with accessibility attributes that restrict access to unlocked devices. Never roll your own encryption wrapper around standard preferences; the key management complexity introduces subtle bugs.

// Android: Secure token storage with EncryptedSharedPreferences
val masterKey = MasterKey.Builder(context)
    .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
    .build()

val securePrefs = EncryptedSharedPreferences.create(
    context,
    "secure_token_prefs",
    masterKey,
    EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
    EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)

// Store auth token securely
securePrefs.edit()
    .putString("auth_token", accessToken)
    .apply()

For iOS, always set kSecAttrAccessibleWhenUnlockedThisDeviceOnly to prevent tokens from appearing in iCloud backups or being accessible when the device is locked. This single attribute prevents an entire class of forensic extraction attacks.

Data classification drives storage decisions

Not all data needs keystore-level protection. Classify data into three tiers before writing storage code:

  • Secrets: Auth tokens, API keys, private keys → Hardware keystore only
  • Sensitive: User PII, health data, financial records → Encrypted database (SQLCipher) or encrypted file storage
  • Public: UI preferences, cached content, non-sensitive metadata → Standard storage acceptable

This classification aligns with compliance frameworks like SOC 2 and ISO 27001. During audits, reviewers will ask for evidence of data classification policies mapped to technical controls. Having this documented before development starts saves weeks of remediation later. For teams managing backend databases alongside mobile clients, understanding PostgreSQL administration essentials ensures server-side storage matches mobile-side security posture.

How do you secure mobile API communication against interception?

TLS alone is insufficient for mobile apps. Certificate authorities can be compromised, corporate proxies can intercept traffic, and users can install malicious root certificates. Defense-in-depth network security requires TLS 1.3 enforcement combined with certificate pinning and payload-level protections.

Implement certificate pinning correctly

Certificate pinning binds your app to specific server certificates or public keys, rejecting connections even if a valid CA-signed certificate is presented. Pin the Subject Public Key Info (SPKI) hash rather than the full certificate to allow certificate rotation without app updates.

# OkHttp certificate pinner configuration (Kotlin)
val certificatePinner = CertificatePinner.Builder()
    .add("api.example.com", "sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")
    .add("api.example.com", "sha256/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB=") // backup pin
    .build()

val client = OkHttpClient.Builder()
    .certificatePinner(certificatePinner)
    .sslSocketFactory(Tls13OnlySocketFactory(), trustManager)
    .build()

Always include at least one backup pin. I have seen production outages where a primary certificate expired and the app had no fallback, requiring an emergency app store update. Test pinning failures explicitly in CI using tools like TrustKit or custom test harnesses.

Enforce network security configuration

Android's Network Security Config and iOS's App Transport Security (ATS) provide declarative network policies. Disable cleartext traffic globally and whitelist only trusted domains. This prevents accidental HTTP requests from leaking data before they reach production.

App RequestBuild PayloadEncrypt BodySign HeadersTLS HandshakeVerify TLS 1.3Check Cipher SuiteReject < TLS 1.2Cert PinningExtract SPKI HashCompare to PinsFail ≠ MatchServer ValidateDecrypt PayloadVerify SignatureProcess Request
Sequential validation flow for secure mobile API requests from payload encryption through certificate pinning to server processing

What authentication patterns prevent session hijacking in mobile?

Mobile authentication differs fundamentally from web authentication. Cookies are unreliable, browsers handle redirects differently, and biometric sensors provide capabilities unavailable on desktop. Secure mobile auth binds sessions to device-specific factors and minimizes token exposure surface area.

Bind tokens to device attestation

Use Android SafetyNet/App Attest (iOS) to generate device-bound tokens. When your backend issues refresh tokens, tie them to the attestation result. If a token extracted from a rooted device appears on a different device fingerprint, revoke it immediately. This limits the blast radius of credential theft.

Implement biometric authentication correctly

Biometrics should unlock stored credentials, not replace them. The pattern is: authenticate with biometrics → retrieve token from keystore → use token for API calls. Never store passwords or tokens in biometric-protected storage directly; store only the decryption key. This ensures biometric compromise does not equal credential compromise.

// iOS: Biometric-gated keychain access
let context = LAContext()
context.localizedCancelTitle = "Enter Passcode Instead"

var error: NSError?
guard context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) else {
    // Fallback to passcode or PIN entry
    return
}

context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics,
                       localizedReason: "Access secure account data") { success, evalError in
    if success {
        // Retrieve token from Keychain with kSecAttrAccessibleWhenUnlockedThisDeviceOnly
        let token = KeychainHelper.retrieveToken()
        // Use token for authenticated API call
    }
}

Short-lived access tokens with secure refresh

Access tokens should expire in 15 minutes or less. Refresh tokens live longer but require device binding and rotation on each use. Implement refresh token rotation: every time a refresh token is used, issue a new refresh token and invalidate the old one. If a stolen refresh token is reused after rotation, detect the replay and revoke the entire token family. Teams integrating with Laravel backends should review building REST APIs with Laravel Sanctum for proper token lifecycle management.

How do platform-specific security controls differ between iOS and Android?

While security principles transfer across platforms, implementation details diverge significantly. Understanding these differences prevents copy-paste vulnerabilities where Android patterns fail silently on iOS or vice versa.

Control AreaAndroid ImplementationiOS ImplementationCommon Pitfall
Secure StorageEncryptedSharedPreferences + KeystoreKeychain Services + Data ProtectionUsing standard SharedPreferences/UserDefaults for secrets
Network SecurityNetwork Security Config XMLApp Transport Security in Info.plistDisabling ATS exceptions without documenting justification
Certificate PinningOkHttp CertificatePinner / TrustKitTrustKit / URLSessionDelegatePinning leaf certificate instead of SPKI hash
Biometric AuthBiometricPrompt APILocalAuthentication frameworkStoring credentials directly in biometric storage
Code ProtectionR8/ProGuard obfuscationLLVM obfuscation + bitcode strippingRelying solely on obfuscation without runtime checks
Device IntegrityPlay Integrity APIApp Attest + DeviceCheckSkipping integrity checks on debug builds only

A critical difference often overlooked is backup behavior. Android allows full app backup by default unless android:allowBackup="false" is set in the manifest. iOS includes Keychain items in encrypted backups but excludes them from unencrypted iTunes backups. Test backup extraction on both platforms during security QA to verify sensitive data does not leak through backup artifacts.

Runtime protection varies by ecosystem

Android's open nature makes runtime manipulation easier. Implement root detection, debugger detection, and emulator detection as layered defenses. iOS sandboxing provides stronger isolation but jailbreak detection remains necessary. Use commercial RASP solutions or open-source alternatives like RootBeer (Android) and JailMonkey (cross-platform) as baseline protections, understanding that determined attackers bypass all client-side checks.

Android Security StackApplication LayerR8 Obfuscation · Runtime ChecksPlatform SecurityKeystore · BiometricPrompt · SafetyNetNetwork ControlsNetwork Security Config · OkHttp PinningHardware RootTEE · StrongBox · Titan MiOS Security StackApplication LayerLLVM Obfuscation · Jailbreak DetectionPlatform SecurityKeychain · LocalAuth · App AttestNetwork ControlsATS · TrustKit · URL Session DelegateHardware RootSecure Enclave · SEP · FaceID/TouchID
Side-by-side comparison of iOS and Android security control architectures highlighting equivalent platform-specific implementations

Integrating mobile security into your development workflow

Security controls fail when treated as post-launch hardening. Integrate mobile app security basics into sprint planning, code review, and CI pipelines from day one. Add SAST tools like MobSF or Semgrep to pull request checks. Require security review sign-off for any PR touching authentication, storage, or networking code. Maintain a security decision log documenting why specific controls were chosen over alternatives — this becomes audit evidence and onboarding documentation.

For Nepal-based teams building fintech or health applications, align these controls with NRB directives and local data residency requirements early. Global compliance frameworks map cleanly to local regulations when foundational controls are solid. Budget-conscious startups should prioritize encrypted storage and TLS pinning first; advanced RASP and attestation can follow as threat models mature. Teams already practicing structured observability will find security monitoring integrates naturally — see structured logging best practices for patterns that serve both operational and security telemetry needs.

Next steps for securing your mobile application

Start with a threat model specific to your application's data sensitivity and user base. Implement encrypted storage and certificate pinning before adding features. Test security controls in CI, not just during penetration tests. Document decisions for auditors and future maintainers. If your team needs hands-on guidance implementing these controls or preparing for SOC 2 certification, reach out to discuss your mobile security roadmap. Practical, audit-ready security is achievable without slowing feature delivery when fundamentals are solid.

Frequently Asked Questions

Core mobile app security basics include enforcing TLS 1.3 for all network traffic, encrypting sensitive data at rest using platform keystores, implementing certificate pinning, and applying code obfuscation. These foundational controls prevent common interception and reverse engineering attacks targeting iOS and Android applications in production environments.

Certificate pinning binds your app to specific server certificates or public keys, preventing man-in-the-middle attacks even if a rogue CA is trusted by the OS. Configure pins in OkHttp or Alamofire with backup pins and expiration dates to avoid bricking apps during certificate rotations.

RASP adds detection layers but is not part of essential mobile app security basics. Focus first on secure coding, proper encryption, and API hardening. RASP suits high-risk fintech or healthcare apps where regulatory compliance demands additional tamper detection beyond standard platform protections and code obfuscation techniques.

Use AES-256-GCM for data at rest and TLS 1.3 for transit. Store keys in Android Keystore or iOS Keychain, never in source code. Avoid custom crypto algorithms. Follow NIST SP 800-38D guidance updated through 2026 for authenticated encryption modes approved for mobile deployments.

Never store JWTs or session tokens in SharedPreferences or UserDefaults. Use encrypted storage via Android EncryptedSharedPreferences or iOS Keychain with access control flags. Set token expiration under fifteen minutes and implement refresh token rotation to limit exposure windows if device storage is compromised.

No. SAST catches only about thirty percent of mobile vulnerabilities. Combine MobSF or SonarQube scans with manual penetration testing and dynamic analysis using Frida. Automated tools miss logic flaws, insecure IPC mechanisms, and business logic errors that require human review against OWASP MASVS standards.

Obfuscation raises reverse engineering effort but is not a standalone defense. Use ProGuard or R8 for Android and bitcode compilation for iOS alongside string encryption and control flow flattening. Treat obfuscation as defense-in-depth supporting stronger controls like certificate pinning and secure key management practices.

Implement per-request signing with HMAC-SHA256, enforce strict input validation server-side, and apply rate limiting per user and device fingerprint. Never trust client-side validation alone. Use OAuth 2.1 with PKCE for authentication flows and audit all endpoints quarterly against OWASP API Security Top 10 guidelines.

Reassess quarterly and after every major OS release or dependency update. Mobile threat landscapes shift rapidly; new jailbreak techniques and side-channel attacks emerge monthly. Schedule regular pentests, update cryptographic libraries promptly, and review MASVS compliance checklists to maintain baseline security posture throughout 2026.

Biometrics enhance convenience but do not replace password-based authentication entirely. Always bind biometric prompts to cryptographic operations via platform APIs rather than storing biometric templates. Implement fallback authentication methods and liveness detection to prevent spoofing attacks against facial recognition or fingerprint sensors.

Logging PII, credentials, tokens, or full API responses violates security basics. Strip sensitive fields before writing logs and use structured logging with allowlisted fields only. Disable verbose logging in release builds and route logs through secure channels that comply with GDPR and CCPA data handling requirements.

Deep links can expose sensitive parameters in URLs and enable phishing attacks. Validate all incoming URI schemes server-side, avoid passing secrets in link parameters, and implement universal links or app links with verified domain ownership. Sanitize inputs and restrict accessible functionality based on authentication state.

Third-party SDKs introduce supply chain vulnerabilities, excessive permissions, and data leakage vectors. Audit SDKs using dependency scanning tools, pin exact versions, and review privacy manifests. Remove unused SDKs regularly and isolate untrusted components behind abstraction layers to contain potential breaches within your mobile application architecture.

Yes. WebViews inherit browser attack surfaces including XSS and mixed content vulnerabilities. Disable JavaScript unless required, validate loaded URLs against an allowlist, and use postMessage for secure JS-native communication. Enable safe browsing APIs and avoid loading remote content without integrity verification in production releases.

Run SAST on every commit, DAST weekly against staging builds, and full manual pentests quarterly. Integrate security gates into CI pipelines blocking merges on critical findings. Supplement automated testing with bug bounty programs to catch edge cases that scripted tests miss during rapid development cycles.