[GH-ISSUE #465] [Feature]: server-side extension storage for cross-device sync (mirroring synced themes) #205

Closed
opened 2026-10-20 17:26:15 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Romuromylus on GitHub (May 6, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/465

What problem does this solve?

Extensions in Marinara are currently stored in browser localStorage and are therefore per-device + per-browser. A user with Marinara on desktop + phone has to:

  1. Re-import every extension on each new device.
  2. Toggle each extension's enabled/disabled state separately on each device.
  3. Lose all extensions if they clear site data on any device.

This is inconsistent with how custom themes already work (synced via /api/themes + useLegacyThemeMigration), and it gets worse the more devices a user uses Marinara on.

Proposed solution

Move extensions from localStorage to server-side storage, exactly like custom themes. Concrete shape:

  • New installed_extensions table (file-backed + legacy SQLite both supported via FILE_BACKED_TABLES).
  • /api/extensions CRUD route (GET /, POST /, PATCH /:id, DELETE /:id). No script.js-style endpoint — keep the v1.5.8 client-side blob-URL loader unchanged so extension execution semantics are identical to today.
  • useExtensions() React Query hook with the same polling/refetch options as useThemes() so devices observe each other's installs/toggles within ~15s.
  • useLegacyExtensionMigration() mirrors useLegacyThemeMigration() — reads existing localStorage on first load, replays each entry against /api/extensions, dedupes on name + css + js, then flips a one-shot migration flag.
  • LegacyInstalledExtension type retained in ui.store.ts solely for migration replay; canonical InstalledExtension type comes from @marinara-engine/shared.

Hardening that the existing v1.5.7 → v1.5.8 path didn't need but server-side storage does:

  • .max() size caps on css (256 KiB) and js (1 MiB) in the zod create/update schemas so the installed_extensions table can't be ballooned.
  • /api/extensions rate-limited to 60 req/min/IP via the existing rate-limit middleware so an XSS-driven mass install can't exploit the persistent storage path.
  • Extension-runtime marinara.apiFetch rejects calls to /extensions/* and /admin/* so a malicious installed extension can't re-install itself after the user deletes it or pivot to admin endpoints.

Alternatives considered

  • Sync via existing backup/export flow — too manual; doesn't keep state in sync, just lets you copy a frozen snapshot.
  • kolacheee's approach in #431 — replaced the loader with same-origin <script src> to side-step CSP. That conflicted with the v1.5.8 loader you'd already chosen and was correctly closed. This proposal keeps your loader intact and only changes the storage layer.
  • Doing nothing — viable, but the multi-device gap will keep coming up as Marinara picks up users on phone + desktop.

Additional context

  • Same useLegacyThemeMigration pattern that already shipped — no new architecture concepts.
  • Acknowledges the threat-model implication: an XSS that already breaks CSP could now install a persistent extension via POST /api/extensions instead of a session-bounded one. The rate limit + size cap + apiFetch denylist mitigate this; the underlying assumption is still "an XSS that bypasses our existing CSP is already game over."
  • Discussed in #431 thread (kolacheee's original sync-plus-loader proposal). PR coming separately, branched off post-#461 main, single feat commit, kolacheee credited in the body.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (May 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/465 ## What problem does this solve? Extensions in Marinara are currently stored in browser `localStorage` and are therefore per-device + per-browser. A user with Marinara on desktop + phone has to: 1. Re-import every extension on each new device. 2. Toggle each extension's enabled/disabled state separately on each device. 3. Lose all extensions if they clear site data on any device. This is inconsistent with how custom themes already work (synced via `/api/themes` + `useLegacyThemeMigration`), and it gets worse the more devices a user uses Marinara on. ## Proposed solution Move extensions from `localStorage` to server-side storage, exactly like custom themes. Concrete shape: - New `installed_extensions` table (file-backed + legacy SQLite both supported via `FILE_BACKED_TABLES`). - `/api/extensions` CRUD route (`GET /`, `POST /`, `PATCH /:id`, `DELETE /:id`). No `script.js`-style endpoint — keep the v1.5.8 client-side blob-URL loader unchanged so extension execution semantics are identical to today. - `useExtensions()` React Query hook with the same polling/refetch options as `useThemes()` so devices observe each other's installs/toggles within ~15s. - `useLegacyExtensionMigration()` mirrors `useLegacyThemeMigration()` — reads existing `localStorage` on first load, replays each entry against `/api/extensions`, dedupes on `name + css + js`, then flips a one-shot migration flag. - `LegacyInstalledExtension` type retained in `ui.store.ts` solely for migration replay; canonical `InstalledExtension` type comes from `@marinara-engine/shared`. Hardening that the existing v1.5.7 → v1.5.8 path didn't need but server-side storage does: - `.max()` size caps on `css` (256 KiB) and `js` (1 MiB) in the zod create/update schemas so the `installed_extensions` table can't be ballooned. - `/api/extensions` rate-limited to 60 req/min/IP via the existing rate-limit middleware so an XSS-driven mass install can't exploit the persistent storage path. - Extension-runtime `marinara.apiFetch` rejects calls to `/extensions/*` and `/admin/*` so a malicious installed extension can't re-install itself after the user deletes it or pivot to admin endpoints. ## Alternatives considered - **Sync via existing backup/export flow** — too manual; doesn't keep state in sync, just lets you copy a frozen snapshot. - **kolacheee's approach in #431** — replaced the loader with same-origin `<script src>` to side-step CSP. That conflicted with the v1.5.8 loader you'd already chosen and was correctly closed. This proposal keeps your loader intact and only changes the *storage* layer. - **Doing nothing** — viable, but the multi-device gap will keep coming up as Marinara picks up users on phone + desktop. ## Additional context - Same `useLegacyThemeMigration` pattern that already shipped — no new architecture concepts. - Acknowledges the threat-model implication: an XSS that already breaks CSP could now install a *persistent* extension via `POST /api/extensions` instead of a session-bounded one. The rate limit + size cap + `apiFetch` denylist mitigate this; the underlying assumption is still "an XSS that bypasses our existing CSP is already game over." - Discussed in #431 thread (kolacheee's original sync-plus-loader proposal). PR coming separately, branched off post-#461 main, single feat commit, kolacheee credited in the body. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-20 17:26:15 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#205
No description provided.