I have a question about security.
I am making an iOS app with in app purchase following this tutorial, and I store what products were bought in NSUserDefaults. That's why I wonder :
Can a user with a jailbroken device modify NSUserDefaults key and values for an app?
Thank you very much if you know about it.
Jer
All the contents saved by NSUserDefaults is saved inside a plist file that can be found under Library -> Preferences -> $AppBundleId. plist as shown in the image below. Open up the plist file and you can easily view the contents of the file.
Overview. The NSUserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an app to customize its behavior to match a user's preferences. For example, you can allow users to specify their preferred units of measurement or media playback speed.
A keychain is an encrypted container that holds passwords for multiple applications and secure services. Apple Inc. uses keychains as password management system in Mac OS and iOS. UserDefaults Provides a way for application behavior Customization based on user preferences.
This method is using a pthread_mutex_t to lock the access to the dictionary containing the values. So NSUserDefaults is thread safe.
Yes, they can. The user defaults are stored relative to your app directory here:
./MyAppName.app
./Library/Preferences/com.mycompany.MyAppName.plist
The plist file is not encrypted or signed, so it can be modified easily:
plutil -convert xml1 com.mycompany.MyAppName.plist
vim com.mycompany.MyAppName.plist
You can look into the iOS keychain, as @rckoenes said, or also something like this open source secure defaults replacement, which offers an interface similar to NSUserDefaults
.
Since iOS 8, the data directory (and thus the preferences plist files) are now under:
/var/mobile/Containers/Data/Application/<GUID>/Library/Preferences/
Apple Reference Docs
Even users without a Jailbroken device can modify plists...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With