Lesson 2 of 11
App Security - JWT, Certificate Pinning & Obfuscation
Mobile app security has unique challenges: the binary can be installed on a rooted/jailbroken device, traffic can be intercepted via a proxy, and sensitive logic lives in the bundle file. Production apps must defend against each.
Security Checklist and Implementation
// ---- 1. Secure token storage (SecureStore) ----
// Already covered in Module 6 - never use AsyncStorage for tokens
// ---- 2. Certificate Pinning - prevent MITM attacks ----
// MITM: attacker installs a root certificate to intercept HTTPS traffic
// Certificate pinning: the app only trusts a specific server certificate
npm install react-native-ssl-pinning
import { fetch as pinnedFetch } from 'react-native-ssl-pinning';
// Store the SHA-256 hash of your server certificate's public key
const PINNED_HASH = 'sha256/YOUR_SERVER_CERT_HASH_HERE=';
export const secureClient = {
get: async (url: string, token: string) => {
const response = await pinnedFetch(url, {
method: 'GET',
pkPinning: true,
sslPinning: {
certs: [PINNED_HASH], // your certificate's public key SHA256 hash
},
headers: { Authorization: `Bearer ${token}` },
});
return response.json();
},
};
// ---- 3. Jailbreak / Root detection ----
npm install jail-monkey
import JailMonkey from 'jail-monkey';
function checkDeviceSecurity() {
if (JailMonkey.isJailBroken()) {
// Jailbroken iOS or Rooted Android
Alert.alert(
'Security Warning',
'This device has been modified and may not be secure. Some features are disabled.',
[{ text: 'Continue Anyway' }]
);
// For financial apps: block entirely
// For social apps: warn but allow
}
if (JailMonkey.canMockLocation()) {
// GPS mocking app detected (e.g., fake GPS for location-based features)
console.warn('Location mocking detected');
}
}
// ---- 4. JS Bundle Obfuscation ----
// Metro minifies by default in production builds
// For extra obfuscation, use metro-react-native-babel-preset with hermes-bytecode
// The Hermes bytecode is harder to reverse-engineer than raw JS
// ---- 5. Sensitive data in logs ----
// ❌ Never log tokens/passwords - even in dev
console.log('Token:', accessToken); // WRONG
// ✅ Safe logging
if (__DEV__) console.log('Auth success'); // only in dev, no token
// ---- 6. Deep link validation ----
// Validate all deep link params - treat them as untrusted user input
function handleDeepLink(url: string) {
const parsed = new URL(url);
const productId = parsed.searchParams.get('id');
if (!productId || !/^[a-zA-Z0-9-]{1,36}$/.test(productId)) {
console.warn('Invalid deep link param');
return;
}
navigation.navigate('ProductDetail', { productId });
}Tip
Tip
Practice App Security JWT Certificate Pinning Obfuscation in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Hardening mobile apps with SSL pinning, root detection, and ProGuard minification
Practice Task
Note
Practice Task - (1) Write a working example of App Security JWT Certificate Pinning Obfuscation from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with App Security JWT Certificate Pinning Obfuscation is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready react native code.
Finished this lesson?