Skip to content

fix(storage): selectable browser store, truthful IsEncrypted, DPAPI persistence, ISettings registration - #3153

Merged
kazo0 merged 2 commits into
mainfrom
dev/sb/storage-fixes
Aug 24, 2026
Merged

kazo0 merged 2 commits into
mainfrom
dev/sb/storage-fixes

Conversation

@kazo0

@kazo0 kazo0 commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue (If applicable): split out of #3139 (relates to #3025, #2346)

PR Type

  • Bugfix
  • Feature

What is the current behavior?

  • On WebAssembly the browser store is not selectable. The default IKeyValueStorage is ApplicationData (which Uno maps to localStorage) with no way to choose sessionStorage or memory-only, so anything built on storage - the authentication token cache above all - has exactly one lifetime in the browser.
  • IsEncrypted is wrong on the stores that do encrypt. EncryptedApplicationDataKeyValueStorage (DPAPI) and PasswordVaultKeyValueStorage (Credential Locker) both report false. That flag is on the public IKeyValueStorage surface and is exactly what a consumer branches on to decide whether a store is safe for tokens, so under-reporting pushes callers away from the Windows stores that protect them.
  • DPAPI-protected values never persist on unpackaged Windows. The unpackaged path stores through the string-only ISettings, and the base store persists value?.ToString() - so every protected byte[] was written as the literal "System.Byte[]" and read back as nothing. The keys persisted regardless, so TokenCache.HasTokenAsync reported the user signed in with nothing to recover.
  • UseStorage does not register the ISettings its own stores need. It was registered by UseThemeSwitching (and later by UnoHost.CreateDefaultBuilder), so a host built any other way fails to resolve the default store.

What is the new behavior?

  • KeyValueStorageConfiguration:BrowserCacheLocation selects the browser store - LocalStorage (the default, so upgrading never relocates existing data), SessionStorage (new SessionStorageKeyValueStorage over direct JS interop; there is no WinRT surface for sessionStorage), or MemoryStorage. The member names mirror msal-browser's cacheLocation. Only the browser acts on it - Skia desktop shares the same #else branch and must keep ApplicationData - but it is validated on every platform, so a typo in a shared appsettings.json fails the desktop run a developer actually does rather than only the one head that reads it.
  • IsEncrypted is true for the DPAPI and Credential Locker stores.
  • The base store base64-encodes binary values on the ISettings path; the encrypted store returns the raw DPAPI bytes on both paths and still accepts either shape on read, so existing packaged caches are not orphaned.
  • AddKeyedStorage registers ISettings itself (TryAdd - an app's own wins). That needs the implementation, which lives in Uno.Extensions.Core.UI, so Uno.Extensions.Storage.WinUI now references Uno.Extensions.Core.WinUI (as Hosting.WinUI and Navigation.WinUI already do). UseThemeSwitching keeps its own TryAdd.
  • New Uno.Extensions.Storage.WinUI.Tests (runtime UI tests): store selection for each BrowserCacheLocation value on the browser and the "ignored elsewhere" guard on every other head, the strict validation (unknown and numeric values throw naming the setting; casing is accepted), and a write/read round trip through whatever the default resolved to.
  • Docs: StorageOverview.md gains the per-platform default-store table and the BrowserCacheLocation section, plus a note that Android/iOS heads built with the Skia renderer get plain ApplicationData (the SDK swaps in this package's netX.0 build there, and the KeyStore/Keychain stores only exist in the platform builds); UpdatingExtensions.md records the IsEncrypted and ISettings changes.

PR Checklist

  • Tested code with current supported SDKs
  • Docs have been added/updated which fit documentation template
  • Unit Tests and/or UI Tests for the changes have been added
  • Wasm UI Tests are not showing any unexpected differences
  • Contains NO breaking changes - BrowserCacheLocation is additive with a preserving default; IsEncrypted changes value on two stores, which is the flag reporting the truth
  • Updated the Release Notes
  • Associated with an issue (GitHub or internal)

Other information

Verified locally: the new test class 8/8 on the desktop runtime-test head; Uno.Extensions-packageonly.slnf Release build 0 errors. The browser-side cases (sessionStorage interop, the localStorage/session/memory mapping) run on the WebAssembly runtime-test lane that #3139's CI layer adds; until that lands they are covered by the desktop run's "ignored off the browser" assertions and by #3139's own WebAssembly lane, where this class is 8/8.

Reviewer note: this is the storage layer of #3139's split. The MSAL provider's WebAssembly token-cache persistence, which is what motivated BrowserCacheLocation, comes in a later PR; nothing here depends on it.

Also carries a small docs: commit fixing pre-existing markdownlint/cspell failures elsewhere in the tree (specs/004, specs/006, specs/lessons.md, two dictionary words, MD059/MD060 disabled): the docs-validation stage only runs for PRs that touch .md, and this is the first such PR since they crept in. Same fixes as #3139.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EqfQh5ovrPEvFGcERLiLhH

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 229788 has failed on uno.extensions.

@kazo0
kazo0 enabled auto-merge August 24, 2026 16:41
@mergify

mergify Bot commented Aug 24, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

kazo0 and others added 2 commits August 24, 2026 13:10
…ersistence, ISettings registration

The storage layer of #3139's split.

- KeyValueStorageConfiguration:BrowserCacheLocation selects the WebAssembly
  store: LocalStorage (the default - what the browser already used, so
  upgrading never relocates data), SessionStorage (new
  SessionStorageKeyValueStorage over direct JS interop; there is no WinRT
  surface for sessionStorage) or MemoryStorage. Member names mirror
  msal-browser's cacheLocation. Only the browser acts on it - Skia desktop
  shares the same #else branch and must keep ApplicationData - but the value
  is validated on every platform so a typo in a shared appsettings.json fails
  the desktop run a developer actually does
- IsEncrypted reports true for EncryptedApplicationDataKeyValueStorage (DPAPI)
  and PasswordVaultKeyValueStorage (Credential Locker). It is the flag on the
  public surface a consumer branches on to decide whether a store is safe for
  tokens, and both said false
- DPAPI-protected values now persist on unpackaged Windows. The unpackaged
  path goes through the string-only ISettings, and the base store persisted
  value?.ToString() - the literal "System.Byte[]" - while the keys persisted,
  so HasTokenAsync reported a signed-in user with nothing to recover. The base
  store base64-encodes byte[] on that path; the encrypted store returns raw
  bytes on both and accepts either shape on read, so packaged caches are not
  orphaned
- AddKeyedStorage registers the ISettings its stores need (TryAdd; an app's
  own wins), so UseStorage works on any host rather than only after
  UseThemeSwitching. Storage.WinUI therefore references Core.WinUI, as
  Hosting.WinUI and Navigation.WinUI already do

New Uno.Extensions.Storage.WinUI.Tests, wired into the runtime-test head:
store selection per BrowserCacheLocation value on the browser and the
"ignored elsewhere" guard everywhere else, strict validation (unknown and
numeric values throw naming the setting, casing accepted), and a round trip
through the resolved default.

Docs: StorageOverview.md gains the per-platform default-store table, the
BrowserCacheLocation section, and a note that Android/iOS heads built with the
Skia renderer get plain ApplicationData (the SDK loads this package's netX.0
build there, and the KeyStore/Keychain stores only exist in the platform
builds); UpdatingExtensions.md records the IsEncrypted and ISettings changes.

Verified: Storage.WinUI.Tests 8/8 on the desktop runtime-test head;
Uno.Extensions-packageonly.slnf Release 0 errors; markdownlint and cspell clean.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EqfQh5ovrPEvFGcERLiLhH
The docs-validation stage only runs for PRs that touch a .md file, and the
first one to do so since these crept in fails on files it did not change:

- MD040 (fenced code block without a language) in specs/004 and specs/006
- cspell: "nuspecs" and "unmaterialized" (technical terms, added to the
  dictionary) and "recognise" in specs/lessons.md (spelled the way the rest
  of the docs do)
- MD059 / MD060 are new rules in current markdownlint-cli that flag existing
  tables and link text across doc/; disabled in the config, as #3139 did, so
  the lane checks what it checked before rather than the whole tree at once

Verified with the CI commands: markdownlint clean, cspell 226 files / 0 issues.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EqfQh5ovrPEvFGcERLiLhH
@kazo0
kazo0 force-pushed the dev/sb/storage-fixes branch from 93ebe00 to ec84019 Compare August 24, 2026 17:10
@kazo0
kazo0 merged commit e96c0bd into main Aug 24, 2026
17 of 20 checks passed
@kazo0
kazo0 deleted the dev/sb/storage-fixes branch August 24, 2026 17:42
agneszitte pushed a commit that referenced this pull request Nov 3, 2026
- The docs validation only runs for PRs that touch a .md file. This PR does (HowTo-DefineRoutes.md, from #3254), so it fails on 7.3 files it didn't change
- Same fix as main's ec84019 (from #3153): MD040 in specs/004 and specs/006, "nuspecs" and "unmaterialized" in the dictionary, "recognize" in specs/lessons.md, MD059/MD060 off
- Also adds "rehook" (specs/009), which main got with #3154

(cherry picked from commit ec84019)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

3 participants