fix(themes): guard installed-themes storage against non-array JSON#268
Open
dormouse-bot wants to merge 1 commit into
Open
fix(themes): guard installed-themes storage against non-array JSON#268dormouse-bot wants to merge 1 commit into
dormouse-bot wants to merge 1 commit into
Conversation
A valid-but-non-array value in localStorage (corruption or external tampering) was returned cast as DormouseTheme[], causing an uncaught TypeError in getAllThemes()'s spread and addInstalledTheme()'s filter. Add an Array.isArray guard and a regression test (the module had none).
Deploying mouseterm with
|
| Latest commit: |
562e206
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e0a7f3f1.mouseterm.pages.dev |
| Branch Preview URL: | https://fix-themes-store-array-guard.mouseterm.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
getInstalledThemes()inlib/src/lib/themes/store.tswrapsJSON.parsein atry/catch, so malformed (non-JSON) storage falls back to[]. But valid JSON that isn't an array — e.g.localStorage['dormouse:installed-themes']holding{"id":"oops"}from corruption or external tampering — parses successfully and is returned cast asDormouseTheme[]without any shape check. The non-array value then flows into the spread ingetAllThemes()and the.filter(...)inaddInstalledTheme()/removeInstalledTheme(), throwing an uncaughtTypeErrorthat breaks theme listing and installation entirely.Found during the nightly rolling survey of
lib/src/lib/themes/store.ts.Solution
Add an
Array.isArrayguard after the parse: a parsed value that isn't an array now falls back to[], matching the existing fail-soft intent of the surroundingtry/catch. No behavior change for well-formed storage.Testing
This module previously had no test file, though every sibling under
themes/does. Addedstore.test.ts(@vitest-environment jsdom, reusing the siblinginstallStorageStubpattern) covering:[]and doesn't throw throughgetAllThemes()/addInstalledTheme();[];The regression test fails on the pre-fix code (
getInstalledThemes()returns{id:'oops'}instead of[]) and passes with the guard.tsc --noEmitis clean and all 8themes/test files pass locally.Automated nightly survey finding.