Android Core
Simple tips to secure Android app
Here, I list down most common things that developers should take care to protect the application.
- Do not store private or sensitive data on SDCard. To store file on internal storage, use following methods with private mode (Context.MODE_PRIVATE) openFileOutput & openFileInput. If you really wants to store data in sdcard then encrypt it. You will find many encryption libraries. I prefer conceal from facebook.
- Restrict ContentProvider using exported flag set as false. It’s not the case that every time we develop ContentProvider for data exchange between applications but ContentProvider can be developed for single application or private.
- Restrict WebView to access local data. HTML5 and related technologies have become popular to develop Mobile Web App app or Hybrid app. For Hybrid uses WebView to display content from locally store HTML or fetch HTML and other content from the server. Major security concerns for WebView are setAllowFileAccess() and setAllowContentAccess() methods.
- Do not pass sensitive information through Broadcast & Intent. Use LocalBroadcastManager for broadcast data within process / app. LocalBroadcastManager is available in Support Library V4.
- Don’t print sensitive information in LogCat. Information like username, password, web service URL, request or response, etc detail.
- Remove unnecessary Log before publishing app.
- Don’t process malicious Intents. Before process Intent received in onReceive method of BroadcastReceiver, validate callers package name, action and other information.
- Protect your Service with Permission. Use exposed flag as false When Service is developed for your app only.
- Restrict access to Activities. If the activity is intended solely for the internal use of the app then use exported flag set as false.
- Make sure that debug mode is false before publish APK.
- Encrypt sensitive data even if you store in internal storage.
- For cross app functionality, validate calling application before response.
- Properly verify server certificate TLS/SSL for HTTPS web call.
- Use NDK whenever you feel that information is not safe in Java code because It can decompile easily. i.e. Constant.
- Use ProGuard that shrinks, optimizes, and obfuscates your code.
- Remove unwanted / unused <user-permission> from AndroidManifest.xml
- Loading classes.dex outside of application is major security risk. DexClassLoader allowed developer to load classes.dex on demand.
<provider android:exported="false" android:name="MyContentProvider" android:authorities="com.example.mycontentprovider" />
<activity android:name=".view.MyActivity" android:exported="false"> </activity>
Resource: http://developer.android.com/training/articles/security-tips.html
Reference: | Simple tips to secure Android app from our JCG partner Ketan Parmar at the KP Bird blog. |
any examples of ndk and constant ?
hello george,
Yes, I do have example, I will upload example in github.com
Regards
KPBird
it would be great, many thanks