Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can users modify NSUserDefaults key values in an iOS app?

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

like image 582
darksider Avatar asked Oct 09 '12 07:10

darksider


People also ask

Where are the NSUserDefaults values stored?

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.

What is NSUserDefaults in iOS?

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.

What is difference between keychain and UserDefaults in Swift?

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.

Is NSUserDefaults thread safe?

This method is using a pthread_mutex_t to lock the access to the dictionary containing the values. So NSUserDefaults is thread safe.


2 Answers

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.


Update:

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

like image 82
Nate Avatar answered Oct 12 '22 01:10

Nate


Even users without a Jailbroken device can modify plists...

like image 28
Lefteris Avatar answered Oct 12 '22 01:10

Lefteris