Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #869 +/- ##
==========================================
+ Coverage 90.46% 90.70% +0.24%
==========================================
Files 15 15
Lines 1122 1141 +19
Branches 234 228 -6
==========================================
+ Hits 1015 1035 +20
- Misses 102 106 +4
+ Partials 5 0 -5
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…F#16) loadLayout replays a layout JSON blob from localStorage on every future session, so a one-shot XSS that plants a malicious desktopJS-layouts entry keeps firing on reload. Close that off: - sanitizeUrl rejects non-http(s)/relative schemes (javascript:, data:, etc.) on persisted window urls before createWindow is called (F#14). - Layout JSON is parsed with a reviver that strips __proto__/constructor/ prototype keys, closing the Object.assign(window.options, ...) prototype-pollution gadget, and malformed/missing storage no longer throws out of getLayoutFromStorage/getLayouts (F#13). - ContainerBase.storage is now set via an overridable constructor parameter instead of being hard-bound to window.localStorage (F#16). F#03 (Object.assign smuggling arbitrary createWindow option keys) is intentionally not addressed here: createWindow is a thin pass-through shim in both remaining containers (window.open features string / fin.desktop.Window options), so smuggled keys carry no more privilege than a caller already has by calling createWindow/window.open directly. The one option key that did escalate privilege, Electron's webPreferences, is removed along with the rest of the Electron package. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
bingenito
force-pushed
the
security/core-layout-storage-hardening
branch
from
November 3, 2026 21:11
d4ef278 to
860d8a4
Compare
bingenito
marked this pull request as ready for review
November 3, 2026 21:17
bingenito
marked this pull request as draft
November 3, 2026 21:18
bingenito
marked this pull request as ready for review
November 3, 2026 21:19
There was a problem hiding this comment.
🟡 Changes recommended
Obfuscated JavaScript URLs still allow script execution, and the protected constructor breaks existing subclass instantiation with TypeScript errors.
4 open issues
What changed in this PR
This PR adds safeguards to ContainerBase layout persistence to reduce the risk of replaying malicious data from localStorage.
Changes:
- Centralizes stored JSON parsing, handles malformed data, and strips prototype-related keys.
- Adds URL scheme filtering before restoring windows and guards missing group targets.
- Adds tests for unsafe URLs, valid URLs, corrupt storage, and prototype-key stripping.
| File | Description |
|---|---|
packages/desktopjs/tests/unit/container.spec.ts |
Adds layout-loading security and storage-handling tests. |
packages/desktopjs/src/container.ts |
Adds storage injection, defensive JSON parsing, URL filtering, and guarded group restoration. |
Review effort: Balanced
| : undefined; | ||
| public storage: Storage; | ||
|
|
||
| protected constructor(storage?: Storage) { |
Comment on lines
+229
to
+233
| const schemeMatch = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(url); | ||
| if (schemeMatch && !["http", "https"].includes(schemeMatch[1].toLowerCase())) { | ||
| this.log("warn", `Blocked layout window with disallowed url scheme '${schemeMatch[1]}'`); | ||
| return undefined; | ||
| } |
| } | ||
|
|
||
| try { | ||
| return JSON.parse(raw, (key, value) => ContainerBase.unsafeJsonKeys.has(key) ? undefined : value); |
| await container.loadLayout("Test"); | ||
|
|
||
| expect(container.createWindow).toHaveBeenCalledWith("url", expect.objectContaining({ name: "1" })); | ||
| expect(({} as any).polluted).toBeUndefined(); |
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.


Summary
loadLayoutreplays a layout JSON blob fromlocalStorageon every future session, so a one-shot XSS that plants a maliciousdesktopJS-layoutsentry keeps firing on reload. This closes that off inContainerBase: