Skip to content

Preserve Loon encryption keys while upgrading flutter_secure_storage to 11.x - #46

Open
rayliverified wants to merge 1 commit into
danReynolds:mainfrom
rayliverified:fix/secure-storage-11-key-survival-20261111
Open

rayliverified wants to merge 1 commit into
danReynolds:mainfrom
rayliverified:fix/secure-storage-11-key-survival-20261111

Conversation

@rayliverified

@rayliverified rayliverified commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Resolve flutter_secure_storage ^11.2.0 and keep Loon's existing key name, Android namespace and cipher defaults. Set Android resetOnError: false so a storage/decrypt error does not automatically erase the persistent database encryption key.
  • Check the plugin's read-only upgrade status before treating an absent key as a new installation. Fail initialization for reported legacy unreadable/discarded data or unknown status; propagate read errors without replacing the key. This does not decrypt or repair 9.x data under v11.
  • Add regression tests for key creation, continuity, legacy/unknown status and failed reads; update the example's Android API 24 and iOS 13 minimums and document safe migration.

Migration risk and evidence

Loon stores the AES key as loon_encrypted_file_persistor_key; file/SQLite ciphertext cannot be read if that key is silently replaced. The v11 changelog states that the 9.x RSA-PKCS1/AES-CBC ciphers were removed and installations originating on v9 must actually run v10 and access/migrate the key before running v11. An app currently declaring v10 is not proof every installed user has completed that step. Android resetOnError defaults to true; here it is explicitly disabled only for Loon's key, preserving plugin migration and namespace settings.

Android emulator upgrade sequence already tested in the NOCD app (secure-storage authInfo token, not Loon's AES key): an install with a token written by v10.3.4 retained it when upgraded to v11.2.0; an install with a token written by v9.2.4 lost it on a direct upgrade to v11.2.0 (AEADBadTagException, B2_after.log:583-604); and an install with v9.2.4 data retained the token when v10.3.4 was opened first (C2_v10.log:580-594), then updated to v11.2.0 (C3_after.log). This is observed Android plugin migration behavior, not a test of Loon's own key or encrypted database. The rollout procedure and recovery cautions are in docs/secure_storage_migration.md. Backups and an app-level staged rollout are still mandatory for old installations; an already-deleted key cannot be recovered by this patch.

Verification

  • flutter pub get: resolves flutter_secure_storage 11.2.0; example lockfile updated.
  • dart analyze lib test/core/persistor/data_store_encrypter_test.dart: clean.
  • flutter test test/core test/native: 257 tests passed, including five mocked key-survival regression tests.
  • flutter build ios --simulator --debug (example): built Runner.app; Flutter's local toolchain automatically migrated the sample project to iOS 15 during this verification, but generated migration edits were intentionally excluded from this PR (the committed minimum is iOS 13). No device keychain upgrade was exercised.
  • flutter analyze (whole repo): exits nonzero on two existing use_null_aware_elements infos in benchmark/value_store/run_core.dart:126,305; no changed-code issues.
  • flutter test (all): fails when VM tries to compile test/web/indexed_db_persistor_test.dart with dart:js_interop; core/native suite passes. flutter build apk --debug (example): blocked by pre-existing imperative Flutter Gradle app_plugin_loader.gradle application in the old example project on Flutter 3.47.8, before plugin compilation. Did not change Android emulators or downstream app.

@rayliverified

Copy link
Copy Markdown
Contributor Author

The flutter_secure_storage suffers from a critical mistake, where the author created a breaking change, that prevents users from migrating successfully and potentially incurs catastrophic irrecoverable data loss.

There is no migration path from v9 to v11 with a guarantee of no data loss.

@rayliverified

rayliverified commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Android emulator migration findings (installed-app upgrades without clearing data):

Stored value / upgrade path Observed result
flutter_secure_storage 10.3.4 → 11.2.0 Existing app authInfo token remained readable.
9.2.4 → 11.2.0 directly Token read failed with AEADBadTagException; the app started logged out.
9.2.4 → opened 10.3.4 and read the token → 11.2.0 v10 migrated the stored item; the token remained readable on v11.
Direct 9 → 11 failure, then reinstall 10.3.4 Did not recover the token.

The v11 changelog says legacy ciphers were removed and v10 must migrate existing data first. Setting migrateOnAlgorithmChange: true in v11 did not rescue the direct 9 → 11 case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant