-
-
Notifications
You must be signed in to change notification settings - Fork 483
[WIP] fix(android): isolate storage instances per shared preferences name (fix: #1023) #1031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
Opened for initial code review as it directly solves the mentioned issue #1023, however, I will be working on introducing the same type of namespace/storage isolation for the |
Important compatibility note (Android)On some existing installs, upgrading to this fix can make previously-stored values “disappear” even when the app passes the same Why this can happenIssue #1023 is caused by the Android plugin reusing a single After this PR, reads/writes are correctly bound to the requested namespace. If legacy data was accidentally stored under a different prefs file due to the bug, the upgraded version will not find it in the “correct” namespace anymore (because it never lived there). In other words: this PR fixes the bug, but it also removes accidental cross-namespace behavior some apps may have relied on unknowingly. Apps that previously experienced namespace mixing might observe missing values after upgrade. Suggested solution (introduce a new field; deprecate
|
allow for secure storage config isolation per namespace, allowing usage of different algorythms between storages
This is actually a big problem that needs to be solved as well, and not just a "note". It's especially relevant since there's now a migration mechanism in v10 from AES/CBC to another cipher. If you have 2 storages with different algorithms/keys, they will conflict because they are using the same key alias in KeyStore, and all data will be lost as a result. Different keys should be used for different storages |
Yes, that is true. I introduced a |
That doesn't solve the issue fully because the key alias is the same for all algorithms/storages, which means the same key is used for all instances: but obviously, keys should be separated as well for different algorithms/storages; otherwise, they will conflict with each other. Correct me if I'm wrong |
|
Hi all, sorry for the delay. I think a valid issue is raised here. I think the best solution would indeed be to migrate to The best would be to introduce this change in v11, as v11 will remove the older encryption methods, as well as the migration tool. This way we could also alter |
Fix Android namespace isolation for
sharedPreferencesNameFixes #1023
Problem
Multiple
FlutterSecureStorageinstances with differentsharedPreferences Namevalues shared a single cachedFlutterSecureStorageinstance, causingdeleteAll()and other operations to affect data across namespaces.Solution
Enforce namespace isolation at the plugin layer by routing each
MethodChannelcall to a dedicatedFlutterSecureStorageinstance persharedPreferencesName. This ensures operations on namespace B never affect namespace A.Implementation:
Map<String, FlutterSecureStorage>keyed bysharedPreferencesNamegetOrCreateStorage()retrieves or creates the correct instance per namespaceread,write,delete,deleteAll, etc.) use the namespace-specific instanceTesting
✅ Added Android-only integration test that:
namespace_a,namespace_b)deleteAll()onnamespace_bnamespace_aremains intactBreaking Changes
None
Notes
SHARED_PREFERENCES_CONFIG_NAMEremains global (stores migration/cipher metadata only). This poses a threat of possible encryption-related issues when two or more storages use different algorithms.sharedPreferencesName